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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      558 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X