Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Current Month Open Value on Chart

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

    Current Month Open Value on Chart

    Can anyone point in me the right direction to get this to plot properly....

    I'm trying to plot the current month open by using a secondary data series. But apparently it's not as simple as referencing the 2nd bar data series...??

    I can get the correct month open values to print in the Output window, but the plot value is "N/A".

    I see on previous posts references to Monthly OHLC but the indicator offered is for the Prior month values.


    Thanks



    =================== CODE SAMPLE START ===================

    protected override void OnBarUpdate()
    {

    if (BarsInProgress == 1 && CurrentBars[1] > 0)

    {

    CurrentMonthOpen[0] = Opens[1][0];


    // print to check values are correct

    double currentMonthOpen = Opens[1][0];
    Print("Current Month Open Value: " + currentMonthOpen);

    }

    }

    region Properties

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


    =================== CODE SAMPLE END ===================​



    #2
    Hello MattD888,

    Thanks for your post.

    Please answer the questions below so that I may accurately assist.
    • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
    • To clarify, are you calling AddDataSeries() in your script to add a 1-Month secondary data series to the script?
    • ​Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
    Also, please share an exported copy of the script with me so I may look at the full code in the indicator and see if anything stands out.

    To export the script, go to Tools > Export > NinjaScript AddOn.

    I look forward to assisting further.
    <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

      Current NT: 8.0.28.0 64-bit

      Yes, I am calling a monthly bar in the Configure state.


      Please see the attached code.

      Thanks!

      Matt




      Attached Files

      Comment


        #4
        Hello Matt,

        Thanks for your notes.

        In your script, you are only assigning a value to the plot when the monthly secondary series processes.

        You should instead assign the value to the plot when the primary series is processing.

        For example, the code might look something like this:

        Code:
        protected override void OnBarUpdate()
        {
            if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
                return;
        
            CurrentMonthOpen[0] = Opens[1][0];​
        
        }
        See the help guide documentation below for more information.

        AddPlot(): https://ninjatrader.com/support/help...t8/addplot.htm
        CurrentBars: https://ninjatrader.com/support/help...urrentbars.htm
        Working with Multi-Timeframe/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm
        <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


          #5
          Thank you Brandon. I now have a value assigned to the plot and printing successfully on the chart. Only challenge now is the value is from the prior month.

          Do you know if the value in the bars array for the monthly series in the position of [0] should be the current month's Open value? For some reason it appears it is the prior month's open value.

          I thought at first I was accessing position [1] in the array but I believe the code you supplied: " Opens[1][0];​ " should be reading position [0] in the bars array, correct?

          Editing Post...

          It dawned on me it might be due to On Bar Close.... and when I changed to On Price Change it now posted the correct monthly open. The only trouble is that the value is only correct on the current active bar. The bars prior are showing a value of last month's open.

          Any ideas?

          Thanks for any insights you may have.
          Last edited by MattD888; 10-16-2023, 06:14 AM.

          Comment


            #6
            Hello Matt,

            Thanks for your notes.

            When using Calculate.OnBarClose, the Opens[1][0] would refer to the Open price of the last closed monthly bar which would be September.

            Note that historical bars will be calculated using Calculate.OnBarClose which is why you are seeing the Open price of September on historical bars but see the Open price of October on realtime bars.

            To have the historical bars calculated using Calculate.OnPriceChange, you could need to enable Tick Replay for your Data Series. Tick Replay guarantees that your indicators and strategies are historically calculated tick-per-tick exactly as they would have been if the indicator/strategy was running live during a period

            See this help guide page for more information about Tick Replay: https://ninjatrader.com/support/help...ick_replay.htm
            <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
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            573 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            575 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X