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

Multiple Orders filled when i only want one.

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

    Multiple Orders filled when i only want one.

    Hello.

    I'm using a script that shows up two buttons on the chart. One is a BUY button, the other is a SHORT button (code attached to the post).
    When clicked, an "Open" button is changed into a "Close" button.
    The buttons do what's expected : Buy when clicked, then close when clicked again.

    My issue is that sometimes, I get more than one order filled, when only 1 is supposed to be.
    As you can see in the linked screenshot : it should be only 1 order filled, but you can see 3 orders filled.

    Can you help me understanding why I have those unexpected orders filled ?

    Thank you in advance for your reply.
    Attached Files

    #2
    Hello thanajo,

    Thanks for your post.

    The strategy is being run with Calculate.OnEachTick. This means the code is executed for every incoming tick which can be very fast executions. The code block for entering an order is only checking 2 conditions, 1) for a button click bool and 2) the position being flat. Once the button is clicked the bool remains true until the button is clicked again. The other entry condition is checking to see if the position is flat, the position object cannot be updated until the order has been sent to the exchange, received, filled, and acknowledged back which takes physical time to perform, meanwhile your code continues to execute as each new tick comes in and when the button click is true and the position remains flat, orders will continue to be submitted as fast as the ticks come in.

    To prevent multiple unintended orders, you would need to add another entry condition.

    You can add code to limit the order entry to no more than once per bar. This can be done by using the systems CurrentBar which is the bar number that is being processed and by using an int variable (that you create, likely one for long and one for short). In the entry condition, you would check to see if the CurrentBar is NOT equal to the int variable. In the action part of the if statement where you submit the order you would then assign CurrentBar to the int variable. The first time the button is clicked (which sets a bool true) and you are flat the current bar number will not be equal to the int variable so the order will be sent and the current bar number is then saved to the int variable. On the very next tick, the button bool is still true, the position is still flat however now the CurrentBar is equal to the int variable so the condition is no longer true and this will prevent further orders from being placed.

    Reference: https://ninjatrader.com/support/help...currentbar.htm

    If you need the ability to place an order multiple times within the same bar then you would need to come up with logic that would allow you to do that again adding a condition into the entry block.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you very much Paul.
      That helped me perfectly !

      Regards.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by algospoke, Yesterday, 06:40 PM
      2 responses
      19 views
      0 likes
      Last Post algospoke  
      Started by ghoul, Today, 06:02 PM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      45 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      20 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      181 views
      0 likes
      Last Post jeronymite  
      Working...
      X