Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Avoid Multiple Orders from the same condition

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

    Avoid Multiple Orders from the same condition

    Hi,

    I have a strategy where it places buy stop orders when the close of the current bar satisfies some conditions.

    I have two questions and hoping somebody can clarify...

    1) When the conditions are first satisfied at the close of a bar and the buy stop order is placed, what is the duration of the order? I mean how long does the order stay active. Until the close of the current bar or until it is executed or canceled.

    2) Once the current bar close satisfies the conditions to place a buy stop order, how do I prevent subsequent bar closes that satisfy the same conditions from placing the same order?

    Thanks for your help!

    #2
    1. By default you have 1 bar to fill it. It will auto cancel unless you keep it alive by calling EnterLongStop() or whatever your entry method was again. You have the option to turn it to live-until-cancelled if that is the behavior you wish for. Please see the helpg uide article on EnterLongStop() for more information on that.

    2. You will want to use a flag variable.
    Code:
    // In Variables section of your code
    private bool flag = true;
    
    // In OnBarUpdate()
    if (some condition && flag)
    {
         EnterLongStop(....);
         flag = false;
    }
    Note: This flag will prevent any resubmission of the order to keep it alive. You will need to play around if you want to keep the order alive.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh. That worked.

      However, now I have a different problem...

      My strategy buys with an order name of "Long" and exits a long position by an order name of "ExitLong".

      It sells with an order name of "Short" and exits a short position by an order name of "ExitShort".

      While it was running today, when the condition to go long was met, it placed a buy order ("Long"). When the condition to exit long was met, it placed an ExitLong order ("ExitLong"). That was the desired performance.

      Next, the condition to go short was met. This is when it got strange.
      The strategy correctly placed a short order with the label "Short".

      However, at the SAME time, it also placed another short order at the SAME price with a label "Close Position".

      A little later, the condition to close out my open positions (the start of a new bar) was met. At that time both short positions were closed with a label "Buy to Cover"

      I would like to understand where the extra short position that I had not coded came from.

      How do I suppress that extra order or resolve that situation?

      Thanks for your help.

      Comment


        #4
        menlo,

        That is correct. If you try to place an EnterShort() order when you still have an active long position it will first close your long position and then get you into your short position. You need to ensure you no longer have a long position before submitting your short position if you do not want this.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mmenigma, Yesterday, 03:25 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by kujista, Today, 05:44 AM
        0 responses
        6 views
        0 likes
        Last Post kujista
        by kujista
         
        Started by ZenCortexCLICK, Today, 04:58 AM
        0 responses
        9 views
        0 likes
        Last Post ZenCortexCLICK  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        172 responses
        2,281 views
        0 likes
        Last Post sidlercom80  
        Started by Irukandji, Yesterday, 02:53 AM
        2 responses
        18 views
        0 likes
        Last Post Irukandji  
        Working...
        X