code for limiting the number of cumulative orders
Forums › ProRealTime English forum › ProOrder support › code for limiting the number of cumulative orders
- This topic has 29 replies, 8 voices, and was last updated 3 years ago by nonetheless.
-
-
10/12/2020 at 5:08 PM #147183
I’m using the following code to limit cumulative orders to a max of 8:
1234567Once MaxPositionsAllowed = 8// Conditions to enter long positionsIF Ctime and c1 and c1a AND C3 and c3a AND C5 and c5a and abs(CountOfPosition) < MaxPositionsAllowed THENBUY positionsize CONTRACT AT MARKETSET STOP %LOSS 1.3SET TARGET %PROFIT 2.2ENDIFbut in practice (demo) the strategy is taking more than 8, see attached pic. Is there anything wrong with the above code?
10/12/2020 at 5:26 PM #147185I don’t know how your positionsize is calculated and how your countofposition usually evolves, but let’s say as an example you have abs(countposition)=7 ( is lower than 8) and positionsize is 3, the “if” statement will conclude that 7 being lower than 8 (and your other conditions being respected), it’s ok to add 3 to this, and 7+3=10…
In other words, from quick read without the rest of the code, this piece of code is not preventing you from going above 8 at all, because you made your check before adding to the position, so I’d try with : abs(countofposition)<maxpositionallowed-positionsize to see there’s enough room left below the max before increasing the position
1 user thanked author for this post.
10/12/2020 at 5:35 PM #147188I think line 3 could be written as:
1IF Ctime and c1 and c1a AND C3 and c3a AND C5 and c5a and (abs(CountOfPosition) + PositionSize) <= MaxPositionsAllowed THEN2 users thanked author for this post.
10/12/2020 at 5:38 PM #147189Thanks for that, but perhaps I am missing something. Surely countofposition and positionsize are 2 different things, no?
In this case, positionsize is .4 on the DJ and I want to have a max of 8 different entries of .4 each. Would the MaxPositionsAllowed then need to be 3.2 ?
10/12/2020 at 5:40 PM #14719010/12/2020 at 5:50 PM #147193But how will that work with MM then? when the positionsize increases? Maybe
1MaxPositionsAllowed = (positionsize x 8)???
10/12/2020 at 5:52 PM #147194COUNTOFPOSITION is the number (negative for Short positions) of total positions accumulated so far, while PositionSize is the number of positions you want to trade at that very moment. After opening additional PositionSize contracts/shares, COUNTOFPOSITION will be increased by PositionSize units.
10/12/2020 at 6:43 PM #147206Sorry Roberto, if my positionsize = .4 and the strategy has cumulated 7 orders then the countofposition is 7 or 2.8 ?
10/12/2020 at 7:01 PM #14720810/12/2020 at 7:09 PM #147209Ok, so countofposition is actually the total number of contracts. In this case I would want that to max at 3.2 and if positionsize didn’t change then there’s no problem. But what happens when the MM changes the positionsize? Is there no way of specifying the number of instances, rather than the number of contracts?
10/12/2020 at 7:50 PM #14721110/12/2020 at 8:24 PM #147212Hi Fifi, comment ca va?
Do you mean
10/12/2020 at 8:37 PM #147217that is supposed to say
1234Once MaxPositionsAllowed = 8// Conditions to enter long positionsIF Ctime and myconditions and round(CountOfPosition/positionsize) <= MaxPositionsAllowed THEN10/12/2020 at 8:53 PM #147220Why using ROUND()?
MaxPositionsAllowed is a limit. If your current COUNTOFPOSITION is 7.4 and you wanna add 0.8 the code won’t allow that.
Rounding that number will count it as 7, so you’ll be allow to add 0.8 PositionSize contracts, but doing this actually will raise COUNTOFPOSITION to 8.2, which is not what you asked with MaxPositionsAllowed.
10/12/2020 at 8:57 PM #147221Sorry, I just realized I misunderstood.
You want MaxPositionsAllowed to set the number of times you open positions, no matter how large they are.
In that case your code is correct.
2 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on