Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Delay between Executions to Prevent Duplicate Positions

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

    Delay between Executions to Prevent Duplicate Positions

    Is there a command in NinjaScript to introduce a brief delay, say 1 second, between trade executions? I've created a simple MA-Crossover strategy where the goal is to flatten and reverse the position when the crossover happens. The problem is sometimes instead of one contract, two are opened! I'm considering adding a slight delay between the stop-out and opening a new position in the opposite direction to resolve this. If you have a better solution, I'd appreciate your assistance. Thanks!

    #2
    Hello rezamerik,

    Thank you for your post.

    Are you calling an exit at the same time as an entry? Calling an exit followed immediately by an entry will double the quantity in the opposite direction. This is because 3 orders are sent.

    For example, say you are long 1 when you call ExitLong and then EnterShort . Since you are long 1, NinjaTrader will see that and a signal to ClosePosition. However, then when you call EnterShort(), the platform hasn't had enough time to actually close out the initial entry.

    Now, you have an ExitLong(), ClosePosition, and then EnterShort(), resulting in an extra order which causes your quantity to double.

    Please read this forum post for a detailed explanation:

    https://forum.ninjatrader.com/forum/...op#post1036616

    NT8 Managed Approach - https://ninjatrader.com/support/help...d_approach.htm

    For an example script that demonstrates reversing positions on crossovers, check out SampleMACrossover included in NinjaTrader 8.

    Please let me know if I can assist further.

    Comment


      #3
      Thanks so much NinjaTrader_Gaby for the information! That's exactly the mistake I had made as I didn't know EnterLong() / EnterShort() automatically reverse the position.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      39 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      19 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      26 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      36 views
      0 likes
      Last Post CarlTrading  
      Working...
      X