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 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
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X