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

what looks like a problem setting/executing stops on strategy backtest

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

    what looks like a problem setting/executing stops on strategy backtest

    Hi,

    First of all im a ninja 6.5/trading newbie so apologies in advance if anything sounds too silly :-)

    I have been trying to get to grips with ninja strategy backtesting and have come across a problem in my hand calculation testing :

    I'm using this code to set my strategy backtest trade and stops based on daily close historic data in ninja

    EnterShort(NoOfShares,"SHORT" );
    SetStopLoss(CalculationMode.Percent, 0.10);

    and it seems superficially (im checking at the mmt) ok except that ive come across a situation where the stop isnt triggered in the following situation

    RSL.L

    20/07/2010
    OPEN - 68.15
    HIGH - 68.20
    LOW - 64.35
    CLOSE - 64.75

    21/07/2010
    OPEN - 253.8
    HIGH - 253.8
    LOW - 229.0
    CLOSE - 246.0

    So theres a rising window and my strategy had a running SHORT trade on the 20/7 which instead of being stopped out at 10% above the short entry price @ 75.35 was stopped out at 253.8 .. such a big loss i noticed it on code testing ;-)

    Now i guess I'm asking if one of the strategy or ninjacode settings can be for "guaranteed" stops rather than stopping at the next days OPEN price in this case

    rgds

    ian

    #2
    Looks like it worked as you mention.

    But there was a 1 for 30 split on the days in question you mention.

    Yahoo shows $1,942 before the split, so I'm not sure about your $68 value.

    $253/$65 = $3.89.. so that doesn't even compare to 30 for 1

    At Yahoo Finance, you get free stock quotes, up-to-date news, portfolio management resources, international market data, social interaction and mortgage rates that help you manage your financial life.


    (put in 2 year chart)

    Stock Charts shows the same thing, I'm not sure how your average price was really $75.





    Originally posted by hyena View Post
    Hi,

    First of all im a ninja 6.5/trading newbie so apologies in advance if anything sounds too silly :-)

    I have been trying to get to grips with ninja strategy backtesting and have come across a problem in my hand calculation testing :

    I'm using this code to set my strategy backtest trade and stops based on daily close historic data in ninja

    EnterShort(NoOfShares,"SHORT" );
    SetStopLoss(CalculationMode.Percent, 0.10);

    and it seems superficially (im checking at the mmt) ok except that ive come across a situation where the stop isnt triggered in the following situation

    RSL.L

    20/07/2010
    OPEN - 68.15
    HIGH - 68.20
    LOW - 64.35
    CLOSE - 64.75

    21/07/2010
    OPEN - 253.8
    HIGH - 253.8
    LOW - 229.0
    CLOSE - 246.0

    So theres a rising window and my strategy had a running SHORT trade on the 20/7 which instead of being stopped out at 10% above the short entry price @ 75.35 was stopped out at 253.8 .. such a big loss i noticed it on code testing ;-)

    Now i guess I'm asking if one of the strategy or ninjacode settings can be for "guaranteed" stops rather than stopping at the next days OPEN price in this case

    rgds

    ian

    Comment


      #3
      hyena, did this happen more than once or do you suspect it has something to do with the 1 for 30 split that sledge mentioned?
      AustinNinjaTrader Customer Service

      Comment


        #4
        hi guys,

        I'm not sure how ninjatrader would know the stock was subject to a stock split as its only got daily data in it and as far as i can tell no means of knowing about any corporate action mechanistically.

        I think its an issue of when there is a large gap up or gap down and ninja takes the "gap upped"/"gapped down" open which can be a fair way past the stop set. I havnt looked in detail for other examples. Saying that I am only at the point of testing my ninja backtest code (testing stops) and I'm a newbie :-)

        I think with this particular case its a very large gap up/down which is why it stood out so much. I just wondered if there was a parameter setting to use a "guaranteed stop" rather than ninja taking a gapped up/down open value past the stop.

        ps.

        could i ask a very quick newbie question ... Being a newbie i use the strategy wizard to generate a strategy and then i put my own strategy code in it. The problem i am having is that if i add any additional parameters later they dont show up in the backtest parameters section .. i figured i needed to add another entry (eg SmaDays below) for each additional parameter i added to the wizard generated variables section to the end section below but when i add an entry i get an error message on compilation

        "your strategy likely holds one or more recursive properties which could cause NinjaTrader to crash:SmaDays"

        Any idea what code i need to add to sort this out

        thx

        ian

        ----------------------------------------------------------
        #region Properties
        [Description("Indicator Period")]
        [Category("Parameters")]
        public int IndPeriod
        {
        get { return indPeriod; }
        set { indPeriod = Math.Max(3, value); }
        }
        [Description("Standard Position value in Pence")]
        [Category("Parameters")]
        public double PosnValue
        {
        get { return posnValue; }
        set { posnValue = Math.Max(1, value); }
        }

        [Description("SMA Days")]
        [Category("Parameters")]
        public int SmaDays
        {
        get { return SmaDays; }
        set { SmaDays = Math.Max(1, value); }
        }
        ---------------------------------------------------------------------------
        Last edited by hyena; 09-19-2011, 11:40 AM.

        Comment


          #5
          Hello hyena,

          First recommendation is to upgrade to NinjaTrader 7. There have been many bug fixes and improvements in 7 compared to 6.5. NinjaTrader 6.5 will no longer receives updates or bug fixes, should you encounter them.

          Split data would definitely explain your results. Data is commonly sent as not adjusted for splits, so they are defined locally in your NinjaTrader installation. You can find split settings in the instrument manager for a given stock, and the Yahoo connection is actually great for automatically getting the split definitions. See following link for this technique:


          I just checked and this feature works well for NT7 but not for 6.5. You may have to define your own splits manually if using 6.5.

          Here is what the compiler is saying. You use the same name in your get/set accessors as the name of the variable you're declaring. The properties region is to declare a public user defined inputs, and should be linked to a private variable. The NinjaTrader convention for this is to start with an upper-case letter for the public one, and a lower-case name for the private. This is shown in more detail here:


          You can resolve (provided you also have private smaDays declared in variables region) by making this change:


          [Description("SMA Days")]
          [Category("Parameters")]
          public int SmaDays
          {
          get { return smaDays; }
          set { smaDays = Math.Max(1, value); }
          }
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Ryan,

            hi,

            thanks for this i'll have a bash at it .. ninja 6.5 seems fine for what i need at the mmt as i have a couple of ninja indicators i use wihich are not 7 compatible yet.

            the integrity of yahoo data is aweful .. so bad in fact that i pay (ionic) for end of day LSE/Plus, NYSE/NASDAQ data and manually import in to ninja ..

            as i only import OHLC daily data in to ninja, it cant know of any corporate actions so to a newbie (me) it looks like when theres a gap up or down ninja 6.5 stops on that mornings open (well past the set stop) otherwise i guess it would have stopped out at the set stop ...

            best rgds and thx for the help

            ian

            Comment


              #7
              Ryan,

              hi

              This worked great to sort out the parameters problem.


              I noticed as well in the strategy analyser chart i couldnt seem to use my default chart template without the strategy trade overlay disappearing. am i missing something or am i limited to just the default strategy analyser chart template ?

              thx

              ian

              Comment


                #8
                Hi ian,

                Great that worked for you. Correct, the strategy analyzer chart cannot be further customized once generated. If you make any changes, will lose plot executions. Although, you can add in your strategy code the indicators you would like to see on this chart. This post can assist with adding indicators to a strategy and setting their panels, colors, etc:
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Ryan,

                  hi

                  thx this should do me just as well, ill have a bash at this

                  b.r.
                  ian

                  Comment


                    #10
                    Ryan,

                    hi this worked perfectly and i have the indicators plotting ... can i ask an additional question not covered explicitly in the excellent link you provided.

                    I have my indicators now automatically on the chart, but their values do not show up on the associated data box, is there an additional line of code i need to put in my strategy code to get the indicator values appear on the databox


                    thx

                    ian

                    Comment


                      #11
                      Ian, what type of values are you indicators visualizing? Only Plots() would make it to the data box.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Bertrand,

                        hi,

                        sorry been away for a few days ..

                        an example would be the ninja swing indicator which is plotted on the chart (ive added Add(Swing(x));
                        Swing(x).Plots[0].Pen.Width = 1;
                        Swing(x).Plots[0].Pen.DashStyle = DashStyle.Dot;
                        (where x is a number)
                        etc

                        to my strategy code already so the swing indicator shows up on the strategy analyser chart .. just it doesnt appear on the databox
                        Last edited by hyena; 09-27-2011, 11:42 AM.

                        Comment


                          #13
                          Swing indicator is designed not to show values in data box. The actual values of swing are not known until future bars. This property is set in its Initialize() method and would need to be removed for you to see the historical swing values.
                          DisplayInDataBox = false;
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            ryan,

                            thanks,

                            i figured it would be something like this

                            no problems i'm just playing around with indicators trying to get an understanding of how strategy works

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by knighty6508, Today, 01:20 AM
                            0 responses
                            5 views
                            0 likes
                            Last Post knighty6508  
                            Started by knighty6508, Today, 01:17 AM
                            0 responses
                            6 views
                            0 likes
                            Last Post knighty6508  
                            Started by tierraany, Today, 01:06 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post tierraany  
                            Started by Wilmarobyi, Today, 12:48 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post Wilmarobyi  
                            Started by BackToTheFutures, 08-17-2021, 03:15 PM
                            8 responses
                            732 views
                            0 likes
                            Last Post joehanus  
                            Working...
                            X