Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with PriorMonthOHLC indicator and the way it Plots lines

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

    Help with PriorMonthOHLC indicator and the way it Plots lines

    Hi!

    Any help is welcome!

    1. I want the Plot Style "Line" and Dash Style "Dash" but without this "Zig-Zag". I want the horizontal lines only. I don't want to use Hash because this makes me noise on the chart and sometimes it looks like a continuous line, it depends on the zoom on the chart.

    I read in another post about "RESET" property that could help, but I would not know how to implement it and I don't know if this really will help with this need.


    2. I would like to Plot the Current Open Month of every month, including the running month.

    This is the indicator PriorMonthOHLC.

    Thank you very much!!
    Attached Files

    #2
    Hello joselube001,

    Thanks for your post.

    You could consider using Series<T>.Reset in your script to reset the values of plots.

    Series<T> objects will always contain a value that is assigned, however calling Reset() simply means you effectively ignore the value of the current bar for plotting purposes. For calculation purposes, you will want to use IsValidDataPoint() to ensure you are not calculating off of any reset values assigned by the Reset() method.

    See this help guide page for more information about Series<T>.Reset and an example: https://ninjatrader.com/support/help...html?reset.htm

    Let us know if we may further assist.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hi Brandon!
      Thanks for your answer!

      I was trying to use "Reset" but the plots disappear.

      If you can help me with the correct code it is welcome!

      I show in Red text my modification into the code:

      Code:
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Dash, 2), PlotStyle.Line, "PriorMonthOpen");
      AddPlot(new Stroke(Brushes.Tan, DashStyleHelper.Dash, 2), PlotStyle.Line, "PriorMonthHigh");
      AddPlot(new Stroke(Brushes.Tan, DashStyleHelper.Dash, 2), PlotStyle.Line, "PriorMonthLow");
      AddPlot(new Stroke(Brushes.White, DashStyleHelper.Dash, 2), PlotStyle.Line, "PriorMonthClose");
      }
      
      
      protected override void OnBarUpdate()
      
      //Add your custom indicator logic here.
      if (!Bars.BarsType.IsIntraday)
      {
      Draw.TextFixed(this, "err", "PriorMonthOHLC only works on intraday interval", TextPosition.BottomRight);
      return;
      }
      
      if (newMonth < Time[0])
      {
      prMonthlyOpen = monthlyOpen;
      prMonthlyHigh = monthlyHigh;
      prMonthlyLow = monthlyLow;
      prMonthlyClose = monthlyClose;
      
      monthlyOpen = Open[0];
      monthlyHigh = High[0];
      monthlyLow = Low[0];
      monthlyClose = Close[0];
      
      newMonth = Time[0].Date.AddDays(DateTime.DaysInMonth(Time[0].Year, Time[0].Month) - (Time[0].Day - 1));
      
      }
      
      if (prMonthlyOpen != 0)
      {
      if (ShowOpen) PriorMonthOpen[0] = prMonthlyOpen;
      if (ShowHigh) PriorMonthHigh[0] = prMonthlyHigh;
      if (ShowLow) PriorMonthLow[0] = prMonthlyLow;
      if (ShowClose) PriorMonthClose[0] = prMonthlyClose;
      }
      
      
      [COLOR=#e74c3c]if (Bars.IsFirstBarOfSession)
      {
      PriorMonthOpen.Reset();
      PriorMonthHigh.Reset();
      PriorMonthLow.Reset();
      PriorMonthClose.Reset();
      }[/COLOR]
      
      monthlyHigh = Math.Max(High[0], monthlyHigh);
      monthlyLow = Math.Min(Low[0], monthlyLow);
      monthlyClose = Close[0];
      }
      Thank you very much!!

      Comment


        #4
        Hello joselube001,

        Thanks for your note.

        I see that you are not using IsValidDataPoint() to ensure you are not calculating any reset values assigned by the Reset() method. As stated in post #2, you will want to use IsValidDataPoint() to ensure you are not calculating off of any reset values assigned by the Reset() method.

        Please see the attached example script which demonstrates how to use Reset() to reset the value of a plot when the current bar is the first bar of the session.

        In the example script, we first assign a value to our plot. Then, we check if Bars.IsFirstBarOfSession and we reset our plot. After resetting the plot, we only calculate the MyPlot value if it has not been reset. If you test the attached example script, we see prints in the NinjaScript Output window that prints out "Reset on bar:" and the bar number that the plot is being reset. We also see prints for the current bar and plot value when MyPlot has not been reset.

        Ultimately, to understand why the script is behaving as it is, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.
        https://ninjatrader.com/support/foru...121#post791121

        Let us know if we may assist further.
        Attached Files
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        581 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        338 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X