Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Current Range Bar possible High & Low Plot

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

    Current Range Bar possible High & Low Plot

    I have just started looking at Range Bars and put together this little Hash-Line indicator that plots, only on the current bar, the possible high and low based on whatever Range Bar setting you have. For people using these bars and especially if any bar patterns for trailing stops etc. are part of the method, it should be quite helpful - don't have to keep counting to figure out where the high or low might end up since this plot adjusts automatically as the width of the bar develops over time.
    Attached Files
    Last edited by cclsys; 08-11-2009, 01:42 PM.

    #2
    By the way, is it possible to have the script reference the number of ticks in the Range Bar Chart as specified by the user when loading the chart so that whenever the Indicator loads it automatically knows the correct Range Number versus having to input it manually on each different chart loaded?

    Comment


      #3
      You mean the value of range chart the user is using? You can access that through Bars.Period.Value.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Josh View Post
        You mean the value of range chart the user is using? You can access that through Bars.Period.Value.
        Thanks.

        I tried writing in:

        PossHigh.Set(Low[0]+ (BarsPeriod.Value*TickSize));

        but it won't compile.

        Original code (which works fine):

        protected override void OnBarUpdate()

        {
        if ( High[0] == Low[0] + (range*TickSize) || (Low[0] == High[0] - (range*TickSize)) )
        return;

        PossHigh.Set(Low[0]+ (range*TickSize)); // range is a variable that can be set in the menu panel for each chart, i.e. for a 5-Range bar chart you input 5.
        PossLow.Set(High[0]- (range*TickSize));

        }

        Substituting:

        PossHigh.Set(Low[0]+ (BarsPeriod.Value*TickSize));
        PossLow.Set(High[0]- (BarsPeriod.Value*TickSize));


        Is this possible or is there some particular way the language has to be used that is not explained in the help menu which only features:

        if (BarsPeriod.Id == PeriodType.Tick && BarsPeriod.Value >= 100)
        ....

        Comment


          #5
          From an indicator you have to do Bars.Period.Value not BarsPeriod.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Josh View Post
            From an indicator you have to do Bars.Period.Value not BarsPeriod.
            I wrote:

            PossHigh.Set(Low[0]+ (BarsPeriod.Value*TickSize));
            PossLow.Set(High[0]- (BarsPeriod.Value*TickSize));

            as posted above.

            I don't understand your reply Josh.

            Comment


              #7
              NOT BarsPeriod but Bars.Period.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Thanks, I changed it to

                PossHigh.Set(Low[0]+ (Bars.Period.Value*TickSize));
                PossHigh.Set(Low[0]+ (Bars.Period.Value*TickSize));

                but although it compiles, it doesn't seem to work right. I'll wait until there are more active markets tomorrow but right now it is plotting all the past bars - which it shouldn't - and not plotting the current bar - which it should.

                Also, when I loaded it even though Overlay = true and Calculate on Bar Close = true in the code, it wants to plot it in a new panel (which the other version did not do) and also defaults to Calculate on Bar Close.

                Strange.

                It would be helpful if you could show me how to write it and/or mention any other issues that are required when using this term. I suspect whatever the problem is is simple, but given the Help Menu only gives a one-line example and no other explanation, it's a little hard to figure out.
                Last edited by cclsys; 08-11-2009, 03:41 PM.

                Comment


                  #9
                  Bars.Period.Value gets you the value you set your range chart to. If you are on a 4 Range chart it will return you 4. Please debug your code to see if you are getting values you are looking for.

                  You need to add a new instance of your indicator for changes like Overlay = true.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Josh View Post
                    Bars.Period.Value gets you the value you set your range chart to. If you are on a 4 Range chart it will return you 4. Please debug your code to see if you are getting values you are looking for.

                    You need to add a new instance of your indicator for changes like Overlay = true.
                    Re: "You need to add a new instance of your indicator for changes like Overlay = true."

                    Each time I have changed something I have removed the Indicator and reloaded it. Is that what you mean by a 'new instance'? If not, please explain.

                    Also, why would changing the code to use Bars.Period.Value versus my previous menu-derived int make the Overlay and Panels shift when loading the indicator again?

                    I have found what I think was the problem. In changing the .Set lines I forgot to set the if condition line:
                    if ( High[0] == Low[0] + (range*TickSize) || (Low[0] == High[0] - (range*TickSize)) )
                    return;

                    which was still referencing the menu item 'range'. Now I have changed that line to use Bars.Period and also removed the range input altogether and it seems to be fine. I still don't understand why the Overlay and BarOnClose changed, but since it's not doing that anymore, all seems well.

                    Thanks for helping me to learn that Bars.Period.Value coding. Thanks to you the Indicator will load with any range chart and/or when you change the range value you don't have to go to the indicator menu and manually change the range value. Much better!
                    Last edited by cclsys; 08-11-2009, 04:49 PM.

                    Comment


                      #11
                      Well, there is still something wrong. With some charts it works perfectly, then with others it displays on every bar. It doesn't seem to like even-numbered ranges for some reason but there is no logic in the code that I can tell that should make that an issue. If anyone can figure out this little thing, would be grateful.

                      When I print out Bars.Period.Value for a 4-range chart, there are many lines in the output window. When I print it out in a 5-range chart, only two prints.

                      Like most of my indicators in Ninja Script it's just a small visual aid to day-trading, nothing hyper-fancy.

                      Print (Bars.Period.Value);
                      Attached Files
                      Last edited by cclsys; 08-11-2009, 05:37 PM.

                      Comment


                        #12
                        cclsys, briefly checked this on ZenFire ES 09-09 Range charts and could not reproduce what you see, the Bars.Period.Value prints correctly for even and odd range charts here...
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Bernard,

                          I also tried printing out the values and they seem spot on. But sometimes on some charts the plots remain on previous bars, and on other charts they don't - like they are supposed to. I wonder if there is a very small decimal difference not shown in the prints between the Bars.Period.Value * TickSize and the actual High or Low? I am still new to printing things out and haven't found out yet how to get it to print to 10 decimal pts to research this idea. But in the default printout mode, both in the Output Window and the Data Window, the value of the High or Low and the values of the plots are identical, in which case they should not be plotted.

                          I know this is a small thing, but it would be nice to get it right. I will load a chart later today with the problem and post a picture.

                          Comment


                            #14
                            I get the same thing. On the ES it seems to work properly and on the TF the hash marks remain for the previous bars.

                            Maybe it has something to do with the tick sizes being different?

                            Comment


                              #15
                              Originally posted by Jason11 View Post
                              I get the same thing. On the ES it seems to work properly and on the TF the hash marks remain for the previous bars.

                              Maybe it has something to do with the tick sizes being different?
                              That should not be the problem (in theory) since the code is specifying 'TickSize' as the referent.

                              I loaded several charts yesterday and none of them had the problem. But then after reading your post, I tried again and after (again many tries) one of them was bad, the TF 4 range. TF 5 range was fine (and 6,7,8,9). Often 4 gives it a problem for some reason!

                              Anyway, here is a picture showing the plots. They seem to be at the right prices (and when this happened before I checked in the Data Box and indeed they were, i.e. the plot prices and the highs and lows were identical. This is why I wonder if there is not a very small decimal price difference somewhere which I can't see. Other than that, it remains a mystery.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by minotti1, Today, 08:31 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Jim  
                              Started by SmartArtsStudio, 05-15-2021, 10:46 AM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Airwave, Today, 06:02 AM
                              2 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by bottakemoney, Today, 12:10 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Started by JGRtrader, Yesterday, 10:54 PM
                              2 responses
                              3 views
                              0 likes
                              Last Post JGRtrader  
                              Working...
                              X