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

    #16
    Hello Dawn,

    However, checking the SMA values of the 5m and 10m bars on the 1m post will vary. For example, at 7:31 the SMA on the 5m may be pointing up, but at 7:32 it may be pointing down.
    This isn't true, since it is calculating on 5 minute bars it is only going to update every 5 minutes. When it hits a 5 minute timestamp, you'll see the values update per tick.

    Take a look at the output for this sample script. It plots and prints out the value on each tick of an 5 minute SMA that is also calculating on each tick.

    You'll notice timestamps between 5 minute markers do not change value. Only 7:00, 7:05, 7:10 etc. actually have the value update.
    Attached Files

    Comment


      #17
      You'll notice timestamps between 5 minute markers do not change value. Only 7:00, 7:05, 7:10 etc. actually have the value update.
      Are you talking about the value of the time? I'm talking about the value of the SMA. I apologize, this is all new to me.

      Here's some example output from your script:

      Code:
      4/17/2024 7:50:00 AM 17936.8571428571
      4/17/2024 7:50:00 AM 17936.875
      4/17/2024 7:50:00 AM 17936.875
      4/17/2024 7:51:00 AM 17936.0178571429
      4/17/2024 7:51:00 AM 17936.0178571429
      4/17/2024 7:51:00 AM 17936.0178571429
      4/17/2024 7:51:00 AM 17936
      4/17/2024 7:51:00 AM 17936​​
      As you can see, the SMA values are changing when the price changes and could be the same or different between each tick. I can watch the values and direction of the line of the SMA change on each tick or price change on the charts when in Playback. For example, the direction of the SMA line of the 5m chart could change (up, down, flat) multiple times within it's 5 minute candle. So, at any given 1m post within the 5m candle, the direction of the SMA line (and values) could be different.

      So, back to my original question, is it possible to determine the following:

      Primary chart: 1m with SMA
      Additional charts (or timeframes, or DataSeries, or whatever the correct term is): 5m, 10m with SMA
      At each 1m candle post: Determine the direction of the SMA line on all charts.

      Is that possible?​ If that's still unclear, let me know where I need to clarify or if there's a better way to communicate. Thank you so much!

      Comment


        #18
        Hello,

        Thank you for your response.

        No, I am not talking about the time. I'm referring to the value of the SMA. What timeframe chart have you applied this indicator to?

        When applied to a 1minute chart, you can see the value of the 5minute SMA would not change during that 5 minutes.

        From the output below, we can see that from 4:55AM-4:59AM, the value doesn't change. There are no updates to the value of the 5 minute SMA applied to a 1 minute chart on 4:56, 4:57, 4:28, or 4:59AM.

        It only changes 5 minutes later, at 5:00AM. There are no updates at 5:01, 5:02, 5:03, or 5:04AM.

        Then once again the value does not update until 5:05AM, and so on. There are no updates between the 5 minute increments because the SMA is calculated on the 5 minute bars. You will see similar behavior for an SMA calculated on 10 minute bars applied to a 1 minute chart.

        5/13/2024 4:55:00 AM 5251.625
        5/13/2024 4:55:00 AM 5251.625
        5/13/2024 4:56:00 AM 5251.625
        5/13/2024 4:57:00 AM 5251.625
        5/13/2024 4:58:00 AM 5251.625
        5/13/2024 4:59:00 AM 5251.625
        5/13/2024 5:00:00 AM 5251.78571428571
        5/13/2024 5:00:00 AM 5251.78571428571
        5/13/2024 5:01:00 AM 5251.78571428571
        5/13/2024 5:02:00 AM 5251.78571428571
        5/13/2024 5:03:00 AM 5251.78571428571
        5/13/2024 5:04:00 AM 5251.78571428571
        5/13/2024 5:05:00 AM 5251.89285714286
        5/13/2024 5:05:00 AM 5251.89285714286
        5/13/2024 5:06:00 AM 5251.89285714286
        5/13/2024 5:07:00 AM 5251.89285714286
        5/13/2024 5:08:00 AM 5251.89285714286
        5/13/2024 5:09:00 AM 5251.89285714286
        5/13/2024 5:10:00 AM 5252.08928571429
        5/13/2024 5:10:00 AM 5252.08928571429
        5/13/2024 5:11:00 AM 5252.08928571429
        5/13/2024 5:12:00 AM 5252.08928571429
        5/13/2024 5:13:00 AM 5252.08928571429
        5/13/2024 5:14:00 AM 5252.08928571429
        5/13/2024 5:15:00 AM 5252.25
        5/13/2024 5:15:00 AM 5252.25

        Since you are using Calculate.OnEachTick, you may see the value of the SMA change multiple times per tick on on every 5:00, 5:05, 5:10 timestamp. But nothing in between.

        If you look at the SMA displayed visually on the chart, this ​backs this up. It has a stair-stepping effect because for for timestamps in between the 5 minute updates, the value of the SMA isn't updating. It only updates every 5 minutes. ​

        Comment


          #19
          I'm applying the script you provided to the 1m minute chart. If I add the SMA to a 5m chart I can watch the value change with each price change. Here's some output from your script:

          Code:
          5/13/2024 8:15:00 AM  1Min SMA: 18291.125,  5Min SMA: 18298.8035714286,  10Min SMA: 18305.7857142857
          5/13/2024 8:15:00 AM  1Min SMA: 18291.125,  5Min SMA: 18298.8035714286,  10Min SMA: 18305.7857142857
          5/13/2024 8:15:00 AM  1Min SMA: 18291.125,  5Min SMA: 18298.8035714286,  10Min SMA: 18305.7857142857
          5/13/2024 8:15:00 AM  1Min SMA: 18291.1071428571,  5Min SMA: 18298.7857142857,  10Min SMA: 18305.7678571429
          5/13/2024 8:15:00 AM  1Min SMA: 18291.0892857143,  5Min SMA: 18298.7678571429,  10Min SMA: 18305.75
          5/13/2024 8:15:00 AM  1Min SMA: 18291.0892857143,  5Min SMA: 18298.7678571429,  10Min SMA: 18305.75
          5/13/2024 8:15:00 AM  1Min SMA: 18291.0892857143,  5Min SMA: 18298.7678571429,  10Min SMA: 18305.75
          5/13/2024 8:15:00 AM  1Min SMA: 18291.0892857143,  5Min SMA: 18298.7678571429,  10Min SMA: 18305.75
          5/13/2024 8:15:00 AM  1Min SMA: 18291.0892857143,  5Min SMA: 18298.7678571429,  10Min SMA: 18305.75
          5/13/2024 8:15:00 AM  1Min SMA: 18291.0892857143,  5Min SMA: 18298.7678571429,  10Min SMA: 18305.75
          5/13/2024 8:15:00 AM  1Min SMA: 18291.0714285714,  5Min SMA: 18298.75,  10Min SMA: 18305.7321428571
          5/13/2024 8:15:00 AM  1Min SMA: 18291.0714285714,  5Min SMA: 18298.75,  10Min SMA: 18305.7321428571
          5/13/2024 8:16:00 AM  1Min SMA: 18291.375,  5Min SMA: 18296.6785714286,  10Min SMA: 18305.7142857143
          5/13/2024 8:16:00 AM  1Min SMA: 18291.375,  5Min SMA: 18296.6785714286,  10Min SMA: 18305.7142857143
          5/13/2024 8:16:00 AM  1Min SMA: 18291.3928571429,  5Min SMA: 18296.6964285714,  10Min SMA: 18305.7321428571
          5/13/2024 8:16:00 AM  1Min SMA: 18291.3928571429,  5Min SMA: 18296.6964285714,  10Min SMA: 18305.7321428571
          5/13/2024 8:16:00 AM  1Min SMA: 18291.3928571429,  5Min SMA: 18296.6964285714,  10Min SMA: 18305.7321428571
          5/13/2024 8:16:00 AM  1Min SMA: 18291.3928571429,  5Min SMA: 18296.6964285714,  10Min SMA: 18305.7321428571
          5/13/2024 8:16:00 AM  1Min SMA: 18291.3928571429,  5Min SMA: 18296.6964285714,  10Min SMA: 18305.7321428571
          5/13/2024 8:16:00 AM  1Min SMA: 18291.375,  5Min SMA: 18296.6785714286,  10Min SMA: 18305.7142857143
          5/13/2024 8:16:00 AM  1Min SMA: 18291.3928571429,  5Min SMA: 18296.6964285714,  10Min SMA: 18305.7321428571
          5/13/2024 8:16:00 AM  1Min SMA: 18291.3571428571,  5Min SMA: 18296.6607142857,  10Min SMA: 18305.6964285714
          5/13/2024 8:16:00 AM  1Min SMA: 18291.3571428571,  5Min SMA: 18296.6607142857,  10Min SMA: 18305.6964285714
          5/13/2024 8:16:00 AM  1Min SMA: 18291.3571428571,  5Min SMA: 18296.6607142857,  10Min SMA: 18305.6964285714​
          This output shows the 5m value changing. Are you not seeing the same thing?

          And back to my original question—is it possible to determine the direction of the SMA line on all charts (1m, 5m, 10m) on the 1m post?

          Comment


            #20
            Hello DawnTreader,

            Could you please provide some more information on what exactly you want to detect? What do you mean by the "direction"?

            Do you mean checking if the previous value SMA calculating from the 5-Minute series is greater than the current value?
            Or, do you want to check if the slope is positive or negative to determine if it is trending up or down?

            I look forward to your response.

            Comment


              #21
              I've tried explaining this in the previous posts, so maybe images will help. The two screenshots below show a 1m and 5m chart with the EMA 9 Period (orange line), calculating on each tick. This EMA-9 works better than the SMA-14 for seeing what I'm wanting to do.

              This first screenshot shows a post at 7:32—the 1m EMA is pointing down and the 5m EMA is pointing up.

              Click image for larger version

