Cumulate orders issue
- This topic has 3 replies, 3 voices, and was last updated 1 month ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
Similar topics:
Forums › ProRealTime English forum › ProOrder support › Cumulate orders issue
Hey everyone!
This will be my first time engaging on this forum, Im new to the pro realtime platform but already benefiting from features (backtesting mainly).
But.. I have ran in to a little bit of a snag, hoping someone can help me out. I’m trying to set a limit on cumulating orders for a strategy, but it’s not respecting my max count. Im sure I’m doing something wrong, I have minimal to no coding experience. Please see screen shot and let me know what you think, any help would be greatly appreciated.
Thanks,
Josh
When posting code, please use the text format, either pasting it as is or pasting it using the “insert PRT code” button. To copy it to the clipboard you can either select the text of the code to be copied manually or press the COPY icon highlighted in the attached screenshot X.
The screenshot Y shows where you can find the “insert PRT code” button.
Thanks 🙂
There you go:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
DEFPARAM CumulateOrders = true ONCE MaxContracts = 3 MyLongConditions = (close > average[20,0](close)) AND close > close[1] MyShortConditions = (close < average[20,0](close)) AND close > close[1] IF MyLongConditions AND (abs(CountOfPosition) < MaxContracts) THEN BUY 1 Contract at Market ENDIF IF MyShortConditions AND (abs(CountOfPosition) < MaxContracts) THEN SELLSHORT 1 Contract at Market ENDIF SET STOP %LOSS 1 SET TARGET %PROFIT 1 graph CountOfPosition |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
// Definition of code parameters DEFPARAM CumulateOrders = true // Cumulating positions deactivated // Conditions to enter long positions c1 = (close > high[12]) indicator1 = Average[50](close) c2 = (close > indicator1) // Buying the market conditions IF c1 AND c2 THEN BUY 1 SHARES AT MARKET ENDIF // Cummulate orders until max position achieved set limits IF LONGONMARKET AND COUNTOFLONGSHARES < 3 AND Open > Close[1] THEN BUY 1 SHARES AT MARKET ENDIF // Conditions to exit long positions c3 = (close < low[14]) c4 = (close < indicator1) IF c3 OR c4 THEN SELL AT MARKET ENDIF // Stops and targets SET STOP %LOSS 4 |
Hi Josh, welcome…
Here’s the code from your screenshot…
The issue with your system not respecting the maximum position size lies in line 10 of your code…
When the conditions c1 and c2 are true, a position is opened. However, these conditions can remain true for multiple bars (days), which causes the system to keep opening new positions as long as the conditions hold…
The solution is to replace line 10 with the following condition:
If NOT LongOnMarket and c1 and c2 then
This ensures that a new position is only opened when no position is already active…
Find exclusive trading pro-tools on