Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy execution during enable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Strategy execution during enable

    I have a tick based strategy that increments a trade counter in OnBarUpdate right after EnterLong or EnterShort.

    It stops trading if this counter reaches a configured amount. This counter is initialized to zero in State.DataLoaded.

    However whenever I enable/disable the strategy (at least in playback mode where I'm developing), via print statements I can see this code being executed and it increments my counter. Then the strategy doesn't start because the counter has hit its limit.

    I guess I must be missing something here in the startup/event loop process, to keep this from happening? If you can help me please.

    thanks

    #2
    Hello trader24211341,

    When you enable a strategy it does a historical backtest before entering realtime. If you don't have any means to prevent that then that is why the counter is being incremented. If you only want to test the strategy in realtime you can add:

    if(State == State.Historical) return;

    To the beginning of OnBarUpdate, that will prevent the backtest and allow it to work only going forward.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    30 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    64 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X