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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Working...
      X