Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get indicator value based on another chart timeframe post

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

    #31
    Hello DawnTreader,

    Issue: the output value of the 5m and 10m Slopes are showing the values from their previous bar close, not their current values on each 1m update.​
    This would suggest that either you are looking at the historical values without using TickReplay, or you changed the Calculate setting in State.SetDefaults but did not remove the old strategy instance and add a new instance to load the new Calculate setting. May I confirm that either of these are not the case?

    When I test your strategy out, I do see the MA values update on each tick for the added data series. I recorded a video of the test that demonstrates that the currently updating values of the 5m EMA and SMA from your strategy are the same as what is being shown on a 5-minute chart with the EMA and SMA directly applied (calculating on each tick). The values are matching, showing that your strategy is updating the values correctly.

    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

    Comment


      #32
      Hey Gaby, thanks for the video! I'm seeing the same thing in realtime, but my question is, how do I get the current values in Playback (using Market Replay with tick data) AND in the Strategy Analyzer? I've tried checking the TickReplay box in the Strategy Analyzer, but it's still giving me the values of the additional data series at its previous bar close, not at the 1m updates/closes. I've tried updating the Calculate settings to all three options (bar close, tick, and price) with no luck.

      While testing in Playback, I may have not tried removing the strategy and then adding it again after updating the file. So, I will try that. However, let me know if it's possible to accomplish this using the Strategy Analyzer, as that is my main concern.

      Thanks!

      Comment


        #33
        Hello,

        It would require enabling Tick Replay and implementing intrabar granularity.

        Please review the help guide page on the differences on real-time vs backtest.



        To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar. Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.​

        Comment


          #34
          Hey, did you check out my script from a few posts ago? I'm using the EMA and SMA on a 1m chart with an additional 5m data series. When I run this in the Strategy Analyzer, with Tick Replay checked, and look at my Prints, the 5m Slope values are from their previous bar closes (5m) and not their current values on the 1m bar close, which I'm checking when BarsInProgress == 0 and IsFirstTickOfBar is true. Does that make sense?

          Can you verify this and let me know what I'm doing wrong? I have not implemented the order logic yet. Thanks!
          Last edited by DawnTreader; 07-06-2024, 02:14 PM.

          Comment


            #35
            Hello,

            Yes, that is the script I tested in my video.

            When I backtest the script with Tick Replay enabled, I am seeing the 5m EMA and SMA values updating intrabar, as well as the slope values.

            If you add the following print statement to your script, what output are you seeing?

            Print(Times[0][0] + " EMA5m: " + EMA5m[0] + " SMA5m[0]: " + SMA5m[0] + " Slope EMA5m: " + GetSlopeAngle(EMA1m) + " Slope SMA5m: " + GetSlopeAngle(SMA5m));​

            Comment


              #36
              Hmm, weird. I am seeing it print correctly now. However, when I also print the OHCL it's showing the same price for each one. Example:

              ------------------------------------------------
              6/12/2023 8:58:00 AM
              Bar: 1017
              Closes[0][0]: 15452.25
              Close[0]: 15452.25
              Open[0]: 15452.25
              High[0]: 15452.25
              Low[0]: 15452.25
              ------------------------------------------------
              6/12/2023 8:59:00 AM
              Bar: 1018
              Closes[0][0]: 15457.25
              Close[0]: 15457.25
              Open[0]: 15457.25
              High[0]: 15457.25
              Low[0]: 15457.25
              ------------------------------------------------
              6/12/2023 9:00:00 AM
              Bar: 1019
              Closes[0][0]: 15451.25
              Close[0]: 15451.25
              Open[0]: 15451.25
              High[0]: 15451.25
              Low[0]: 15451.25
              ------------------------------------------------

              I think this is why I was confused as I assumed my `buyConditions` and `sellConditions` that were not returning the expected true/false were failing because of the 5m values. However, it appears the issue is with the OHCL values not giving me the correct price. Why is this?

              Comment


                #37
                Hello Dawn,

                I am not seeing this behavior. What values are you printing out? Could you let me know if you enabled Tick Replay while running this test?

                Using this print statement, I do not see the OHLC have the same exact values:

                Print(Times[0][0] + " Opens[0][0]: " + Opens[0][0] + " Highs[0][0]: " + Highs[0][0] + " Lows[0][0]: " + Lows[0][0] + " Closes[0][0]: " + Closes[0][0]);

                Comment


                  #38
                  Ok, what in the world is going on!! All the OHLC values are now working but the 5m EMA/SMA from before aren't working—it's showing me the values from it's previous bar close (e.g. every 5 minutes is showing the same value for EMA5m[0]). Here's the print of the 5m EMA, SMA, and the Slope values:

                  ------------------------------------------------
                  6/23/2023 8:50:00 AM
                  EMA5m[0]: 15711.8688438973
                  SMA5m[0]: 15713.8214285714
                  Slope EMA5m: 80.3927186206433
                  Slope SMA5m: 78.0238675557979
                  ------------------------------------------------
                  6/23/2023 8:51:00 AM
                  EMA5m[0]: 15711.9450751178
                  SMA5m[0]: 15716.0714285714
                  Slope EMA5m: 4.35929600467609
                  Slope SMA5m: 66.0375110254218
                  ------------------------------------------------
                  6/23/2023 8:52:00 AM
                  EMA5m[0]: 15711.9450751178
                  SMA5m[0]: 15716.0714285714
                  Slope EMA5m: 4.35929600467609
                  Slope SMA5m: 66.0375110254218
                  ------------------------------------------------
                  6/23/2023 8:53:00 AM
                  EMA5m[0]: 15711.9450751178
                  SMA5m[0]: 15716.0714285714
                  Slope EMA5m: 4.35929600467609
                  Slope SMA5m: 66.0375110254218
                  ------------------------------------------------
                  6/23/2023 8:54:00 AM
                  EMA5m[0]: 15711.9450751178
                  SMA5m[0]: 15716.0714285714
                  Slope EMA5m: 4.35929600467609
                  Slope SMA5m: 66.0375110254218
                  ------------------------------------------------
                  6/23/2023 8:55:00 AM
                  EMA5m[0]: 15711.9450751178
                  SMA5m[0]: 15716.0714285714
                  Slope EMA5m: 4.35929600467609
                  Slope SMA5m: 66.0375110254218
                  ------------------------------------------------
                  6/23/2023 8:56:00 AM
                  EMA5m[0]: 15708.2060600943
                  SMA5m[0]: 15712.0714285714
                  Slope EMA5m: -75.0266828258606
                  Slope SMA5m: -75.9637565320735
                  ------------------------------------------------
                  6/23/2023 8:57:00 AM
                  EMA5m[0]: 15708.2060600943
                  SMA5m[0]: 15712.0714285714
                  Slope EMA5m: -75.0266828258606
                  Slope SMA5m: -75.9637565320735
                  ------------------------------------------------
                  6/23/2023 8:58:00 AM
                  EMA5m[0]: 15708.2060600943
                  SMA5m[0]: 15712.0714285714
                  Slope EMA5m: -75.0266828258606
                  Slope SMA5m: -75.9637565320735
                  ------------------------------------------------
                  6/23/2023 8:59:00 AM
                  EMA5m[0]: 15708.2060600943
                  SMA5m[0]: 15712.0714285714
                  Slope EMA5m: -75.0266828258606
                  Slope SMA5m: -75.9637565320735
                  ------------------------------------------------
                  6/23/2023 9:00:00 AM
                  EMA5m[0]: 15708.2060600943
                  SMA5m[0]: 15712.0714285714
                  Slope EMA5m: -75.0266828258606
                  Slope SMA5m: -75.9637565320735
                  ------------------------------------------------​​

                  Here are my Print statements:
                  Print("EMA5m[0]: " + EMA5m[0]);
                  Print("SMA5m[0]: " + SMA5m[0]);
                  Print("Slope EMA5m: " + GetSlopeAngle(EMA5m));
                  Print("Slope SMA5m: " + GetSlopeAngle(SMA5m));​

                  How is this possible? I thought it was an issue with NT logging me out after a while, as it does this every time, but after shutting it down and logging back in, the print above is what I'm seeing. And yes, I have Tick Replay enabled. Can you try this Print statement to confirm?

                  Thanks again.

                  Comment


                    #39
                    Hello,

                    I'm not seeing this same data, this output would suggest that Tick Replay is not enabled or your print is within a condition that only evaluates once per bar.

                    Below I am attaching the output I'm getting as well as the script used to test in the Strategy Analyzer. It is the original script you shared, just with the Print statements added. However, I'm sharing this because I'm curious if you have further edited the script which may also be leading to discrepancies.

                    You can see from my output the values of the EMA5m, SMA5m, as well as their slopes are getting updated intrabar. I did enable Tick Replay when testing this in the Analyzer.

                    Please note that if you have your print statement within your IsFirstTickOfBar condition, this will lead to it only calculating and printing once per bar, as if you were using Calculate.OnBarClose. IsFirstTickOfBar is only going to be true once per bar. This applies to any logic you have within a condition that uses IsFirstTickOfBar.
                    Attached Files

                    Comment


                      #40
                      Hey, thanks for the update. I'm checking the values inside the IsFirstTickOfBar condition because I want to get the value of the 5m EMA/SMA on the 1m post. Why wouldn't this get the current values of the 5m indicators? How do I get their current values on the 1m (primary series) post?

                      Comment


                        #41
                        IsFirstTickOfBar is only going to evaluate true once, on the first tick of the bar. Therefore, any logic within your isFirstTickOfBar condition is only going to be evaluated one time for every 1 minute bar (so within this condition you will not see any intrabar updates for the 1 minute or 5 minute series).

                        You should use IsFirstTickOfBar if you only want to check for updates once per bar (basically OnBarClose).

                        If you are looking to check the 5m values on every tick of a 1m bar, do not use IsFirstTickOfBar.

                        Your "if (BarsInProgress != 0) return;" already ensures that the script is only going to check for updates on the 1 minute (primary data series).


                        Have you taken a look at where the print statements are in the script in my previous post? They are not within the isFirstTickOfBar condition. ​

                        If you test out this version of the script, are these the values you are expecting to see?

                        Comment


                          #42
                          I'm sorry if I'm not being clear. Here is what I want to do: I want to check/get the 5m values on the bar close of the 1m series (primary).

                          This doesn't work when using IsFirstTickOfBar. So, are you saying that I need to check for updates on every tick in order to get the 5m values? If so, then how do I check when it's the last tick of the 1m bar, because that's when I want to get the 5m values? Does that make sense?

                          Comment


                            #43
                            Hello DawnTreader,

                            Correct, if you want to see the values updating on every tick, this should not be in a condition checking for IsFirstTickOfBar as this is only true of the first tick of a new bar.

                            If you do want to check the values only after a bar has closed, then this would be put in a condition checking for IsFirstTickOfBar.

                            Note, IsFirstTickOfBar is in relation to the BarsInProgress updating OnBarUpdate(). This means if you want the 5 minute values only after the 5 minute bar has closed, then this should be in a condition checking that BarsInProgress is the index of that 5 minute series.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #44
                              Right, I understand that. However, I am unable to get the 5m values (EMA/SMA) on the bar close of the 1m series (primary) using IsFirstTickOfBar. Doing so does not give me the current values of the 5m EMA/SMA, it gives me their values from their previous 5m bar close. Does that make sense? So, how do I get the 5m EMA/SMA values on each 1m bar close?

                              Comment


                                #45
                                Hello DawnTreader,

                                If the script is using Calculate.OnEachTick, then for all series the barsAgo [0] index value will be for the currently updating bar. (The Calculate setting cannot be applied to some series and not others).

                                This means when the 1 minute series has the first tick of a new bar, the value from the 5 minute series will be whatever the most recently updated price was for that series.
                                Chelsea B.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Yesterday, 05:17 AM
                                0 responses
                                62 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                134 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                75 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                45 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                50 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X