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

R/S levels with variable lookback period

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

    R/S levels with variable lookback period

    Hi,

    I am appling to apply in a strategy which will enter long when the close price will cross above the highest high in a variable lookback period. I tried to find the Highest high by making a double variable and also through a dataseries. However, no one is working as expected. The double variabale is compled but the dataseries not. Does anybody have an idea or any solution how can I do it?

    #2
    Hi Loukas,

    For Highest High, there is indicator MAX() which accepts a series and a lookback as its parameters.

    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I am already using the MAX() but the problem is with the CrossAbove. I code the below
      As a double: double HighWeek=MAX(High,5)[0];

      // As a dataseries HighWeekly.Set(MAX(High,5)[0]);

      if (CrossAbove(Close[0],HighWeek[1],1))
      {
      Do something
      }

      Do you have any suggestion on this?

      Comment


        #4
        If you want to apply indexing to it like that, it needs to be a data series. What is it that you're running into exactly? Are you having trouble creating expressions that compile or something else?
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          It is complite, howevere when I am running backtest doesnt make trades. Could you have at the attachedment. Thanks
          Attached Files

          Comment


            #6
            Your conditions are likely too restrictive to allow trades. Unfortunately we could not debug this for you. You will need to simplify and print all values to confirm they're what you expect. Since a crossing looks at two bars and two values, you need to check every bar the values for:
            Close[0] and Close[1]
            HighWeek[1] and HighWeek[2].

            Help for debugging is here:
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              I made the changes below but it is not compile

              HighWeekly.Set(MAX(High,Weekly)[0]);

              if (CrossAbove(Close[0],HighWeekly[0],1))

              Comment


                #8
                Cross conditions cannot have two doubles. One needs to be a series, so either of the two below will compile:

                if (CrossAbove(Close, HighWeekly[0],1))

                or

                if (CrossAbove(Close[0], HighWeekly,1))

                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  If I made the condition as if (CrossAbove(Close, HighWeekly[0],1)) does not made any trades but if I change it to if (CrossAbove(Close, HighWeekly[1],1)) the strategy makes few trades. However, I am wondering if the HighWeekly[1] is correct because it is taking into account the previous highest hight not the current highest. So the idea to enter Long when the close price cross above the last month highest does not exist! What is your thoughs about it? Maybe I need to change the condition with CurrentBar ?
                  Thanks

                  Comment


                    #10
                    Yes, HighWeekly[1] is the value of HighWeekly 1 bar ago. It makes sense that you would never see Close crossing above the highest high of last few bars. 100% of the time Close is <= Max(High) if it's included in Max's lookback.

                    In order to understand what your strategy is doing, you're going to have to dig into it with print statements. Please see my previous post for guidance on what you'll need to verify to evaluate crossing statements. If you're having trouble following it in your strategy, start simplifying and working from this good example of a crossing strategy:

                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      I am trying something simple just to improve my skills, I have tried 3 ways but no one look to working eventhough they are compiled.
                      1. if (CurrentBar < Weekly )
                      return;
                      double HighWeek=MAX(High,Weekly)[0];
                      if (Close[0]>HighWeek)
                      {
                      EnterLong(DefaultQuantity, "");
                      }
                      2. HighWeek.Set(MAX(High,Weekly)[0]); if (CrossAbove(Close,HighWeek,1))
                      {
                      EnterLong(DefaultQuantity, "");
                      }
                      3.
                      if (Close[0]>MAX(High,Weekly)[0])
                      {
                      EnterLong(DefaultQuantity, "");
                      }
                      I dont thing so this is something sophisticated, I just cannot understand why is not working. I want some guides if it is possible!

                      Comment


                        #12
                        This thread has references to crossing strategy guides and guidelines for how to verify crossing conditions through Print() statements. What you're trying to do may not work until you refine the conditions a bit.

                        If lookback period for MAX(High, lookback)[0] includes the close value you're checking for a crossover, then your condition will never be true. See this thread that was posted today about applying indexing to a MAX expression for some ideas to change your condition.

                        In these examples below, you could use >= and you have a chance to enter, only if the most recent close is the highest high over the Weekly lookback. It can't/won't ever be greater.

                        if (Close[0]>MAX(High,Weekly)[0]) // never true

                        double HighWeek=MAX(High,Weekly)[0];
                        if (Close[0]>HighWeek) //never true

                        if (Close[0]>MAX(High,Weekly)[0]) //never true
                        Last edited by NinjaTrader_RyanM1; 09-12-2011, 08:10 AM.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by Loukas View Post
                          I am trying something simple just to improve my skills, I have tried 3 ways but no one look to working eventhough they are compiled.
                          1. if (CurrentBar < Weekly )
                          return;
                          double HighWeek=MAX(High,Weekly)[0];
                          if (Close[0]>HighWeek)
                          {
                          EnterLong(DefaultQuantity, "");
                          }
                          2. HighWeek.Set(MAX(High,Weekly)[0]); if (CrossAbove(Close,HighWeek,1))
                          {
                          EnterLong(DefaultQuantity, "");
                          }
                          3.
                          if (Close[0]>MAX(High,Weekly)[0])
                          {
                          EnterLong(DefaultQuantity, "");
                          }
                          I dont thing so this is something sophisticated, I just cannot understand why is not working. I want some guides if it is possible!
                          Write your condition down in standard spoken language, then code that. So you would say as condition 3 that:

                          If the Close today, is higher than the highest high for the last 20 bars, as at yesterday, then go long. MAX() requires a DataSeries and an (integer) lookback period.

                          So that gets coded as:

                          Code:
                          if (Close[0] > MAX(High, 20)[1])
                          {
                          // Do stuff
                          }
                          Of course, you can always replace "20" with a user-specifiable variable.

                          Comment


                            #14
                            Thanks koganam. I done that you same but it is executing only one trade. I think something is missing.
                            if (CurrentBar < Weekly )

                            return;
                            if (Close[0] > MAX(High,Weekly)[1])

                            {
                            EnterLong(DefaultQuantity, "");
                            }



                            RayM
                            """If lookback period for MAX(High, lookback)[0] includes the close value you're checking for a crossover, then your condition will never be true""""
                            A good point! Thanks for the explanation.


                            Comment


                              #15
                              Originally posted by Loukas View Post
                              Thanks koganam. I done that you same but it is executing only one trade. I think something is missing.
                              if (CurrentBar < Weekly )

                              return;
                              if (Close[0] > MAX(High,Weekly)[1])

                              {
                              EnterLong(DefaultQuantity, "");
                              }



                              RayM
                              """If lookback period for MAX(High, lookback)[0] includes the close value you're checking for a crossover, then your condition will never be true""""
                              A good point! Thanks for the explanation.
                              And how many bars are on your chart?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post algospoke  
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              44 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              180 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X