Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting two days ago OHLC

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

    Plotting two days ago OHLC

    Hi everyone,

    I have been struggling to plot "TWO days ago" OHLC on my charts on NinjaTrader 8. I came across this post, downloaded the file provided by Chris L, and changed the indexing as follows per his update:

    Code:
    if(BarsInProgress != 0)
    return;
    
    if(CurrentBars[0] < 2 || CurrentBars[1] < 2)
    return;
    
    if (ShowOpen) PriorOpen[0] = Opens[1][1];
    if (ShowHigh) PriorHigh[0] = Highs[1][1];
    if (ShowLow) PriorLow[0] = Lows[1][1];
    if (ShowClose) PriorClose[0] = Closes[1][1];
    }


    Bizarrely, the two days ago "CLOSE" does not line up with the previous day's close! This is odd because the highs and lows match perfectly, as you can see below:


    I also tried to modify the original "Prior Day OHLC" file but could not make things work! Would highly appreciate any advice on how to fix this!

    Thank you! ​​

    #2
    Hello rezamerik,

    I am not certain I understand the problem you mentioned, the Two days ago close is not specifically going to match One days ago close, those are two different days with different data.

    In the code you provided you are checking the value of 1 bars ago which would be 1 day ago, the sample you linked is doing the correct syntax which is Closes[1][2]; which is 2 days ago.

    Comment


      #3
      Hi NinjaTrader_Jesse,

      Thanks very much for your response, I really appreciate it. Sorry for the confusion; I should have clarified that:

      The BLACK dashed lines = Yesterday's High & Low
      The ORANGE dashed line = Yesterday's Close
      The GRAY dashed lines = Two Days Ago's High & Low
      The YELLOW dashed line = Two Days Ago's Close

      As you can see, the dashed GRAY lines from TODAY are aligned with the BLACK lines from YESTERDAY, as they should be. Now I would expect the dashed YELLOW line from TODAY also be aligned with the ORANGE line from YESTERDAY,​ but it doesn't (please see the photo below). Essentially I'm trying to show the close of the two days ago on TODAY'S chart, if that makes sense!

      Click image for larger version

Name:	OHLC Drawing Issue 02.png
Views:	206
Size:	151.4 KB
ID:	1220375

      Comment


        #4
        Hello rezamerik,

        The script you linked to is showing the close of 2 daily bars ago.

        The orange and yellow plot shouldn't match day to day, you are always plotting 2 days ago from that point. On todays session it would be 2 days ago close from this session. On the previous day it would again be 2 days from that session so the plot will look like stairs or what you pictured.

        Are you trying to make a horizontal line from the current session going backwards which represents 2 days ago close? The script you are using calculates for each bar and displays the daily series data, that shouldn't remain as a straight line but will change daily.

        Comment


          #5
          Thanks for clarifying this NinjaTrader_Jesse! I wasn't thinking about different market sessions at all (just moved from U.S. Stock Market to trade Futures; so I'm used to these lines matching all the time)! With that, I've got a few more questions for you:
          1. Based on what you said, my understanding is there are two ways of plotting the previous day's close: 1) based on the current session, and 2) based on the daily series data/chart. Is that correct?
          2. I notice that the built-in "Prior Day OHLC" indicator's "close" does not match the close of the candles on the daily chart! Is this because the indicator works based on yesterday's session close, rather than based on the daily series data?
          3. Is there a way to plot the previous day's close price based on the candle's closing price on the daily chart?
          4. On a different note, how can I see the OHLC prices of each candle on different charts? In most trading platforms, when you hover your mouse over any candle on any chart, you can see the OHLC prices (and even more; like the volume, etc.). Does NinjaTrader 8 have that option as well?

          Thanks so much again for taking the time to answer my questions.

          Cheers!

          Comment


            #6
            Hello rezamerik,

            1) Yes you can do either. If you use the session information you would need to do that like the PriorDayOHLC. If you use daily data you can use the secondary series like the sample you linked.

            2) the PriorDayOHLC uses intraday chart data to plot the values and not daily bars. Daily bars can differ from intraday chart data, this depends on the data provider and what session the daily bars were recorded using. You can instead use 1440 minute bars in place of a daily series if you wanted to use data which is in the same trading hours as the other chart data being used.

            3) If you are already using a daily chart then you can just plot Close[1] which would be the previous days bar. You can otherwise add a secondary daily series to get daily bar prices with other series being the primary.

            4) You can do that in a chart, that is known as the data box. Its a button in the charts toolbar to enable that window, alternatively you can press the middle mouse button for the mini data box.





            Comment


              #7
              Thanks NinjaTrader_Jesse! Since I want to use the session information / intraday chart data to plot the values, how can I modify the built-in PriorDayOHLC to plot two days ago OHLC? Not a pro programmer, but I thought changing the Close[0] to Close[1] in the code would do it (see below), but it did not (the file compiles with no issues, but nothing gets plotted on the chart):

              Click image for larger version

