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 NullPointStrategies, Today, 05:17 AM
      0 responses
      46 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      126 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      66 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X