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?
    JesseNinjaTrader Customer Service

    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.
          JesseNinjaTrader Customer Service

          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?
              JesseNinjaTrader Customer Service

              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().

                  JesseNinjaTrader Customer Service

                  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.


                        JesseNinjaTrader Customer Service

                        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 WilliCarls, Today, 02:01 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post WilliCarls  
                              Started by Pa_Baz, 12-14-2024, 09:40 PM
                              47 responses
                              790 views
                              1 like
                              Last Post Gianmarco Giorgi  
                              Started by powbordon1126, 02-06-2025, 08:47 PM
                              3 responses
                              27 views
                              0 likes
                              Last Post rockmanx00  
                              Started by dhanushatrader96, Yesterday, 10:24 PM
                              1 response
                              11 views
                              0 likes
                              Last Post bltdavid  
                              Started by reynoldsn, Yesterday, 07:52 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post reynoldsn  
                              Working...
                              X