Name:	Capture.jpg
Views:	216
Size:	106.0 KB
ID:	1220425
              Thank you!

              Comment


                #8
                Hello rezamerik,

                To find two days ago from now would require using a loop to locate previous data. Bars Ago [1] would only be 1 bars ago, there are many bars in a session so you would need to know how many bars had happened in both the current session and the previous days session to know how many bars ago the close would have been.

                To modify the indicator to use intrabar data you would need to make a custom method similar to the swing indicators SwingLowBar method which uses a for loop. Inside that loop you can compare the current bars time against the times being looped over to find when you have exceeded 2 days. This would be fairly involved, I am not aware of a specific sample that I could link to for that concept.

                Using a secondary series with daily bars or 1440 minute bars would be a better approach so that you can just use [2] BarsAgo which would be 2 daily/1440 minute bars ago and no other logic would be needed. You could modify the sample you linked to originally to use 1440 minute bars instead of daily bars if you wanted it to match the intrabar data instead of daily bars.


                Comment


                  #9
                  Thanks @NinjaTrader_Jesse​! It now works like a charm! No wonder why your profile says you have "a reputation beyond repute"!! I appreciate all the help.

                  Cheers,
                  Reza

                  Comment


                    #10
                    Good day NinjaTrader_Jesse!

                    I just noticed whenever I switch my data series from "Minute" to "Second", the script in this post that we discussed does not work anymore, i.e. it does not plot the two days ago OHLC on the chart! Like it plots the lines accurately on a 1-Minute chart, but on a 60-Second chart or a lower time-frame it shows nothing! Is there a way to fix this?

                    Thank you!

                    Comment


                      #11
                      Hello rezamerik,

                      Are you seeing an error in the control center log when you make that change? If nothing shows up that would usually mean an error has happened.

                      Comment


                        #12
                        Hi NinjaTrader_Jesse,

                        Thanks for your response. I don't see any errors/warnings anywhere! Just noticed the indicator disappears once I switch to a Tich Chart as well! Weird! So basically it only plots on Minute Charts and higher time-frames! Could it be fixed by changing the loaded data series in the indicator?

                        Comment


                          #13
                          Hello rezamerik,

                          Did you make sure to load enough data? The default for second/tick data is 3 days which wont be enough to allow that indicator to work. You would need to load 5 days at the minimum. You would also need to scale out to see the plots when looking at a smaller timeframe as you are focused in on a smaller portion of the day.

                          Comment


                            #14
                            Done! Loaded more than 5 days and now it works! THANK YOU! NinjaTrader_Jesse

                            Comment


                              #15
                              Hello again, NinjaTrader_Jesse!

                              How may I expand the plotted lines from the script in this post to the left and right? They don't show up until the market opens (even though it is from the previous day OHLC), and they start expanding candle by candle (please see below). If possible, I would rather have it printed before the market opens, and have it expanded to the right also.

                              Pleasae note that I have assigned this indicator to a data series with "US Equities RTH" trading hours, as I'm interested in plotting yesterday's OHLC for that session. My main data series, however, is "CME US Index Futures ETH", since I want to see all the data on my chart.

                              Click image for larger version

Name:	Untitled.png
Views:	174
Size:	36.3 KB
ID:	1221396


                              P.S. The reason I assigned this indicator to "US Equities RTH" trading hours is I couldn't find another way to plot yesterday's OHLC for that trading session on CME US Index Futures ETH trading hours. If there is a better way, please let me know!

                              Thank you!

                              ​​​
                              Attached Files
                              Last edited by rezamerik; 10-28-2022, 10:37 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              607 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              353 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              560 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              561 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X