Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Debugging Strategy on Playback Connection starts in Position != Flat?

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

    Debugging Strategy on Playback Connection starts in Position != Flat?

    I start my strategy, at the beginning of a day, and it starts off in, for instance, MarketPosition.Short. It hasn't even started yet. How is this possible? Even the Positions log shows there are no open positions but the strategy shows that it is Short. I restart NT8 application, start from the beginning. Start Playback Connection from 12:00 AM beginning of day. Still in Short position without being in a position.

    My only guess is that the strategy is being replayed from bar zero and it ends up in a strategy position of Short but this is not reflected in the NT8 Positions window. If this is the case, how can I get around this? Thanks so much!
    Last edited by bfalls; 05-31-2021, 04:48 PM.

    #2
    Hello bfalls,

    Thanks for your post.

    When you apply a strategy, it will perform its trading on the historical data. With the start behavior of wait until flat, if the strategy has a historical position when you begin real-time data (or playback in run) then that will prevent the strategy from trading until that historical position is closed. In the strategy tab, you would see that the strategy name is yellow/orange and that the strategy position is short and the account position is flat. The strategy will maintain its position until the strategy closes the position and then the strategy name will turn green and the strategy will begin live trading, all done according to your entry and exit conditions. Please see: https://ninjatrader.com/support/help...eStrategiesTab

    You can choose a different start-up behavior and I suggest you test each so that you find what works best for you: Reference: https://ninjatrader.com/support/help..._positions.htm

    Another alternative is to simply bypass performing historical trades by not processing your code on historical data with a simple check of the state condition at the top of your OnBarUpdate:

    if (State != State.Realtime) return; // do not process code below unless in state real time

    Please keep in mind that the code would prevent historical trades so if you test with the strategy analyzer you would need to comment that out. Alternately you could create an input bool that allows you to skip historical processing or not so that you don't need to recompile each time just to switch it on or off.


    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    52 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    48 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X