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

Stop Orders Move

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

    Stop Orders Move

    I am using a 2 step rule to create a Stop Market order based on current low when rules are meet

    SO condition A True, then X rule is True

    IF X rule is true and condition B true, then Y is True

    IF X and Y are True enter Stop Order at Low[0] - 5 ticks, and set Rule X to false (so that it will have to find another Condition A setup to then Set Rule X to True again and move the Order to a new level.

    ALL OF THIS WORKS CORRECTLY so far as creating the Stop order

    Issue is the Stop order on each new bar immediately moves to the Low[0] -5 ticks,

    I do not wish the order to move,

    Am i using the wrong order type?

    Thanks

    #2
    Hello DTSSTS,

    Thanks for your post.

    I suspect you have assigned the value of Low[0] - 5 ticks to the stop order directly so as each bar updates the stop moves to the next bars low minus 5 ticks.

    What you will need to do is to assign the value you want the stop to be at to a variable, ie; double myStopValue = Low[0] - 5 *TickSize and use the variable in the stop order. In addition, you would need to prevent that variable from being changed until you are ready to change it. So likely will need to use a bool variable to prevent it from being changed until the bool is reset.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      ok i follow the adding the double variable and did after several days of tweaking the rules to go back form True to false got the stop order to do what i wanted

      but now I am having an issue with an old order that wants to resubmit, my example is on NQ and says cannot submit below the market, if is a buy stop order that would cover a short position

      it is resubmitting exactly when a new short position is taken but it is 110 points below the the position

      this same order has resubmitting on last 2 short positions and the error is closing my position and disable the strategy

      First not sure why that would reject, Second my rule occurs when Entry bar is Greater than 0, so i am sure by the price and the instant submitting that is is something old trying to resend

      i am sure i am missing something, thanks for the help

      Comment


        #4
        Hello DTSSTS,

        Thanks for your reply.

        I would suggest debugging your script to find out why you are resubmitting the order with an incorrect value. I would print out the value of the variables that are used to determine the exit orders price level.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          i figured this order was live and another method of exit occurred and I need to send some the actions to cancel all live orders pending

          Comment


            #6
            Hello DTSSTS,

            Thanks for your reply.

            If your question is how to cancel orders then please see this example: https://ninjatrader.com/support/help...thod_to_ca.htm
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              DTSSTS can you please show us your code? The behavior you are seeing is exactlyt the behavior I WANT to see, but I cannot get it to work. I use managed orders and try to enter a (say) buy stop order just above the candle that just closed. I do this in OnBarUpdate. But if that order does not fill, it cancels and I cannot seem to get a new stop order submitted above the new candle that just closed. How did you get this to work?

              Comment


                #8
                Most of this code will not help you. But i use a custom bar (cross between a renko and hienki) It is available on my website along with a Chart Trader with buttons 199 per year. characteristics of the bar make it very customizable for many things. Here's the code regarding the order. Item Set 7 I think got rid of the old order when NOT wanted from coming back. Need more live testing to be sure.

                This code runs OnPriceChange the key is the 2 rules that both occur intrabar Set 1 has the Long Setup Rule ONE my bar the Low and the Open are equal always for many ticks so i am looking for when the bar is much lower *you could use your rule in place of mine. (Low[0] + (10 * TickSize)) for example would give you a intrabar where the instrument went down 10 ticks after the open
                That sets the first part of my conditions. After rule 1 is set then SET 2 checks for the bar to move intrabar back up (again my custom bar will alway go above the High1 before it creates a new bar, so my rule for Close[0] is intrabar current price of the same bar - you will need to figure out your Second step of your rule. In SET 2 the action sets Rule 2 true and set the double Paul suggested for the Order.

                I named the variable LongStopVarOrder and set the price of that order and is used in SET 81 there are several bools of when to use this Exit plan. Main thing for you is Rule 2 is true and action for the order to be place (in my case i am submitting that order intrabar where all of the action has taken place, you likely will be on the next bar since you are referring to High and High has not be established yet. assuming you are running OnBarClose these type rules might work pretty close to what they are AGAIN the 2 rules are moving the conditions 1 step at a time

                the behavior of what happen to my order after it was placed was my biggest issue and many test showed different results that were based on When and how the rules were returned to False

                IF YOU RETURN TO FALSE ON THE NEXT BAR, without the Double Paul suggest they would cancel and reappear each time conditions were meet. My goal was to reposition the stop each time conditions were meet. so SET 3 after the close of the Bar sets my Rule 1 to false. Again Low0== open 0 will not work for you, Mainly get Rule 1 set back to false

                I used the BarsSinceEntryExecution because I did not want these conditions to be considered until my entry bar had close - you should not need this

                last SET 7 when my order kept reappearing as soon as a position was taken I need to set all rules to false as to get a fresh start

                My use here is a variable Stop that intrabar places itself near the low of that bar and stays there if the Same bar makes a new low I have a stop in place to protect profits and if the next bar revisits that same level the same. After price advances the stop remains at the level until the condition occurs again. my Low[0] = Open[0] on my custom bar can be true for many bars. I am interested in placing a tighter stop with volatility presents itself

                HOPE USING 2 RULES HELPS YOU HERE IS THE CODE

                **********************************************





                // Set 1
                if ((Position.MarketPosition == MarketPosition.Long)
                && (BarsSinceEntryExecution(0, "", 0) > 0)
                && (Low[0] != Open[0]))
                {
                LongRuleLowLessOpen = true;
                }

                // Set 2
                if ((LongRuleLowLessOpen == true)
                && (Close[0] >= High[1])
                && (Position.MarketPosition == MarketPosition.Long)
                && (BarsSinceEntryExecution(0, "", 0) > 0))
                {
                LongRULE2LowLessOpen = true;
                BarBrush = Brushes.Linen;
                LongStopVarOrder = (Low[0] + (LongTrailStopTicks * TickSize)) ;
                }

                // Set 3
                if ((LongRULE2LowLessOpen == true)
                || (Position.MarketPosition == MarketPosition.Long)
                || (Low[0] == Open[0])
                || (Close[1] > Close[2])
                || (BarsSinceEntryExecution(0, "", 0) > 1))
                {
                LongRuleLowLessOpen = false;
                }

                // Set 4
                if ((Position.MarketPosition == MarketPosition.Short)
                && (BarsSinceEntryExecution(0, "", 0) > 0)
                && (High[0] != Open[0]))
                {
                ShortRuleHighGreaterOpen = true;
                }

                // Set 5
                if ((ShortRuleHighGreaterOpen == true)
                && (Close[0] <= Low[1])
                && (Position.MarketPosition == MarketPosition.Short)
                && (BarsSinceEntryExecution(0, "", 0) > 0))
                {
                ShortRULE2LowGreaterOpen = true;
                BarBrush = Brushes.Linen;
                ShortStopVarOrder = (High[0] + (ShortTrailStopTicks * TickSize)) ;
                }

                // Set 6
                if ((Position.MarketPosition != MarketPosition.Short)
                || (High[0] == Open[0])
                || (LongRULE2LowLessOpen == true)
                || (Close[1] < Close[2])
                || (BarsSinceEntryExecution(0, "", 0) > 1))
                {
                ShortRuleHighGreaterOpen = false;
                }

                // Set 7
                if (Position.MarketPosition == MarketPosition.Flat)
                {
                LongRuleLowLessOpen = false;
                LongRULE2LowLessOpen = false;
                ShortRuleHighGreaterOpen = false;
                ShortRULE2LowGreaterOpen = false;
                }





                // Set 81
                if ((Position.MarketPosition == MarketPosition.Long)
                && (PerBarExitONEmade == false)
                && (VariableStop == true)
                && (LongRULE2LowLessOpen == true))
                {
                ExitLongStopMarket(Convert.ToInt32(Position.Quanti ty), LongStopVarOrder, @"Exit LS VS", "");
                }

                // Set 82
                if ((Position.MarketPosition == MarketPosition.Short)
                && (PerBarExitONEmade == false)
                && (VariableStop == true)
                && (ShortRULE2LowGreaterOpen == true))
                {
                ExitShortStopMarket(Convert.ToInt32(Position.Quant ity), ShortStopVarOrder, @"Exit SS VS", "");
                }

                GOOD LUCK

                Comment


                  #9
                  WestofPluto I gave some thought to you stating you WANTED the order to come back, which I guess means you want you order to either move if not filled or re send. Not sure what exactly but try in SET 7 (again not sure what your are using to set to false likely that Position is NOT Equal to Flat) but try removing Rule 2 from the reset to false and try removing Rule 1 and Rule 2 as you test IF what I am doing does not work

                  Comment


                    #10
                    Paul

                    I am now adding an Exit Profit Target, again using the value of an indicator at the time the order is sent (this indicator value could change before price reaches target

                    So I need to do a double variable again as I did on the Stops?

                    Also if i wish to scale out of position with 2 different targets, I need to have a use input as to how much of the position to exit at first scale

                    WHAT type input is that double or int?

                    also if that input is set by user to 100 shares / contracts, the trade proceeds to the first target order, exits 100 shares then proceeds to target 2 or stops out I have the stops and next target set to currentposition so the balance of position will be exited

                    WHAT IF input is 100 shares and that is the total position, so target 1 actually will close the position, what happens to target 2

                    Thanks

                    Comment


                      #11
                      Hello DTSSTS,

                      Thanks for your reply.

                      "So I need to do a double variable again as I did on the Stops?", Yes, price will always be a double type.

                      "WHAT type input is that double or int?" For position quantities, it would be an int type.

                      "WHAT IF input is 100 shares and that is the total position, so target 1 actually will close the position, what happens to target 2". You would likely need to cancel the target2 order or better yet not create target 2 when the quantity is 100.
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        since i do not know what a client might do, guess need to check currentposition size to be greater than input 1 size ie greater than 100 as part of sent target 2

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by cmtjoancolmenero, Yesterday, 03:58 PM
                        2 responses
                        19 views
                        0 likes
                        Last Post cmtjoancolmenero  
                        Started by Stanfillirenfro, 04-22-2024, 09:19 AM
                        8 responses
                        59 views
                        0 likes
                        Last Post Stanfillirenfro  
                        Started by olisav57, Yesterday, 07:39 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by cocoescala, 10-12-2018, 11:02 PM
                        7 responses
                        941 views
                        0 likes
                        Last Post Jquiroz1975  
                        Started by oviejo, Today, 12:28 AM
                        1 response
                        11 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Working...
                        X