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

Problem with EnterLongStopMarket() following ExitShort in strategy backtest

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

    Problem with EnterLongStopMarket() following ExitShort in strategy backtest

    Hi,

    I have a strategy which uses EnterLongStopMarket() and EnterShortStopMarket() to open positions after a long or short signal. These orders generally work. However, before opening a long position the strategy will close any existing short position using ExitShort(). When this happens, the short position is closed but the new long position is never opened. Also, a message appears in the error log with the text 'An entry() method to submit an entry order at Date/Time has been ignored...'

    If I replace EnterLongStopMarket() with a simple EnterLong then everything works - I can close an existing position and open a new one on the same bar.

    So why does Strategy Analyzer reject ExitShort / EnterLongStopMarket on the same bar when it is happy with ExitShort / EnterLong ?

    Thank you,
    Jimmy

    #2
    Hello Jimmy,

    Thanks for your first post!

    The Managed Approach has internal order handling rules to reduce unwanted positions. This would prevent EnterLongStopMarket() from submitting an order if the strategy is in a short position. If you are calling ExitShort() and then EnterLongStopMarket(), these order methods will fire, but this does not mean that the strategy will wait until the ExitShort() fills before submitting the EnterLongStopMarket(). This order would then be ignored.

    I may suggest to set bools in OnBarUpdate() and to use OnExecutionUpdate() to detect when the strategy has returned to a flat position after submitting ExitShort(). When your bool is true and the ExitShort is seen as filled (we are back to flat,) the EnterLongStopMarket() should no longer be ignored.

    You can reference the internal order handling rules of the Managed Approach here - https://ninjatrader.com/support/help...antedPositions

    Our SampleOnOrderUpdate strategy and the associated documentation can give some further insight for using OnExecutionUpdate() as well as OnOrderUpdate.

    SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

    Please let us know if we can be of further assistance
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,

      Thank you for the suggestion of using the OnExecutionUpdate() method. I was already using a unique order name when exiting a short position due to a new 'go long' signal :-

      ExitShort("Longsignal", "Short1");

      So all needed to do in OnExecutionUpdate() was this :-

      if (execution.Order != null && execution.Order.Name == "Longsignal")
      EnterLongStopMarket(Close[0] + (TickSize*10*PIPStop), "Long1");

      This is now working - I get a new long position on the same bar that my short position gets closed.

      Thanks again,
      Jimmy

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by frankthearm, Today, 09:08 AM
      7 responses
      29 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by NRITV, Today, 01:15 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by maybeimnotrader, Yesterday, 05:46 PM
      5 responses
      25 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by quantismo, Yesterday, 05:13 PM
      2 responses
      17 views
      0 likes
      Last Post quantismo  
      Started by adeelshahzad, Today, 03:54 AM
      5 responses
      33 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X