Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stoploss - double

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

    stoploss - double

    Hello,

    I´m using stoploss with Donchian and I want to ask when the stoploss moves and changes his value? Can SetTrailStop be used for variable like Donchian? I remember in another thread there was the information that SetTrailStop doesn´t work with Mode.Price.

    So what do I have to code for having the stoploss each bar the actual value of Donchian?

    Thanks
    Tony
    Last edited by tonynt; 07-26-2011, 06:52 AM. Reason: typing error

    #2
    Correct Tony, you can't use SetTrailStop then - you would call SetStopLoss again in your OnBarUpdate() if you would like to change the stop loss price, so basically each bar update as your Donchian value changes then.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks Bertrand,

      but it doesn´t change each bar!. It changes only when the if condition is filled (here the 90 ticks) - referring to the samplepricemodification. This is my coding - I think it should be correct as done same as in the sample.

      if (BarsInProgress !=0)
      return;

      stop1=DonchianChannel(3).Upper[0]+5*TickSize;
      stop2=DonchianChannel(5).Upper[0]+5*TickSize;
      stop3=DonchianChannel(6).Upper[0]+5*TickSize;

      if(Position.MarketPosition == MarketPosition.Flat)
      { SetStopLoss("SG1", CalculationMode.Price, stop1, false);
      SetStopLoss("SG2", CalculationMode.Price, stop1, false);
      SetStopLoss("SG3", CalculationMode.Price, stop1, false);

      if (Position.MarketPosition == MarketPosition.Short
      && Close[0] < Position.AvgPrice - 90 * TickSize)

      { SetStopLoss("SG1", CalculationMode.Price, stop1, false);
      SetStopLoss("SG2", CalculationMode.Price, stop2, false);
      SetStopLoss("SG3", CalculationMode.Price, stop3, false);
      }

      Why does stop move only with the if condition and not from the beginning each bar?
      I´m in the direction of the trade maybe 80 ticks and Donchians moves with my bars but the initial stoploss stays same value.

      Thanks
      Tony

      Comment


        #4
        Tony, the stop is only moving with the if conditions because you've placed it in the if statement code block.

        It will also not move until the trade is 90 ticks in profit.

        Please try simplifying your strategy to one position and one moving stop loss and once you get that figured out you can add the additional positions and stops.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Austin,

          thank you for your reply. You are right of course with the way to debug. But the "stop1" is also in the "if flat" statement. No? There´s no other difference in the both statements as if 90 ticks then change the donchian values for 2nd and 3rd entry.

          Comment


            #6
            If there is no position, then there is no stop loss able to be changed. Setting the stop loss when flat is just for resetting the stop losses, it won't assign a stop loss to your positions.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Oh, big mistake. Thank you! Sorry for the question.

              Originally posted by NinjaTrader_Austin View Post
              If there is no position, then there is no stop loss able to be changed. Setting the stop loss when flat is just for resetting the stop losses, it won't assign a stop loss to your positions.

              Comment


                #8
                Not a problem, Tony. Let us know what you get figured out.
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Austin, referring to you information I have changed now to the following coding but this does´t work

                  if (BarsInProgress !=0)
                  return;

                  stop1=DonchianChannel(3).Upper[0]+5*TickSize;
                  stop2=DonchianChannel(5).Upper[0]+5*TickSize;
                  stop3=DonchianChannel(6).Upper[0]+5*TickSize;

                  if(Position.MarketPosition == MarketPosition.Flat)
                  { SetStopLoss("SG1", CalculationMode.Price, stop1, false);
                  SetStopLoss("SG2", CalculationMode.Price, stop1, false);
                  SetStopLoss("SG3", CalculationMode.Price, stop1, false); }

                  if (Position.MarketPosition == MarketPosition.Short
                  && Close[0] < Position.AvgPrice - 30 * TickSize
                  && Close[0] > Position.AvgPrice - 90 * TickSize)

                  { SetStopLoss("SG1", CalculationMode.Price, stop1, false);
                  SetStopLoss("SG2", CalculationMode.Price, stop1, false);
                  SetStopLoss("SG3", CalculationMode.Price, stop1, false); }



                  if (Position.MarketPosition == MarketPosition.Short
                  && Close[0] < Position.AvgPrice - 90 * TickSize)

                  { SetStopLoss("SG1", CalculationMode.Price, stop2, false);
                  SetStopLoss("SG2", CalculationMode.Price, stop2, false);
                  SetStopLoss("SG3", CalculationMode.Price, stop3, false); }

                  How can I change to have a variable in the stoploss untill a certain price and then changing to another variable from this certain price?

                  Thanks

                  Comment


                    #10
                    Hi Tony, you could for example add some boolean flags / user variables to your code to control the flow of the statements used better. A related sample script could be used here - http://www.ninjatrader.com/support/f...ad.php?t=15417

                    Think of the this functionality like switches that would have two values (true / false) to control which action is taken and in your case then which stop value / calculation is used at which time in the trade.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Thank you for your reply. I tried to do so but it doesn´t work as stoploss always jumps back to first condtion that is true also with condtion 2 and 3. What am I doing wrong? Thank you

                      if(Position.MarketPosition == MarketPosition.Flat)
                      {SetStopLoss("SG1", CalculationMode.Ticks, 70, false);
                      Variable1 = 0;}

                      if (Position. MarketPosition==MarketPosition.Short
                      && Close[0]<Position.AvgPrice - 60*TickSize)
                      {Variable1 = 1;}

                      if (Variable1 == 1)
                      {SetStopLoss("SG1", CalculationMode.Price, stop1,false);}

                      if (Position. MarketPosition==MarketPosition.Short
                      && Close[0]<Position.AvgPrice - 90*TickSize)
                      {Variable1 = 2;}

                      if (Variable1 == 2)
                      {SetStopLoss("SG1", CalculationMode.Price, stop2,false);}

                      if (Position. MarketPosition==MarketPosition.Short
                      && Close[0]<Position.AvgPrice - 150*TickSize)
                      {Variable1 = 3;}

                      if (Variable1 == 3)
                      {SetStopLoss("SG1", CalculationMode.Price, stop3,false);}

                      Comment


                        #12
                        Tony, you would also need a check what your variable state is here in the first condition, so it would not always evaluate to true and force changes in your stoploss but only if your variable is reading a certain state where you would like this to to triggered again.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          ????????????

                          Comment


                            #14
                            Tony, by your reply, I was unfortunately not sure which part was unclear to you, but I hope the attached strategy can help shed some more light on the topic.

                            Good luck,
                            Attached Files
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Thank you!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by tsantospinto, 04-12-2024, 07:04 PM
                              7 responses
                              126 views
                              0 likes
                              Last Post aligator  
                              Started by futtrader, 04-21-2024, 01:50 AM
                              5 responses
                              56 views
                              0 likes
                              Last Post NinjaTrader_Eduardo  
                              Started by PeakTry, Today, 10:49 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post PeakTry
                              by PeakTry
                               
                              Started by llanqui, Today, 10:32 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              45 responses
                              3,994 views
                              3 likes
                              Last Post johntraderuser2  
                              Working...
                              X