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

continuous horizontal line at highest high of n periods

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

    continuous horizontal line at highest high of n periods

    good day to everyone,


    i want to develop a very simple indicator that will look back at the last n periods (let's say 500), determine the highest high for the symbol we are evaluating over this time period and draw a continuous horizontal line at that value (the highest high of the last n periods).

    i received some invaluable assistance from other users and this is how the code for this indicator looks like in nt7:

    Code:
    protected override void OnBarUpdate()
    {
    
    highs.Add(High[0]);                                
                    
    if(highs.Count > period)
    double high = highs.Skip(highs.Count-period).Take(period).Max();            
    
    DrawLine("highesthigh"+CurrentBar,false,1,high,0,high,Color.Silver,DashStyle.Solid,4); 
    
    }
    this code is quite complicated and has some advanced functions in it, ¿does anyone know how could i now adapt it to nt8?


    thanks, regards.

    #2
    Hello rtwave,

    Thanks for your post.

    You can simplify the code as follows:

    if (CurrentBar > 500) // Can only check once 500 bars processed
    {
    double high = MAX(High, 500)[0]; // Get Maximum High of the last 500 bars
    Draw.Line(this, "highesthigh"+CurrentBar,false,1,high,0,high,Brush es.Silver,DashStyleHelper.Solid,4);
    }


    Another alternative would be to use the indicator CurrentDayOHL which will plot the current High (You can turn off the Open and Low if you wish), however it will reset at each session break.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul,


      thanks a lot.


      the code you kindly provided works perfectly in nt8. in this case nt8's ninjascript commands are far easier and more intuitive than nt7's version.


      thanks.

      Comment


        #4
        Hello rtwave,

        Thanks for your reply.

        The same method, MAX() also exists in NT7 and would work equally as well. Please see attached NT7 example.
        Attached Files
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          good day to everyone,


          i have looked further at this indicator and there's one small adjustment i would like to make. currently, the indicator is not calculated and plotted until the number of bars in the chart is greater than the period over the which we are doing this analysis.


          i would prefer if the indicator was calculated and plotted from the first bar in the chart, initially working with as many bars as there are available and then after the number of bars is greater than the period we have determined, using only as many bars as have been set as an input.


          to achieve this i tried to create some variables to hold the values of the current number of bars, the minimum between the current number of bars and the period we have used as an input and finally the highest high like before. however this code is not compiling, there are error messages about int, double and overload methods.


          Code:
          {
                      double    currbarv    = CurrentBars[0];
                      double    hhpere        = MIN(Hhperiod, currbarv)[0];
                      double    hhighv        = MAX(High, hhpere)[0];
                      Draw.Line(this, "highesthigh"+CurrentBar,false,1,hhighv,0,hhighv,Brushes.White,DashStyleHelper.Solid,4);
          
          }

          i think the logic should work and it is the syntax that would need some fine tuning. ¿does anyone know how these variables could be defined so that this code would work? thanks.

          Comment


            #6
            Hello rtwave,

            Thanks for your post.

            The MIN and MAX method require an integer parameter for the second parameter (period).

            An alternative to start with the first bar is:

            double high = MAX(High, CurrentBar > 500 ? 500 : CurrentBar)[0];
            Draw.Line(this, "highesthigh"+CurrentBar,false,1,high,0,high,Brush es.Silver,DashStyleHelper.Solid,4);


            In the double high statement, the period for MAX is resolved through the use of a logic condition that states, if the CurrentBar is greater than 500 then use 500 for the period, otherwise use the CurrentBar number for the period.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Paul,



              thanks.


              the structure you suggested works perfectly and now the indicator can generate visual signalling right from the start of a chart.

              coding can be really elegant and effective when people know their stuff.

              Comment


                #8


                regards to everyone,



                i have noticed that some weeks ago i received a message from another user who wanted to share the code to this indicator.


                i share it below in case it could be useful for other members:




                Highesthighperiod = 500;

                AddPlot(Brushes.White, "Highesthigh");
                }
                else if (State == State.Configure)
                {
                }
                }

                protected override void OnBarUpdate()
                {


                if (CurrentBar < 1) return;


                {
                double hhighv = MAX(High, CurrentBar > Highesthighperiod ? Highesthighperiod : CurrentBar)[0];
                Draw.Line(this, "highesthigh"+CurrentBar,false,1,hhighv,0,hhighv,B rushes.DarkBlue,DashStyleHelper.Solid,4);
                }

                }

                #region Properties
                [NinjaScriptProperty]
                [Range(0, int.MaxValue)]
                [Display(Name="highesthighperiod", Description="highesthighperiod", Order=1, GroupName="Parameters")]
                public int Highesthighperiod
                { get; set; }



                [Browsable(false)]
                [XmlIgnore]
                public Series<double> Highesthigh
                {
                get { return Values[0]; }
                }
                #endregion

                Comment


                  #9
                  Hello rtwave,

                  Thank you for your reply.

                  If you'd like to share the full script, I'd invite you to export your indicator and upload it to our User App Share.

                  You can submit your script through the forum here:
                  Upload tools and add-ons that you build to share through the NinjaTrader Ecosystem User App Share.


                  Please let us know if we may be of further assistance to you.
                  Kate W.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post Javierw.ok  
                  Started by timmbbo, Today, 08:59 AM
                  2 responses
                  10 views
                  0 likes
                  Last Post bltdavid  
                  Started by alifarahani, Today, 09:40 AM
                  6 responses
                  40 views
                  0 likes
                  Last Post alifarahani  
                  Started by Waxavi, Today, 02:10 AM
                  1 response
                  18 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by Kaledus, Today, 01:29 PM
                  5 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X