CUMULATEORDERS – COUNTOFPOSITION
Forums › ProRealTime English forum › ProOrder support › CUMULATEORDERS – COUNTOFPOSITION
- This topic has 11 replies, 4 voices, and was last updated 3 years ago by
robertogozzi.
-
-
12/01/2021 at 11:05 AM #182578
Hi.
If i want to create at strategy with CUMULATEORDERS. Maximun 1 long position and 1 short position at once.
What do i choose in “MAX Position” when i start the tradingsystem?CUMULATEORDERS - COUNTOFPOSITION123456789101112131415161718DEFPARAM CUMULATEORDERS = truedefparam preloadbars = 10000MAXSHARES = abs(COUNTOFPOSITION) <= 1CB = RSI[14]>50CS = RSI[14]<45If cb and MAXSHARES and not longonmarket thenBuy PositionSize CONTRACTS AT MARKETSET STOP %LOSS 1SET TARGET %PROFIT 2ENDIFIf cs and MAXSHARES and not shortonmarket thensellshort PositionSize CONTRACTS AT MARKETSET STOP %LOSS 1SET TARGET %PROFIT 2ENDIF12/01/2021 at 11:10 AM #182581You cannot open opposite positions (Long & Short) in the same strategy.
Anytime you go Long any previous Short position still open will be closed. The other way round when you go Short.
PositionSize is correct, but it must be defined before being used.12/01/2021 at 11:35 AM #182584It need to look like this?
Test code1234567891011121314151617181920212223242526DEFPARAM CUMULATEORDERS = falsedefparam preloadbars = 10000PositionSize=1CB = RSI[14]>50CS = RSI[14]<45If cb then // Entry longBuy PositionSize CONTRACTS AT MARKETSET STOP %LOSS 1SET TARGET %PROFIT 2ENDIFIf cs then // Exit longsell at marketendifIf cs then // Entry shortsellshort PositionSize CONTRACTS AT MARKETSET STOP %LOSS 1SET TARGET %PROFIT 2ENDIFIf cb then // Exit shortexitshort at marketendif12/01/2021 at 12:26 PM #182588What do i choose in “MAX Position” when i start the tradingsystem?
1.
However, I would be very careful with depending on that, because in my particular case it seems it does not work reliably. And do notice that this happens specifically in the situation that the Strategy additionally buys. In other words, enter less in that field than the Strategy wants to do and nothing ever starts (taking position), but set it to e.g. 1 and let the Strategy take position – then when it additionally want to take position (make 2 from 1) then it just does it.
Thus, take care of not depending on it, as it seems that you do that (not 100% sure).1 user thanked author for this post.
12/01/2021 at 12:38 PM #182594MAX positions set when starting the strategy in autotrading and the number of lots/contracts coded with BUY/SELLSHORT grant that the lowest of the two is the one actually used, so if Max is set to 999 but you BUY 1, only 1 contract will be bought, if you set Max to 5 and BUY 10, then only 5 contracts will be bought.
I have never had problems with this, so far.
12/01/2021 at 1:02 PM #182598The way I do it is not to control the number of contracts, but the number of entries. This way you can let your MM alter the positionsize.
123456789101112131415161718if not onmarket thenflag1 = 1flag2 = 1flag3 = 1ENDIF// Conditions to enter long positionsIF not longonmarket and CB and Flag1 THENBUY positionsize CONTRACT AT MARKETflag1 = 0elsif longonmarket and CBA and flag2 thenBUY positionsize CONTRACT AT MARKETflag2 = 0elsif longonmarket and CBA and flag3 thenBUY positionsize CONTRACT AT MARKETflag3 = 0ENDIFYou can repeat the elsif and flags 4, 5, 6 as many times as you want. You can also create different conditions for the additional positions (CBA vs CB).
Eg. you might start the first entry within a certain time range, but let it add extra positions outside of that (ie overnight)
or add other criteria such as “positionperf <0” so that your aggregate is always averaging down.
1 user thanked author for this post.
12/01/2021 at 1:41 PM #182602if you set Max to 5 and BUY 10, then only 5 contracts will be bought.
Maybe you have a special system, but mine (for IG) does not enter at all in that case (which is what I am happy with or else things will happen I did not code).
Maybe I am wrong with my observations.12/01/2021 at 4:16 PM #182622Yes, you are right PeterSt, if you set MAX=5 then if you BUY more than 5 no trade is opened.
You can only buy 5 or less contracts. It makes sense.
Actually I never used that, I always set MAX=999 then I apply lot size management up to that limit.
12/01/2021 at 5:05 PM #182632Actually I never used that, I always set MAX=999 then I apply lot size management up to that limit.
Yes, I did too, until I dynamically started to increase the position (during the original Trade-opening). So now I limit it (with say 5) in order not to run into an out of money and *that* part seems not to work reliably. So this is the other half of the story (“be careful with that !”) but it is hard to test – waiting for the situation to happen.
See example of what I am talking about (if not obvious in the first place).12/01/2021 at 5:08 PM #182635I see, but with Lot & Money management that shouldn’t happen!
12/01/2021 at 5:39 PM #182637I most certainly agree and this is in there all right (see attachment). Meanwhile with such setups I like to have an extra protection. Thus, I set my own MM a tad too high deliberately and want to see if that extra protection (by PRT) works.
N.b.: It s also testing myself (or my code) in order to see what actually happens and how decent I coded it. Thus, if an order is rejected, how do I actually notice that, and is that not one bar too late to remain in control. Understand ?
12/01/2021 at 5:49 PM #182639Ok, that’s clear.
-
AuthorPosts
Find exclusive trading pro-tools on