Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

variable stoploss

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

    variable stoploss

    Hello,

    in my coding I change the stoplosses with certain ticks as variables.

    Now I want to change this method and I want to use variables referring to indicators. The reason for this is that with having stoplosses and exits by indicators there happen overfills.

    To avoid this I want to use the value of the indicator (eg ATR) as stoploss-variable. So this works as stoploss at the brokers server and will be changed from my PC and there can not happen an overfill.

    How can I code eg the ATR as variable please?

    Thanks
    Tony
    Last edited by tonynt; 06-24-2011, 02:48 PM. Reason: typing error

    #2
    Tony, are you just trying to get the value of ATR and store it in a variable? You can do so like this, but be sure to add in the other SetStopLoss parameters such as signal name:

    Code:
    double atr_value = ATR(10)[0];
    SetStopLoss(atr_value, ...);
    If that isn't what you're trying to do, can you please clarify?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hello Austin,

      thank you for your support and reply. Yes, this I want to do. Is there a sample beside the "sampleUserVariables" as there it is not explained how to store and work with.

      Thanks
      Tony

      Comment


        #4
        Tony, unfortunately there are not any other samples. This will have to be done in code, the Strategy Wizard is not able to evaluate mathematical expressions to adjust the ATR.

        How I wrote it above is pretty much exactly how it would work out in code.

        In the variables section is where you'll want to declare the atr_value variable:
        Code:
        #region Variables
        double atr_value = 0;
        #endregion
        And then in OnBarUpdate() is where you'll use it:
        Code:
        atr_value = 3 * ATR(10)[0]; // set atr_value to three times the 10 period ATR
        SetStopLoss(atr_value, ...); // set the stop loss to atr_value
        AustinNinjaTrader Customer Service

        Comment


          #5
          Hello Austin,

          thank you. Will NinjaTrader change the stoploss with this coding every time the ATR value changes? And how do I use the atr eg only for my "Long2" as the "Long1" has different exit-rule or stoploss.

          Best
          Tony
          Last edited by tonynt; 06-24-2011, 03:33 PM.

          Comment


            #6
            Tony, that is correct. It is advisable to run the code I posted only when entering a position. You'll also have to add/subtract atr_value from the current price to get the stop/target value if you use CalculationMode.Price. You can also specify which position you wish to set the stop for, that is what the ... was for in the code I posted.

            For example, working with SetStopLoss, you could do this:
            Code:
            //SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool simulated)
            SetStopLoss("Long2", CalculationMode.Ticks, atr_value, false);
            AustinNinjaTrader Customer Service

            Comment


              #7
              Austin,

              There´s just one small "non-understanding" on my end with definiton of ATR.

              with indicators in the forum there is ATR eg with 1,3,3 (ATRMultiplier, ATRPeriod, MedianPeriod)

              and your coding is atr_value3 = ATR(10) and atr_value3 * 3...

              Sorry for this question but how can I change your ATR eg to 1,3,3?

              Thank you for your support and have a great weekend!

              Best
              Tony

              Comment


                #8
                Tony, the only ATR I know of stands for Average True Range (this is the one that comes with NinjaTrader). It measures the range (range = high - low) of each bar, and then averages it over a certain number of bars (period). In the example we've been working with, the period is set to 10. Then I multiplied it by 3, which would take care of the ATRMultiplier parameter you reference here.

                I am not sure what MedianPeriod means.

                Other than the MedianPeriod, to change the code I gave you to 1,3, it would go like this:
                Code:
                atr_value = ATR(3)[0];
                // anything times itself is 1, so no need to multiply by 1.
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Thank you for your reply. But the position is not closed with SetStopLoss("Long3", CalculationMode.Ticks, atr_value3* 3, false);

                  The 3rd position is closed either at initial stoploss or exit on close. Please see the attached jpg. I have added also an ATRstop-hash-line with settings (1,3,3).

                  Sorry for misunderstanding on my end but what might be the reason why it is not closed with ATR (no matter if I change values of atr)?

                  Thanks
                  Tony

                  Originally posted by NinjaTrader_Austin View Post
                  Tony, the only ATR I know of stands for Average True Range (this is the one that comes with NinjaTrader). It measures the range (range = high - low) of each bar, and then averages it over a certain number of bars (period). In the example we've been working with, the period is set to 10. Then I multiplied it by 3, which would take care of the ATRMultiplier parameter you reference here.

                  I am not sure what MedianPeriod means.

                  Other than the MedianPeriod, to change the code I gave you to 1,3, it would go like this:
                  Code:
                  atr_value = ATR(3)[0];
                  // anything times itself is 1, so no need to multiply by 1.
                  Attached Files
                  Last edited by tonynt; 06-26-2011, 04:16 PM. Reason: typing error

                  Comment


                    #10
                    Tony, please strip your strategy down to a single entry and exit on a single timeframe and then once you get the ATR stop working there, you can start adding more positions and more complicated strategy logic.

                    The ATR indicator you're using isn't a standard NinjaTrader indicator. If you have a question about it, please contact the author.
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      Thank you for your reply.

                      I have done so and only one entry and one timeframe but exit is only at iniitial stoploss or close on end of session. Please see attached files.

                      Thanks
                      Tony





                      Originally posted by NinjaTrader_Austin View Post
                      Tony, please strip your strategy down to a single entry and exit on a single timeframe and then once you get the ATR stop working there, you can start adding more positions and more complicated strategy logic.

                      The ATR indicator you're using isn't a standard NinjaTrader indicator. If you have a question about it, please contact the author.
                      Attached Files

                      Comment


                        #12
                        Tony, please enable TraceOrders in your strategy and check where the stop value would come out at if you enter the double ATR value in the ticksize SetStopLoss mode.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Bertrand, I have done. You know that in HelpGuides there is only the example "TraceOrders = true", this is of course enough as example. But does this work in strategy analyzer? Where is the NinjaScript Output window?.....

                          Comment


                            #14
                            Yes, this will work in backtesting, too - the output window is found under Tools > Output window.
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Great tool. Done, too. What do we see with this now please? Why is the double ATR value in the ticksize SetStopLoss mode not working? Please see the attached file.

                              PS: When I know this last brick for the strategy I will not ask you for a long time!

                              Thanks

                              Originally posted by NinjaTrader_Bertrand View Post
                              Yes, this will work in backtesting, too - the output window is found under Tools > Output window.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Rapine Heihei, Today, 08:19 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by Rapine Heihei, Today, 08:25 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Rapine Heihei  
                              Started by f.saeidi, Today, 08:01 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by Rapine Heihei, Today, 07:51 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post Rapine Heihei  
                              Started by frslvr, 04-11-2024, 07:26 AM
                              5 responses
                              98 views
                              1 like
                              Last Post caryc123  
                              Working...
                              X