Name:	EMA9-Direction-1.png
Views:	166
Size:	166.4 KB
ID:	1303500


              This second screenshot shows a post at 7:34 (2 minutes later)—the 1m EMA is pointing down and the 5m EMA is now pointing down.

              Click image for larger version

Name:	EMA9-Direction-2.png
Views:	120
Size:	165.3 KB
ID:	1303501


              So, I am wanting to check whether or not the EMA's on both charts are pointing up or down on each 1m post. Is that more helpful?

              Thanks!

              Comment


                #22
                Hello DawnTreader,

                Thank you for clarifying. I apologize for any confusion!

                You could use the Slope() function to calculate the slope and supply your EMA or whatever indicator as the series. This would allow to you identify if there a negative slope/trend or a positive slope/trend over the area you want to examine. You would need to supply a startBarsAgo and endBarsAgo to calculate over. It's up to you over how many bars you want to examine the slope.



                Similarly to how we were discussing earlier, you can check this value on every 1 minute bar update if this is supplied to 1 minute chart as the primary series by checking this when BIP 0.

                Please let us know if you have any further questions.

                Comment


                  #23
                  Thank you, that's helpful. I'm having problems getting the Slope of the 5m EMA when the 1m posts. I keep getting a "bars out of range" error. Any suggestions?

                  Comment


                    #24
                    Hello,

                    This message is indicating the specific index requested from a collection does not exist. Indexes must be a non-negative number and less than the size of the collection. The error may be indicating the index requested is larger than the number of elements in the collection.

                    In the case of barsAgo values with Series, any barsAgo index must be less than CurrentBar (the total number of bars is the size of a Series collection).

                    Code:
                    // require BarsInProgress 0 to have 3 bars processed, require BarsInProgress 1 to have 4 bars processed
                    if (CurrentBars[0] < 3 || CurrentBars[1] < 4)
                    return;
                    
                    Print(Times[0][3]); // this does not cause an error as CurrentBars[0] is equal to or greater than 3
                    
                    Print(Times[1][4]); // this does not cause an error as CurrentBars[1] is equal to or greater than 4
                    
                    Print(Times[0][5]); // this line of code will cause an invalid index error. When CurrentBars[0] is 4 there is no bar 5 bars ago
                    ​
                    The help guide discusses ‘Make sure you have enough bars in the data series you are accessing’ .
                    NinjaScript > Educational Resources > Tips > Make sure you have enough bars in the data series you are accessing

                    Comment


                      #25
                      Hey, regarding your previous comment:
                      Similarly to how we were discussing earlier, you can check this value on every 1 minute bar update if this is supplied to 1 minute chart as the primary series by checking this when BIP 0.
                      I still don't understand how I can get the Slope of the 5m EMA on every 1 minute bar. For example, the output of the following code is the same for every 1m bar up to it's timeframe of 5m, and then it updates. If I change the EMA indicator to calculate on price change, I am wanting the Slope of that leading edge on each 1m update.
                      Code:
                      Slope(EMA(BarsArray[1], 9), 1, 0);
                      When you change the EMA to calculate on price change, then the angle, or slope, of the line changes with each price change. I want to know that exact Slope when the 1m bar posts. Does that make sense? Thanks again!

                      Comment


                        #26
                        Hello DawnTreader,

                        Thank you for your response.

                        Are you looking at the results in real time, or historically?

                        Historical data is processed OnBarClose(). Historical data is comprised of the bars open, high, low, close, volume and time, and does not contain all of the ticks to build the bar. When your strategy is run on historical data, regardless of your Calculate setting, the code can only run as if it was using Calculate.OnBarClose. The current bar is always a just closed bar and your code can only run once per bar.

                        ​If you run the attached sample script, you will see the historical output first which will only have an updated value every 5m. However, once the indicator starts calculating in real-time, you can see the intrabar values change.

                        Make sure to run the script on a 1m chart. ​
                        Attached Files

                        Comment


                          #27
                          Hey, sorry for the long delay! Just to recap and clarify:
                          • I am building a Strategy
                          • Primary chart (data series) is a 1m chart
                          • I've added a 5m and 10m DataSeries to the Strategy and have three charts of those timeframes synched together.
                          • All three timeframes have the EMA and SMA indicators
                          • On each 1m update (bar close, candle post, whatever the correct terminology is...) I want to check if the Slope() of the EMA and SMA is greater than zero on all three timeframes.
                          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.

                          So, the question is -- in both Playback, using Market Replay tick data that I have, and the Strategy Analyzer (backtest and optimization), how do I get the current Slope values of the higher timeframes on 1m updates?

                          Comment


                            #28
                            Hello Sir Please send me strategy I can help you fix the issues if you want
                            thanks

                            Comment


                              #29
                              Hey ajgauss13, I've attached a simplified version of the strategy. Thanks for the help!
                              Attached Files

                              Comment


                                #30
                                NinjaTrader_Gaby any help would be greatly appreciated!

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Yesterday, 05:17 AM
                                0 responses
                                54 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                130 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                73 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                44 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                49 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X