Cumulate orders issue
Forums › ProRealTime English forum › ProOrder support › Cumulate orders issue
- This topic has 3 replies, 3 voices, and was last updated 4 months ago by
Jlenn89.
-
-
07/18/2025 at 4:06 PM #248951
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
07/18/2025 at 4:47 PM #248953When 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:
12345678910111213DEFPARAM CumulateOrders = trueONCE MaxContracts = 3MyLongConditions = (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) THENBUY 1 Contract at MarketENDIFIF MyShortConditions AND (abs(CountOfPosition) < MaxContracts) THENSELLSHORT 1 Contract at MarketENDIFSET STOP %LOSS 1SET TARGET %PROFIT 1graph CountOfPosition07/20/2025 at 9:42 AM #248967Cumulate Orders123456789101112131415161718192021222324252627// Definition of code parametersDEFPARAM CumulateOrders = true // Cumulating positions deactivated// Conditions to enter long positionsc1 = (close > high[12])indicator1 = Average[50](close)c2 = (close > indicator1)// Buying the market conditionsIF c1 AND c2 THENBUY 1 SHARES AT MARKETENDIF// Cummulate orders until max position achieved set limitsIF LONGONMARKET AND COUNTOFLONGSHARES < 3 AND Open > Close[1] THENBUY 1 SHARES AT MARKETENDIF// Conditions to exit long positionsc3 = (close < low[14])c4 = (close < indicator1)IF c3 OR c4 THENSELL AT MARKETENDIF// Stops and targetsSET STOP %LOSS 4Hi 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…
3 users thanked author for this post.
07/29/2025 at 10:08 PM #249203 -
AuthorPosts
Find exclusive trading pro-tools on 