Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Getting accurate OHLC values from higher timeframe

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

    Getting accurate OHLC values from higher timeframe

    I seem to be having a hard time getting the Open price from a 15 min dataseries inside a lower time frame strategy.

    I added a dataseries,,,

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 15);
    }

    and then wrote OnBarUpdate ...

    if ((CurrentBars[1] > 1)
    {
    double CDL15Open = Opens[1][0];
    double CDL15Close = Closes[1][0];
    double CDL15Diff = Math.Round((CDL15Open- CDL15Close),2);

    Draw.Text(this, "CDL15Open", true, CDL15Open.ToString(), 0, High[5], 0, Brushes.White, new SimpleFont(), TextAlignment.Center, Brushes.Orange, Brushes.Black, 10);
    Draw.Text(this, "CDL15Close", true, CDL15Close.ToString(), 0, High[4], 0, Brushes.White, new SimpleFont(), TextAlignment.Center, Brushes.Orange, Brushes.Black, 10);
    Draw.Text(this, "CDL15Diff", true, CDL15Diff.ToString(), 0, High[3], 0, Brushes.White, new SimpleFont(), TextAlignment.Center, Brushes.Orange, Brushes.Black, 10);
    }

    I'm getting values all right but when printed on screen, the values printed where from 2 or 3 candles back as if i had written Opens[1][2];

    How do i reference the OHLC of the currently forming higher time frame in the added dataseries?

    #2
    Hi NTBrass,
    Very interesting. I'm able to reproduce the behaviour (or to commit the same mistake).
    I used the FDAX for illustration purposes, which starts trading at 1.15 am. The first 15M candle completes at 1.30 am.
    Look at the Data Box. It is empty until 1.30 am, which makes perfect sense because this candle first needs to complete before the (first) 15M close is known. As of the start of the next 1M candle, 1.31 am, the (first) 15M values are known and correctly displayed in the DataBox.
    However, plotting of these (first) values only starts at 1.37 am.
    By contrast, plotting as of the next 15M completed candle kicks in immediately after completion of such next 15M candle (1.45 am in my example) and with the right values (candle from 1.30 am to 1.45 am).
    @Ninja: Any idea why the first plot is off in times of timing?
    Thx for letting us know.
    NT-Roland
    Attached Files
    Last edited by NT-Roland; 05-01-2020, 05:34 AM.

    Comment


      #3
      Thanks Roland for confirming this behavior with some serious analysis and screenshots.

      Its obvious that NinjaTrader has the still-forming bar's data as they are plotted charts.

      They just have to provide us with a way of referencing these values real-time.

      Comment


        #4
        Hi NTbrass, thanks for your post.

        I will need a full test script to test. Can you Export a script that is reduced down to its lowest level and describes the issue down to the code level?

        I look forward to hearing from you.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi Chris,

          Please see attached.

          The goal was to show HTF Dataseries OHLC Realtime Values within a strategy where I have added an additional data series.

          Kindly show me how this can be achieved.
          Attached Files

          Comment


            #6
            Hi NTbrass, thanks for your reply.

            The thing about higher time frame timestamps is they only have the resolution of the selected time period. So even if your primary series is going along like this: 1:00, 1:01, 1:02 ..., the 15 minute bar timestamp will remain at the last 15 minute bar time stamp, 1:00, it will change to 1:15 when the next bar closes. I attached a sample script that prints out the two time frames in an organized way. If you need to get multiple price updates intrabar, the strategy would need to run OnEachTick or OnPriceChange. I also included a link to the guide on multi time frame scripts.



            Please let me know if I can assist any further.
            Attached Files
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi Chris,
              Thanks for looking into this, but the answer is not quite addressing what we tried to bring to your attention.
              Look at what I had described/attached, please. Can you please explain why the plot of the 15M bar value (Open, Close) does NOT start when the 15M bar is completed? The DataBox proofs the values are there as soon as the 1st 15M bar is completed.
              However, plotting of such value starts - for whatever reason - with a time lag, i.e. NOT immediately after such values are available , but significantly later 1.37 am in my example. That strange time lag on plotting is what puzzles NTbrass and myself. It's not about "using" the values in a strategy, it's about late "plotting.
              NT-Roland
              Last edited by NT-Roland; 05-01-2020, 03:34 PM.

              Comment


                #8
                Added picture
                Attached Files

                Comment


                  #9
                  Hi NT-Roland, thanks for the clarification.

                  The BarsRequiredToPlot property is set to 20 by default. If you set that to 15 or less do you get plots?



                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Chris,
                    No, it doesn't. Even if the 1st trade is already "on" (b/c the BarsRequiredToTrade is reduced), plotting is still way behind the end of the 1st 15M candle.
                    NT-Roland

                    Attached Files

                    Comment


                      #11
                      Hello NT-Roland, thanks for your reply.

                      BarsRequiredToPlot is different from BarsRequiredToTrade. Did you set BarsRequiredToPlot to something less than 20?

                      I look forward to hearing from you.
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Chris,
                        You nailed it :-).
                        I wouldn't have expected Ninja to apply something which is not in the script (I'm not using the StrategyBuilder), but good to know that an invisible default setting needs to be explicitly overridden.
                        As of now, all my strategies will have one more line, just to be on the safe side. BarsRequiredToPlot = xyz.
                        Thx, NT-Roland

                        Comment


                          #13
                          Hi Chris and Roland,

                          Thanks for your ideas in this thread.

                          These have led me to the below conclusions which still leaves me with the problem I'm trying to solve:

                          1. Since higher timeframes have not closed, you can only retrieve their previous bar's closed values from lower timeframes when you use add data series. There's no way to reference the current OHLC of a 5 minute chart within a strategy running on 2 minutes until the 5 min bar closes.

                          2. Or you may be able to reference higher timeframes' OHLC values if you change strategy calculation to on price chage or each tick. How will I do this? Any sample code to make sure orders are entered ONLY if the bar closes?

                          Also, is it possible to use a static class or static variables applied to a higher timeframe to hold calculated values that are calculated on each tick of the higher time frame? Those values can then read on the close of a lower timeframe chart? If this is possible can you please show me how as I'm still new to NT scripting.

                          Thanks.

                          Comment


                            #14
                            Hi NTbrass, thanks for your reply.

                            If you need intra bar price updates from each series your strategy would need to run OnEachTick. Since they are of the same intrument the price will be the same between the two series.

                            We have an example here that demonstrates how to separate the logic between bar close and on each tick using IsFirstTickOfBar:


                            Yes, you can add a static class within the Addons folder. All price variables are already stored though, so I'm not sure what the use case would be other than sharing information throughout the NinjaTrader system. I have an example here that implements a property changed even in a static class:



                            Please let me know if I can assist any further.
                            Chris L.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by sidlercom80, 10-28-2023, 08:49 AM
                            168 responses
                            2,262 views
                            0 likes
                            Last Post sidlercom80  
                            Started by Barry Milan, Yesterday, 10:35 PM
                            3 responses
                            10 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by WeyldFalcon, 12-10-2020, 06:48 PM
                            14 responses
                            1,429 views
                            0 likes
                            Last Post Handclap0241  
                            Started by DJ888, 04-16-2024, 06:09 PM
                            2 responses
                            9 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Started by jeronymite, 04-12-2024, 04:26 PM
                            3 responses
                            41 views
                            0 likes
                            Last Post jeronymite  
                            Working...
                            X