Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Daily ADR Plot On Minute Chart

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

    Daily ADR Plot On Minute Chart

    Hi Team,

    I am attempting to code an Indicator that plots Daily ADR values on a 1 minute chart. I have successfully gotten the indicator to plot the daily ADR high and low values but the values of the plots extend all the way through the previous RTH session. The values change when I scroll back through the chart but I would like them to be painted on the previous RTH session without me having to scroll. Very much like the SWING indicator plots highs and lows over a time period and then changes those values as price changes while keeping the historical values on the chart.

    My code is copied below. Note that I do not consider myself do be a coder. I try my best to read through the docs and reference this forum to get answers. Any help you can provide is much appreciated. Thank you!!!


    Code:
    //This namespace holds Indicators in this folder and is required. Do not change it.
    
    namespace NinjaTrader.NinjaScript.Indicators
    
    {
    
    public class AverageDailyRange : Indicator
    
    {
    
    
    
    private Series<Double> adrHigh;
    
    private Series<Double> adrLow;
    
    private Series<Double> openPrice;
    
    private Series<Double> adr;
    
    private double adrHighPlot, adrLowPlot;
    
    
    
    protected override void OnStateChange()
    
    {
    
    if (State == State.SetDefaults) {
    
    Description = @"Enter the description for your new custom Indicator here.";
    
    Name = "Average Daily Range";
    
    Calculate = Calculate.OnEachTick;
    
    IsOverlay = true;
    
    DisplayInDataBox = true;
    
    DrawOnPricePanel = true;
    
    PaintPriceMarkers = true;
    
    IsSuspendedWhileInactive = true;
    
    Lookback = 20;
    
    AddPlot(new Stroke(Brushes.Green, DashStyleHelper.Dash, 2), PlotStyle.Line, "top");
    
    AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Dash, 2), PlotStyle.Line, "bottom");
    
    BarsRequiredToPlot = 20;
    
    }
    
    else if (State == State.Configure){
    
    
    
    AddDataSeries(null, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 }, "CME US Index Futures RTH");
    
    }
    
    
    
    else if (State == State.DataLoaded){
    
    
    
    
    adrHigh = new Series<double>(this);
    
    adrLow = new Series<double>(this);
    
    openPrice = new Series<double>(this);
    
    adr = new Series<double>(this);
    
    
    
    }
    
    }
    
    
    
    
    protected override void OnBarUpdate()
    
    {
    
    
    
    
    
    if(CurrentBars[0] <= Lookback || CurrentBars[1] <= Lookback)
    
    return;
    
    
    
    if (BarsInProgress == 0)
    
    {
    
    
    
    
    double sum = 0;
    
    
    
    for (int i=0; i<Lookback; i++)
    
    sum = sum + (Highs[1][i] - Lows[1][i]);
    
    
    
    
    adr[0] = Math.Round((sum/Lookback),2);
    
    
    
    
    adrHigh[0] = (Opens[1][0] + (adr[0] / 2));
    
    adrLow[0] = (Opens[1][0] - (adr[0] / 2));
    
    
    
    // Draw.Line(this, "adrHigh" + CurrentBar.ToString(), false, 1, adrHigh[0], 0, adrHigh[0], Brushes.LimeGreen, DashStyleHelper.Dot, 4);
    
    // Draw.Line(this, "adrLow" + CurrentBar.ToString(), false, 1, adrLow[0], 0, adrLow[0], Brushes.Red, DashStyleHelper.Dot, 4);
    
    
    
    
    adrHighPlot = adrHigh[0];
    
    adrLowPlot = adrLow[0];
    
    Values[0][0] = adrHighPlot;
    
    Values[1][0] = adrLowPlot;
    
    
    
    
    Draw.TextFixed(this, "tag1" ,"ADR: " + adr[0] + " ADR High: " + adrHigh[0] + " ADR Low: " + adrLow[0], TextPosition.TopLeft);
    
    }
    
    
    
    
    
    
    
    if (BarsInProgress == 1)
    
    {
    
    
    }
    
    
    }
    
    
    [HASHTAG="t3322"]region[/HASHTAG] Properties
    
    [NinjaScriptProperty]
    
    [Range(1, int.MaxValue)]
    
    [Display(Name="Lookback", Order=1, GroupName="Parameters")]
    
    public int Lookback
    
    { get; set; }
    
    
    
    [Browsable(false)]
    
    [XmlIgnore()]
    
    public Series<double> top
    
    {
    
    get { return Values[0]; }
    
    }
    
    [Browsable(false)]
    
    [XmlIgnore()]
    
    public Series<double> bottom
    
    {
    
    get { return Values[1]; }
    
    }
    
    
    
    
    
    #endregion
    
    
    
    
    }
    
    }
    ​


    ​ ​​ ​​ ​
    Last edited by mfortin; 01-13-2023, 04:17 PM.

    #2
    Hello mfortin,

    You can use two sets of plots and / or two sets of drawing objects.

    This way you can start a new plot without altering the existing plot for a few bars. Same with drawing objects.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the quick reply! If I had two sets of plots, how would I stop the main plot (today's plot) from extending back to tomorrow? I've attached a screen shot of the how the indicator shows up. Also would I have to implement that in (BarsInProgress == 1) so I could reference the open close of the daily bar to start a new plot?
      Click image for larger version

Name:	Screen Shot 2023-01-13 at 5.21.37 PM.png
Views:	473
Size:	86.8 KB
ID:	1231222

      Comment


        #4
        Hello mfortin,

        You can unset values with .Reset() or you can change value by setting a different value with a barsAgo index.


        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        637 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        366 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        107 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        569 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        571 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X