Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

combining stop loss and price crossover simple moving average protective stop

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

    combining stop loss and price crossover simple moving average protective stop

    i have a stop loss of 10 but i'd like an additional measure to ensure stops that make sense earlier than that if they occur. i'd like to have a stop when price drops lower than the simple moving average i use SMA(Low,10) it may at times be less than the stop loss of 10.

    what might the code look like?

    sell market order()
    if Close[0] < SMA(Low,10)[0]

    #2
    Hello SteveReiza,

    I am not certain I follow with the description. Are you saying that you entered a position and have an existing stop loss, you now want to move it when the price crosses an SMA?

    Comment


      #3
      yes, that's correct.

      Comment


        #4
        sometimes the stop loss is up higher than the sma. so its not all the time. but, when the sma does go higher than the stop loss, i want to use that.

        Comment


          #5
          Hello SteveReiza,

          If you are trying to do a single movement when the price crosses below the SMA you should use a CrossBelow condition for that:



          In the condition you can call the order method again to update its price. If you used SetStopLoss you would call SetStopLoss again inside the condition with new values to update the existing stoploss.

          Comment


            #6
            sweet. i'm using a setstoploss with an increment; profit trigger 12, profit target 2. i don't think i need to add it to the setstoploss. so it would be:

            if CrossBelow(Active Position[0], SMA(Low,10,0)0)
            EnterShort()​

            Comment


              #7
              Hello SteveReiza,

              I am not sure I follow, are you trying to reverse the position and enter into the opposite direction based on the SMA rather than moving a stoploss?

              Comment


                #8
                no, i'm just trying to exit the position. wouldn't a sell market close the active long position?

                Comment


                  #9
                  Hello SteveReiza,

                  If you are trying to just exit the position then you would need to submit an exit order as the action of the condition. For example if you were in a short position you would use ExitShort().

                  Comment


                    #10
                    Oh that's sweet. Thank you.

                    Comment


                      #11
                      so if i'm active in a position is it still close[0]. it would be like this:

                      if CrossBelow(Close[0], SMA(Low,10,0)0)
                      ExitLong()​​

                      Comment


                        #12
                        Hello SteveReiza,

                        The CrossBelow function can take two series so you could just use Close

                        Code:
                        if (CrossBelow(Close, SMA(Low, 10), 1))
                        {
                        
                        }
                        You need at least 1 for the crossbelows lookback period for it to detect crosses.


                        Comment


                          #13
                          sweet, thanks. that won't do though. i'm in real time when i see the price move below the simple moving average. it is one bar ago, but i see the current bar go below it, then i exit. is there a way to code that?

                          Comment


                            #14
                            Hello SteveReiza,

                            In real-time to evaluate logic and trigger actions before the bar closes (intra-bar), use Calculate.OnPriceChange or Calculate.OnEachTick.

                            (In historical TickReplay and 1-tick intra-bar granularity is necessary for intra-bar order submissions and fills.
                            https://ninjatrader.com/support/foru...377#post773377)
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              alright, sweet. thank you. i have enough to give to a vendor to help code.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              633 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              567 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X