Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLong() not working as expected

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

    EnterLong() not working as expected

    Hello, I have a brand new strategy with the only code I added being.

    Code:
            protected override void OnBarUpdate()
            {
                if (Position.MarketPosition == MarketPosition.Flat)
                {
                    EnterLong(Convert.ToInt32(DefaultQuantity), Convert.ToString(CurrentBar) + " Long");
                }
            }
    ​
    My chart is ES 6-24 with playback connected and the date range set to 4/15/24 to 4-19-24 time frame is 5 minute.

    I am new to ninjatrader and I have been trying for hours trying different settings but cannot get EnterLong to work as expected. I would expect it to enter a long position on the first bar update after hitting paly. However it wont enter a position until a full day later on 4/16/24 of running the playback. What am I not understanding about this? How can I get it to enter a long position right when I hit play on the first bar update?

    Thanks

    #2
    Hello AlgoDreamer,

    Welcome to the NinjaTrader forums!

    Likely the strategy is placing an order in the historical data and is using the Wait Until Flat Start Behavior.
    If the strategy name is yellow (or orange on some monitors) the strategy is waiting for the position to be exited before it places real-time orders (and the strategy name turns green).

    Below is a link to a support article on Start Behavior.


    If you only want to submit orders in real-time, add to the top of OnBarUpdate():

    if (State != State.Realtime)
    return;
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Adding the check State != State.Realtime makes it work as expected now, thank you!​

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      99 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      146 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      86 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      259 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      340 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X