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

indicator for highest high daily bars

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

    indicator for highest high daily bars

    hello everyone,


    i would appreciate your help with an indicator i'm trying to code in nt.


    it is a very simple idea, on a daily bar chart, i would like an indicator that can find the highest high for the last 2 years only (500 bars or so), and then with that numeric value for the highest high, plot a set of horizontal lines. these lines would be plotted at intervals of 10%, the first horizontal line would be plotted at the value resulting of the highest high of the period by a factor of 100% (1), the second one would be the same highest high by a factor of 90% (.9), and so on until 10% and 0%.

    if there was a way to plot these lines in different colors each and paint the chart bars that fall between two lines with different colors that would be even better.

    thanks a lot, regards.

    #2
    this will get you started, just create a new indicator, delete everything and copy my code in there.

    i only did it for high of the last 500 candles so you would need to add the other lines. Mainly bc i didnt really put much effort in tryin to understand what u even mean

    if you have any questions, pls ask. more information is included in the code.

    Code:
    //#region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    using System.Collections.Generic;   // this is needed for using List
    using System.Linq;                    // this is needed for advanced list functions, like sums and skips. 
    //#endregion
    
    namespace NinjaTrader.Indicator
    {
    
        [Description("")]
        public class HighestHigh : Indicator
        {
        //#region Variables
            private List<double> highs = new List<double>();     // creates a new list with the name in the middle (highs)
            private int period = 500;                            // how many candles to look back - i added it to the variables for dynamic changes in the indicator window
        //#endregion
    
            protected override void Initialize()
            {
                Overlay                = true;                    
            }
    
    
            protected override void OnBarUpdate()
            {
                highs.Add(High[0]);                                // whenever onbarupdate is called (so at ever daily close) this will list the current days high. the list.Count will increase to 1 and +1 for every following day.
                    
                if(highs.Count > period){                        // checks if the list.Count is big enough, so bigger than the period
                    double high = highs.Skip(highs.Count-period).Take(period).Max();            // looks at the full list skips the first (list.Count-period) entries and than takes the max of the remaining (period amount of) entries. that syntax ensures we take the max of the last X(500) entries.
                    DrawLine("high"+CurrentBar,false,1,high,0,high,Color.Magenta,DashStyle.Solid,2); // draws a small line over the currentbar with the max high we got from the line above. this line will be updated on every bar ofc, so will eventually become a big one.
                }
            }
    
        //#region Properties        
            [XmlIgnore()]        
            [Description("")]
            [GridCategory("Parameters")]
            public int Period
            {
                get { return period; }
                set { period = Math.Max(1, value); }
            }
     //     [Browsable(false)]    
        //#endregion
            
            
        }
    }
    Last edited by BigRo; 12-11-2015, 03:05 AM.

    Comment


      #3
      Originally posted by BigRo View Post

      Code:
      
                      DrawLine("high"+CurrentBar,false,1,high,0,high,Color.Magenta,DashStyle.Solid,2); // draws a small line over the currentbar with the max high we got from the line above. this line will be updated on every bar ofc, so will eventually become a big one.

      this code works great and does plot a line at the level of the highest high of the period analyzed.


      i have read most of nt's help guides and i think i now know what kind of modifications would generate the set of horizontal lines i was thinking of. it would be one of these possibilities:


      Code:
      DrawLine("high"+CurrentBar,false,1,(high*.9),0,(high*.9),Color.Magenta,DashStyle.Solid,2);
      
      or
      
      DrawLine("high"+CurrentBar,false,1,(high*.9),0,high,Color.Magenta,DashStyle.Solid,2);
      
      or
      
      DrawLine("high"+CurrentBar,false,1,high,0,(high*.9),Color.Magenta,DashStyle.Solid,2);


      now, how would it be possible to generate an analog indicator to these horizontal lines? an indicator that generated the following calculation and returned a numeric value:


      ( price close (0) - lowestlow (500 previous bars) ) / ( highesthigh (500 previous bars) - lowestlow (500 previous bars) )

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by yertle, Yesterday, 08:38 AM
      7 responses
      28 views
      0 likes
      Last Post yertle
      by yertle
       
      Started by bmartz, 03-12-2024, 06:12 AM
      2 responses
      21 views
      0 likes
      Last Post bmartz
      by bmartz
       
      Started by funk10101, Today, 12:02 AM
      0 responses
      5 views
      0 likes
      Last Post funk10101  
      Started by gravdigaz6, Yesterday, 11:40 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by MarianApalaghiei, Yesterday, 10:49 PM
      3 responses
      11 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X