Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.


    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by inanazsocial, Today, 01:15 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by rocketman7, Today, 02:12 AM
    0 responses
    10 views
    0 likes
    Last Post rocketman7  
    Started by dustydbayer, Today, 01:59 AM
    0 responses
    2 views
    0 likes
    Last Post dustydbayer  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    5 responses
    23 views
    0 likes
    Last Post trilliantrader  
    Started by Davidtowleii, Today, 12:15 AM
    0 responses
    3 views
    0 likes
    Last Post Davidtowleii  
    Working...
    X