Cumulate orders issue

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #248951 quote
    Jlenn89
    Participant
    New

    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

    Screenshot-2025-07-18-at-9.36.47-AM.png Screenshot-2025-07-18-at-9.36.47-AM.png
    #248953 quote
    robertogozzi
    Moderator
    Master

    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:

    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
    Iván González and Jlenn89 thanked this post
    x.jpg x.jpg y.jpg y.jpg
    #248967 quote
    JS
    Participant
    Senior
    // 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…

    robertogozzi, Iván González and Jlenn89 thanked this post
    #249203 quote
    Jlenn89
    Participant
    New

    I appreciate it, system running perfect now.

    Thank you

    JS thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Cumulate orders issue


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Jlenn89 @jlenn89 Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by Jlenn89
6 months, 3 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/18/2025
Status: Active
Attachments: 3 files
Logo Logo
Loading...