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

Using Indicator as Stop Loss

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

    #16
    Hello Trader17,

    Thanks for the reply.

    Yes, that snippet looks good. Please, always test on the Sim101 account to confirm the behavior you were looking for.

    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    Comment


      #17
      Always on Sim first as I am still learning Ninja Script.
      Thank you.

      Comment


        #18
        So do I simply replace SetStopLoss with SetTrailStop in the above example using MIN and MAX?
        • SetTrailStop(CalculationMode.Price, MAX(5)[0]);
        Is the above correct?

        Thank you.

        Comment


          #19
          Hello Trader17,

          I apologize, I didn't notice that we could not have a calculation mode of Price when using SetTrailStop, you can only use Percent, Ticks, or Pips. If you wanted the same result from SetTrailStop, a little more coding is involved. You would need to write a function that figures out the tick range between the Min/Max of previous bars and your entry price, then use the return value of that function in SetTrailStop.

          Please let me know if I can assist further.
          Chris L.NinjaTrader Customer Service

          Comment


            #20
            Thank you. Maybe a future enhancement to allow Strategy Builder to do this using an Indicator. Like running a Trailing Stop using the MIN or MAX or other indicators.

            Also why would an additional function need to be written using MIN or MAX as we are using the value derived directly form the bar and are not concerned with or using the Entry Price for the calculation.

            Thank you.

            Comment


              #21
              Originally posted by NinjaTrader_ChrisL View Post
              Hello Trader17,

              Thanks for the reply.

              You can add or subtract ticks like so:

              SetStopLoss(CalculationMode.Price, MIN(5)[0] -TickSize,tick);

              To subtract two ticks:

              SetStopLoss(CalculationMode.Price, MIN(5)[0] -(TickSize*2),tick);

              Please let me know if you have any questions.

              Thank you Chris. I got a compile error when I tried using the code above. When I removed the word "tick" it compiled without errors. So using it this way did not send any errors back. Am I right?

              SetStopLoss(CalculationMode.Price, MIN(5)[0] -(TickSize*2));

              Thank you.
              Attached Files

              Comment


                #22
                Hello Trader17,

                Thanks for the reply.

                The SetStopLoss method only has two overloads seen on this page:



                To answer your question on the trail stop, you could not use the raw price in a Trailing Stop because the method needs a more abstracted price type, like an amount of ticks to trail by or a percentage to trail by.

                Please let me know if I can assist further.

                Chris L.NinjaTrader Customer Service

                Comment


                  #23
                  So is this correct? I am trying to add or subtract a few ticks from the stop value. If I am deducting 2 ticks from the value. Thanks.
                  • SetStopLoss(CalculationMode.Price, MIN(5)[0] -(TickSize*2),2);

                  Instead of this:
                  • SetStopLoss(CalculationMode.Price, MIN(5)[0] -(TickSize*2),tick);

                  This one works in the strategy as I need it to:

                  SetStopLoss(CalculationMode.Price, MIN(Low,3)[0]-(TickSize*2));

                  Last edited by Trader17; 10-26-2018, 10:29 AM.

                  Comment


                    #24
                    Hello Trader17,

                    Thanks for the reply.

                    This would be the correct one to use if you need to subtract x amount of ticks:

                    SetStopLoss(CalculationMode.Price, MIN(Low,3)[0]-(TickSize*x));

                    Please let me know if I can assist further.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #25
                      Thank you. Got it.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
                      55 responses
                      5,455 views
                      0 likes
                      Last Post BartMan
                      by BartMan
                       
                      Started by DawnTreader, 05-08-2024, 05:58 PM
                      16 responses
                      52 views
                      0 likes
                      Last Post DawnTreader  
                      Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
                      15 responses
                      61 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by kevinenergy, Yesterday, 12:01 PM
                      8 responses
                      28 views
                      0 likes
                      Last Post kevinenergy  
                      Started by nightstalker, Today, 01:32 PM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_Zachary  
                      Working...
                      X