Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Yes of course. that makes sense.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by helpwanted, Today, 03:06 AM
      1 response
      7 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      7 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      5 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      242 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      384 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X