Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unexpected trades

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

    Unexpected trades

    I am using the following code,

    protected override void OnBarUpdate()
    {
    if(Position.MarketPosition != MarketPosition.Flat)
    return;

    if(CrossAbove(EMA(eMAF), EMA(eMAS), 1))
    EnterLong();

    else if (CrossBelow(EMA(eMAF), EMA(eMAS), 1))
    EnterShort();
    }


    I expected it to enter one trade on the first cross of the EMAs and enter no further trades as it would return due to:-

    if(Position.MarketPosition != MarketPosition.Flat)
    return;

    but it continues to enter and exit trades. What am I missing?

    Also I notice that at the end of the contract the open position is closed. Is it possible to get the same behaviour when using the WFA, testing on multiple contracts?

    #2
    GKonheiser, I would expect that only to be the case if you set ExitOnClose to false. As otherwise a new entry could be made after the ExitOnClose is processed for the given day / session.

    This can be done either directly from the UI with the ExitOnClose parameter or by your strategy Initialize method making a call to it - http://www.ninjatrader.com/support/h...ub=ExitOnClose

    Comment


      #3
      Yes of course. that makes sense.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      231 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      149 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      161 views
      1 like
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      243 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      198 views
      0 likes
      Last Post CarlTrading  
      Working...
      X