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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    87 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    128 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    65 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    117 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X