Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiples of Indicators

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

    Multiples of Indicators

    Hi,

    I've just started using NinjaScript for backtesting and I want to program in a trailing stop loss that is (for example)- Twice the 14 day ATR. I can set a stop loss that is the ATR of 'x' days but I am unable to set it as a multiple of this; any suggestions?

    Also, I want to control the position size (number of contracts bought or sold on an entry signal) by making sure that the risk (distance from order entry price to stop loss) is for example 1% of the account size. I am completely lost as to how I can control these variables which decide position size and risk control; I would appreciate any suggestions.

    Many thanks,
    Attached Files
    Last edited by ciaranfryan; 04-09-2009, 03:41 PM.

    #2
    stop = ATR(14)[0] * 2

    Could you use that and just call your stop loss with that price?
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      How do I program in * 2

      Thanks for your help; Yes my problem is how to program in the " * 2 " bit?

      I'm using the strategy wizard; should I be looking at the actual code? When I type in - " * 2 " in the strategy wizard it just sets the value to zero?

      Also, any ideas on the position sizing question?

      Many thanks, really appreciate your help

      Comment


        #4
        ciaranfryan,

        You need to use the Offset parameters. Choose the Offset type = percent and just offset by 1 which would equate to a 100% offset or * 2.

        Position size does not need to be done in the code. When you run the strategy you can choose how your strategy determines position sizes. Choose the option for "By account size" and then just manually type in what 1% of your account size is and it will make trades for up to that amount.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Problems setting stop loss

          Okay, so I have a simple test strategy set up as follows- when the fast SMA of 20 days crosses above the 40 day SMA enter one position long and when the fast 20 day SMA crosses below the slower 40 day SMA enter one position short.

          I also want to set a stop loss at a distance of twice the 10 day ATR from the entry price; so i did as follows- When the SMA crossover entry signal occurs apart from entering a position my strategy also 'sets a user defined variable - Variable0' of twice the 10 day ATR. On the stop loss page of the wizard i then set a stop loss using calculation mode 'ticks' and entered the value as 'Variable0'.

          However when I test the strategy it's not working- it keeps stopping my positions out as soon as it enters them- on the chart for example when an entry signal is hit the chart reads - 'Buy 23,938 @ 36.48, Stop loss 23,938 @ 36.48'.

          Can anyone tell me what I'm doing wrong?

          Many thanks for all the help; this forum is terrific!

          Comment


            #6
            Try choosing CalculationMode = Price and then choose Variable0.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Stop Loss not executing

              Hi Josh,

              Thanks again for your help. I did as you said; set the calculation mode to 'price' instead of ticks but now I run the test and the stops don't execute at all.

              [IMG]file:///C:/DOCUME%7E1/Ciaran/LOCALS%7E1/Temp/moz-screenshot.jpg[/IMG]I have set the stop loss as Variable0 which I have set in this case as ATR (10)(0)*4 which is set when the position is initially entered.

              I have attached a screenshot of the chart showing the trades made during when I backtested the strategy. As you can see when I entered a short position 29,368 at 34.17 I should have been stopped out at a distance of 4 times the ATR from the entry point (1.32 x 4 = 5.28 =4*10 day ATR). This would be a price of (34.17 + 5.28 = 39.45). However the price closes above 40 at one point and my stop does not hit. I backtested the strategy for a period of 1 year and no stops were hit.

              Any help would be greatly appreciated.

              Regards,

              ciaranfryan

              [IMG]file:///C:/DOCUME%7E1/Ciaran/LOCALS%7E1/Temp/moz-screenshot-1.jpg[/IMG]

              Comment


                #8
                ciaranfryan,

                Unfortunately I cannot see the screenshots. Can you please try reposting them? Thanks.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Screenshot

                  Hi Josh,

                  I've reattached the screenshot; it's a word file zipped - I have to zip it because of the limit on the size of attachments.
                  Attached Files

                  Comment


                    #10
                    Hi ciaranfryan, thanks for the screenshot, please contact us at support at ninjatrader dot com Attn Bertrand with the strategy zip so we can take a look and advise - Thanks!
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by ciaranfryan View Post
                      Hi Josh,

                      I've reattached the screenshot; it's a word file zipped - I have to zip it because of the limit on the size of attachments.
                      If you screenshot file size is too big, make the chart smaller first or use a different compression like .png.
                      eDanny
                      NinjaTrader Ecosystem Vendor - Integrity Traders

                      Comment


                        #12
                        Using NinjaScript Editor to Set Trailing Stops

                        Okay so I'm now trying to use the NinjaScript Editor to set my trailing stop.

                        Basically I'm using a simple SMA crossover system to generate entry signals. I want a trailing stop loss to be set when the position is entered at a distance of 4 times the 10 day ATR from the entry price. I then want the stop loss to trail the close price each day as the position moves in my favour. For example- the entry price is $ 10, initial trailstop is set at 4*10dayATR which happens to be a distance of 2 = $ 8. If the position the next day moves in my favour to $ 11 I want the stop to trail to $ 9.

                        Below is what I have so far; is this correct?


                        ///<summary>
                        /// This method is used to configure the strategy and is called once before any strategy method is called.
                        ///</summary>
                        protectedoverridevoid Initialize()
                        {
                        SetTrailStop(
                        "Entry1", CalculationMode.Price, ATR(10)[0]*4, false);
                        SetTrailStop(
                        "Entry2", CalculationMode.Price, ATR(10)[0]*4, false);
                        CalculateOnBarClose =
                        true;

                        /// This will add the SMA indicator to the chart for visualization
                        Add (SMA (SMA1, SMA2));

                        Comment


                          #13
                          You can't call that in Initialize(). You are using a dynamic value and as such you have to do it from OnBarUpdate().
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by judysamnt7, 03-13-2023, 09:11 AM
                          4 responses
                          59 views
                          0 likes
                          Last Post DynamicTest  
                          Started by ScottWalsh, Today, 06:52 PM
                          4 responses
                          36 views
                          0 likes
                          Last Post ScottWalsh  
                          Started by olisav57, Today, 07:39 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post olisav57  
                          Started by trilliantrader, Today, 03:01 PM
                          2 responses
                          21 views
                          0 likes
                          Last Post helpwanted  
                          Started by cre8able, Today, 07:24 PM
                          0 responses
                          10 views
                          0 likes
                          Last Post cre8able  
                          Working...
                          X