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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      88 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X