Cumulate Orders
Forums › ProRealTime English forum › ProBuilder support › Cumulate Orders
- This topic has 14 replies, 3 voices, and was last updated 7 years ago by quo.
-
-
02/19/2017 at 1:48 PM #25597
Hi All, i have a system with this logic:
1.-When conditions are set, buy 1000 eur.
2.-Once in, if the close is lower than the previous buy, buy again 2000.
3.-If the close is again below the second buy, buy 3000.
4.-And if the close is below the third buy, buy 4000.
No more than 4 buys is admited.
I have coded this but everytime i try to put the third buy gives me an error.
123456789IF LONGONMARKET=0 THENIF c1 THENBUY 1000 cash AT MARKETENDIFELSEif close<close[Barindex - Tradeindex] thenbuy 2000 cash at marketendifendifAny help?
thanks
02/19/2017 at 1:56 PM #2559802/19/2017 at 6:26 PM #25629Hi Nicolas, there is no error in the code. It is the way i use it, but i want to improve it with the changes stated before.
I dont know how to limit operations to 4. Also i can´t find how to tell the system for the third buy: the close must be lower the second buy (not the first one).
If you can tell me if this is discused before in the forum or the command i have to use i appreciated.
thanks
02/19/2017 at 6:48 PM #25633I’m not sure it will work like the way you want, please make your tests to see how it goes..Thanks.
123456789101112once amount = 1000IF NOT LONGONMARKET THENIF c1 THENBUY amount cash AT MARKETENDIFELSEif close<positionprice(1) and barindex>tradeindex(1) and countofposition<4 thenamount = abs(countofposition)*1000buy amount cash at marketendifendif04/01/2017 at 10:19 AM #30590Hi Nicolas, i am afaid is not what i want. You gave me a clue and i have been trying to find out if there is a way to get what i want but unfortunatelly not.
I give you the code again and i explain what happen:
123456789101112131415161718// Definición de los parámetros del códigoDEFPARAM CumulateOrders = True // Acumulación de posiciones activada// Condiciones para entrada de posiciones largasc1 = close<Average[5](close) and close[1]<average[5] and close>average[200](close)IF LONGONMARKET=0 THENIF c1 THENBUY 1000 cash AT MARKETENDIFELSEif close<close[Barindex - Tradeindex] thenbuy 2000 cash at marketendifendifIF close>average[5] thensell at marketendifIt works as i want but i have unlimited orders and i want a maximum of 4.
Also it buys 1000 in the first order and 2000 in the rest and i want only four entries (1000 eur, 2000 eur, 3000 eur, 4000 eur)( i mean 4 entries if the price goes lower but a trade can be 1,2,3 or 4 buys)
It is a kind of pyramiding buying more when you get lower prices.
i have read this
https://www.prorealcode.com/blog/trading/averaging-techniques-automated-trading/
but i trade cash no contracts and i want to increase the cuantity every time i buy (limited to 4) and was no possible to adapt it.
I also studied this advice
https://www.prorealcode.com/reply/25833/
but doesn´t work, maybe because this for intraday and in shares.
I also reached this code. It increase the quantity as i want but it does it in the same day!!
1234567891011121314151617181920// Definición de los parámetros del códigoDEFPARAM CumulateOrders = True // Acumulación de posiciones activada// Condiciones para entrada de posiciones largasc1 = close<Average[5](close) and close[1]<average[5] and close>average[200](close)if not longonmarket thenif c1 thenbuy 1000 cash at marketendifelseif close<close[barindex -Tradeindex] and countofposition buy 2000 cash at marketendifif close<close[barindex -Tradeindex] and countofposition buy 3000 cash at marketendifif close<close[barindex -Tradeindex] and countofpositionaverage[5] thensell at marketendifI dont want to use positionprice as you suggest, it is not important the midprice. Other thing: What happen with countofposition? if i skip it in the last code remains the same! can not be used with cash?
thanks for your help
04/01/2017 at 10:24 AM #30591i am sorry i used “insert PRT code” but it did not work
123456789101112131415161718192021222324252627<br>// Definición de los parámetros del códigoDEFPARAM CumulateOrders = True // Acumulación de posiciones activada// Condiciones para entrada de posiciones largasc1 = close<Average[5](close) and close[1]<average[5] and close>average[200](close)if not longonmarket thenif c1 thenbuy 1000 cash at marketendifelseif close<close[barindex -Tradeindex] and countofposition<2000 thenbuy 2000 cash at marketendifif close<close[barindex -Tradeindex] and countofposition<3000 thenbuy 3000 cash at marketendifif close<close[barindex -Tradeindex] and countofposition<6000 thenbuy 4000 cash at marketendifendifIF close>average[5] thensell at marketendif04/01/2017 at 11:48 AM #30600Did you look at the documentation? This should make it clear what you need to change in your code:
04/01/2017 at 1:31 PM #30610Thank you, its true, it is very clear but it seems countofposition works well with contract and shares buy not with cash.
This code with shares works as i want
1234567891011121314151617181920212223// Definición de los parámetros del códigoDEFPARAM CumulateOrders = True // Acumulación de posiciones activada// Condiciones para entrada de posiciones largasc1 = close<Average[5](close) and close[1]<average[5] and close>average[200](close)IF NOT LONGONMARKET and c1 THENBUY 1000 shares AT MARKETENDIFmaxshares = countofposition <=10000if close<close[Barindex - Tradeindex] and longonmarket and countofposition=1000 and maxshares thenbuy 2000 shares at marketendifif close<close[Barindex - Tradeindex] and longonmarket and countofposition=3000 and maxshares thenbuy 3000 shares at marketendifif close<close[Barindex - Tradeindex] and longonmarket and countofposition=6000 and maxshares thenbuy 4000 shares at marketendifIF close>average[5] thensell at marketendifbut… as i trade stocks and they have different price i need to use cash.
i have tried dividing cash into price in order to know the number of shares but does not work, (maybe because it takes different close price every time?)
123456789101112131415161718192021222324// Definición de los parámetros del códigoDEFPARAM CumulateOrders = True // Acumulación de posiciones activada// Condiciones para entrada de posiciones largasc1 = close<Average[5](close) and close[1]<average[5] and close>average[200](close)IF NOT LONGONMARKET and c1 THENBUY (1000/close) shares AT MARKETENDIFmaxshares = countofposition <=10000if close<close[Barindex - Tradeindex] and longonmarket and countofposition=(1000/close) and maxshares thenbuy (2000/close) shares at marketendifif close<close[Barindex - Tradeindex] and longonmarket and countofposition=(3000/close) and maxshares thenbuy (3000/close) shares at marketendifif close<close[Barindex - Tradeindex] and longonmarket and countofposition=(6000/close) and maxshares thenbuy (4000/close) shares at marketendifIF close>average[5] thensell at marketendifi almost got it. Any idea?
04/01/2017 at 4:47 PM #306221234567891011121314151617181920212223242526272829//You can do it by keeping track of the number of tractions yourselfONCE Transactions = 0c1 = close<Average[5](close) and close[1]<average[5] and close>average[200](close)if not LONGONMARKET and c1 thenBUY (1000/close) SHARES AT MARKETTransactions = 1elsif LONGONMARKET thenif close<close[Barindex - Tradeindex] and Transactions = 1 thenbuy (2000/close) shares at marketTransactions = 2endifif close<close[Barindex - Tradeindex] and Transactions = 2 thenbuy (3000/close) shares at marketTransactions = 3endifif close<close[Barindex - Tradeindex] and Transactions = 3 thenbuy (4000/close) shares at marketTransactions = 4endifendifIf close>average[5] thensell at marketTransactions = 0endif1 user thanked author for this post.
04/01/2017 at 4:52 PM #30623*Comment should read ‘transactions’.
And Insert PRT code is losing the indentation.
04/01/2017 at 6:23 PM #3062604/01/2017 at 10:04 PM #30629What timeframe chart are you using?
04/01/2017 at 10:37 PM #3063004/02/2017 at 8:16 AM #30645Ah ok I re-used your code without checking it thoroughly enough, when onmarket it needs to do only one purchase per bar so needs to use an elsif.
1234567891011121314151617181920212223242526ONCE Transactions = 0c1 = close<Average[5](close) and close[1]<average[5] and close>average[200](close)if not LONGONMARKET and c1 thenBUY (1000/close) SHARES AT MARKETTransactions = 1elsif LONGONMARKET then//maxshares = countofposition <=10000if close<close[Barindex - Tradeindex] and Transactions = 1 thenbuy (2000/close) shares at marketTransactions = 2elsif close<close[Barindex - Tradeindex] and Transactions = 2 thenbuy (3000/close) shares at marketTransactions = 3elsif close<close[Barindex - Tradeindex] and Transactions = 3 thenbuy (4000/close) shares at marketTransactions = 4endifendifIf close>average[5] thensell at marketTransactions = 0endif1 user thanked author for this post.
04/02/2017 at 8:49 PM #30753 -
AuthorPosts
Find exclusive trading pro-tools on