Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator displaying highest/lowest close instead of high/low

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

    Indicator displaying highest/lowest close instead of high/low

    I've been working with ElliotWave's FibLines indicator and have found it very useful in my day to day analysis (thanks so much for making it available, ElliotWave). However, I've noticed that it will only display the highest and lowest close for a given range rather than the absolute high and absolute low. I would guess that this throws off all of the fib levels slightly so I'd really like to get it corrected. I don't have programming experience but I'll post the relevant code and if anyone more experienced than me could help out, I would greatly appreciate it.

    #region Variables

    // Wizard generated variables

    private DateTime startTime;

    private string startDate = "3/01/2009 1:00:00 AM";
    private double sessionLengthInHours=0;
    // User defined variables (add any user defined variables below)
    private double HighestHigh;
    private double LowestLow;
    private double Range;
    private int HighBar=0,LowBar=0,FirstBar,LastBar;
    private bool showHighAndLow=true;

    private DateTime endTime;
    private int lineWidth =2;
    private int lineType =4;
    private bool showLabel=true;

    // User defined variables (add any user defined variables below)
    #endregion
    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.Transparent, PlotStyle.Line, "High"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "Low"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "r200"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "r176"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "r161"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "r150"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "r138"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "r123"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "r76"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "r61"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "r50"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "r38"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "r23"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "s23"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "s38"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "s50"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "s61"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "s76"));
    Add(new Plot(Color.Transparent, PlotStyle.Line, "s100"));


    ChartOnly = true;
    AutoScale = false;
    CalculateOnBarClose = true;
    DisplayInDataBox = true;
    Overlay = true;
    PriceTypeSupported = false;

    HighestHigh = Double.MinValue;
    LowestLow = Double.MaxValue;
    FirstBar = -1;
    Range = 0;

    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    { if(CurrentBar<10) return;


    try {
    startTime = DateTime.Parse(startDate);
    }
    catch (FormatException) {
    Print("Unable to convert " + startDate);
    }


    if(sessionLengthInHours == 0) endTime = DateTime.Now;
    else endTime = startTime.AddHours(sessionLengthInHours);

    if(Time[3]<=endTime && Time[2]>endTime) DrawLine("EndTime",3,HighestHigh,3,LowestLow,Color .Magenta,DashStyle.Solid,lineWidth);

    Range = (HighestHigh - LowestLow);

    if(DateTime.Compare(Time[0],startTime)>0 && DateTime.Compare(Time[0],endTime)<0)
    { if(FirstBar<0) FirstBar=CurrentBar;


    if(HighestHigh<0.0)
    { HighestHigh = High[0];
    LowestLow = Low[0];
    } else
    { if(High[0]>HighestHigh)
    { HighestHigh = High[0];
    HighBar=CurrentBar;
    if(showHighAndLow) DrawHorizontalLine("High",HighestHigh,Color.Blue,D ashStyle.Solid,lineWidth);
    }

    if(Low[0]<LowestLow)
    { LowestLow = Low[0];
    LowBar=CurrentBar;
    if(showHighAndLow) DrawHorizontalLine("Low",LowestLow,Color.Red,DashS tyle.Solid,lineWidth);
    }
    }

    if(CurrentBar-FirstBar>3) DrawLine("StartTime",CurrentBar-FirstBar,HighestHigh,CurrentBar-FirstBar,LowestLow,Color.Magenta,DashStyle.Solid,l ineWidth);



    High.Set(HighestHigh); // high
    Low.Set(LowestLow); //low
    R200.Set(HighestHigh + Range * 1);
    R176.Set(HighestHigh + Range * 0.764);
    R161.Set(HighestHigh + Range * 0.618);
    R150.Set(HighestHigh + Range * 0.5);
    R138.Set(HighestHigh + Range * 0.382);
    R123.Set(HighestHigh + Range * 0.236);
    R76.Set(HighestHigh - Range * 0.236);
    R61.Set(HighestHigh - Range * 0.382);
    R50.Set(HighestHigh - Range * 0.5);
    R38.Set(HighestHigh - Range * 0.618);
    R23.Set(HighestHigh - Range * 0.764);
    S23.Set (HighestHigh - Range * 1.236);
    S38.Set (HighestHigh - Range * 1.382);
    S50.Set (HighestHigh - Range * 1.5);
    S61.Set (HighestHigh - Range * 1.618);
    S76.Set (HighestHigh - Range * 1.764);
    S100.Set (HighestHigh - Range * 2);

    #2
    HighestHigh = Double.MinValue;
    LowestLow = Double.MaxValue;

    I'm not sure if you can use capital Double, should be double.MinValue and double.MaxValue.

    Comment


      #3
      Support,

      Just a quick question, does NT have an issue with double.MinValue or MaxValue as an alternative to nullifying a double?


      Thanks,

      Comment


        #4
        r2kTrader,

        Not that I am aware of.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        43 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        25 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        163 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        98 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        158 views
        2 likes
        Last Post CaptainJack  
        Working...
        X