Cumulating positions ARE NOT WORKING
Forums › ProRealTime English forum › ProOrder support › Cumulating positions ARE NOT WORKING
- This topic has 7 replies, 6 voices, and was last updated 3 years ago by deletedaccount051022.
-
-
08/27/2021 at 4:04 AM #176322
Gents,
Could you check this code why the Cumulating positions are not working??CumulateOrders NOT WORKING1234567891011121314151617// Definition of code parametersDEFPARAM CumulateOrders = True // Cumulating positions activatedtimeframe(DEFAULT)MaxPositionsAllowed = 5// Conditions to enter long positionsindicator1 = MACDline[5,35,5](close)indicator2 = MACDSignal[5,35,5](close)c1 = (indicator1 CROSSES OVER indicator2)PP = (DHigh(1) + DLow(1) + DClose(1))/3C2 = (close < indicator1)S3 = DLow(1)-2*(DHigh(1)-(DHigh(1) + DLow(1) + DClose(1))/3)C3 = (close > indicator2)IF c1 AND c2 AND c3 THENBUY 50 CONTRACT AT MARKETENDIF// Stops and targetsSET TARGET pPROFIT 2.008/27/2021 at 6:58 AM #176326Hello,
What is the issue that you have and make you say it’s not working?
For sure, the variable MaxPositionsAllowed is defined but not used in the code, which is not good, the system will rebuy more than 5 times
Assuming that the conditions are met, I would try something like this, and verifying the number of positions in the graph once the results are generated.Modification proposal123456789101112ounce n=0....IF NOT LongOnMarket THENn=0ENDIFIF c1 AND c2 AND c3 AND n<MaxPositionsAllowed THENBUY 50 CONTRACT AT MARKETn=n+1ENDIF08/27/2021 at 7:45 AM #176330Conditions in lines 13 and 15 seem to be impossible to be both true at the same time.
08/27/2021 at 7:46 AM #17633108/27/2021 at 7:54 AM #17633308/27/2021 at 8:01 AM #176337Its not buying again regardless of C2 and C31234567891011121314151617// Definition of code parametersDEFPARAM CumulateOrders = True // Cumulating positions activatedtimeframe(DEFAULT)MaxPositionsAllowed = 5// Conditions to enter long positionsindicator1 = MACDline[5,35,5](close)indicator2 = MACDSignal[5,35,5](close)c1 = (indicator1 CROSSES OVER indicator2)PP = (DHigh(1) + DLow(1) + DClose(1))/3C2 = (close < PP)S3 = DLow(1)-2*(DHigh(1)-(DHigh(1) + DLow(1) + DClose(1))/3)C3 = (close > S3)IF c1 AND c2 AND c3 THENBUY 50 CONTRACT AT MARKETENDIF// Stops and targetsSET TARGET pPROFIT 2.008/27/2021 at 8:52 AM #176344this is the entry code for a cumulating algo I have up and running and I know works. In this case the limit is 3 entries instead of 5, but you can adapt it.
The logic of MaxPositionsAllowed is to control the total number of contracts, not the number of entries. The code below will make 3 entries of 50 contracts each.
Another stipulation I use, that you might want to consider, is adding “and positionperf <0” to your additional entries, so that your total position is always averaging down.
123456789101112131415161718192021222324positionsize = 50MaxPositionsAllowed = 3*positionsizeif not onmarket thenflag = 1flag1 = 1ENDIF// Conditions to enter long positionsIF not longonmarket and (conditions) THENBUY positionsize CONTRACT AT MARKETelsif longonmarket and (conditions) and flag and COUNTOFLONGSHARES < MaxPositionsAllowed thenBUY positionsize CONTRACT AT MARKETflag = 0elsif longonmarket and (conditions) and flag1 and COUNTOFLONGSHARES < MaxPositionsAllowed thenBUY positionsize CONTRACT AT MARKETflag1 = 0ENDIFIf LongOnMarket THENSET STOP %LOSS slSET TARGET %PROFIT tpENDIF2 users thanked author for this post.
08/27/2021 at 9:31 AM #176351I really like the addition of the “and positionperf <0” , neat snippet – thank you for sharing.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on