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