Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stair Step Effect on Multi Time Frame Strategy

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

    Stair Step Effect on Multi Time Frame Strategy

    Hello,

    I have the same issue with the "stairstep" effect when plotting an indicator for a secondary series on the primary series chart. I slightly modified the Example strategy and indicator that Kate designed- Please notice that the issue persists.

    Do you have any idea how to fix this?

    Attached Files

    #2
    Hi Bob, thanks for posting. The chart plots will have a slot index for each bar that is on the chart. If you plot based on a secondary series you will get a stair stepping effect. The best way to plot data from a sercondary series is to save the data in BarsInProgress == 1 then plot the value in BarsInProgress == 1 e.g.

    Code:
    private double savedValue;
    
    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 0)
    {
         Value[0] = savedValue;
    }
    if (BarsInProgress == 0)
    {
        savedValue = SecondaryEMAValue[0];
    }​
    }

    Comment


      #3
      Hi Chris,

      Thank you for replying. I didn't quite understand your code example. Both "if" statements refer to the BarsInProgress == 0. Is that correct?

      And, shall I use your example code from the strategy, or insert it into the EmaSecondarySerires indicator?
      Last edited by bobperez; 12-13-2022, 10:02 AM.

      Comment


        #4
        Chris,

        This is the code I inserted into the indicator, based on my understanding of your explanation.

        Code:
                    if (BarsInProgress == 1 && CurrentBars[1] > 0)
                    {
                        previous = (CurrentBar == 0 ? Input[0] : Input[0] * constant1 + constant2 * previous);
                        //previous = Value[0];
                    }
                    if (BarsInProgress == 0 && CurrentBars[0] > 1)
                    //else if (CurrentBars[0] > 1)
                        //Value[0] = Value[1];
                        Value[0] = previous;
        
        ​
        ​
        The stairstep persists.

        BobPerez

        Click image for larger version

Name:	StairStep.png
Views:	430
Size:	19.6 KB
ID:	1227376
        Attached Files

        Comment


          #5
          Hi BobPerez, thanks for the follow-up. The output depends on the secondary series you are using and this is expected to happen. If you are using a primary series that updates faster than the secondary series, the secondary series values will be the same while the primary bars change, so you will get flat lines.

          Comment


            #6
            Bob the stairstep plot is actually the true nature of the timing of changes in the higher level plot.. smoothing it future might look smoother or prettier but in reality that smoother view is a little bit dishonest if you are seeking accuracy to be visible on your faster time frame chart.

            However if you really want a smoother view of the higher time frame EMA on your faster chart then inside the indi wrap the higher time frame EMA in an EMA based on the faster primary data series and "split" the ema lengths between both of the stacked EMAs so you are not creating additional lag in the now smoother EMA visible on your chart.

            hedge

            Comment


              #7
              Thanks to both Hedge and ChrisL for your reply.

              So, in conclusion, I assume the result is correct. I am using Unirenko T2O1R8 for the primary series and Range,8 for the secondary series.

              Bob

              Comment


                #8
                Click image for larger version  Name:	Stairstep1.png Views:	0 Size:	27.3 KB ID:	1247643

                Hello, I continue having issues with the stairstep behavior. If you manually add a secondary series to a chart and add an EMA to this secondary series, you can move the EMA to the primary-series price panel and it plots smoothly. Can't this be achieved programmatically?

                In the screenshot I programmatically plotted two 5 min Moving Averages on a 1 min chart. I manually added a 5 min secondary series and plotted the same EMA(9) and moved it to the primary series panel. It prints smoothly.

                It's important because my strategy triggers entries based on the 5 min MA values.

                Bob
                Last edited by bobperez; 04-21-2023, 06:39 PM.

                Comment


                  #9
                  Hi bobperez


                  Did you manage to get that indicator to work?

                  Roland

                  Comment


                    #10
                    Originally posted by BigRol00 View Post
                    Hi bobperez


                    Did you manage to get that indicator to work?

                    Roland
                    Hi Roland, No, I didn't. The stairstep indicators that I show on the screenshot were programmatically plotted and the smoother EMA was moved from the lower panel to the upper panel manually.

                    Bob

                    Comment


                      #11
                      Are you able to plot a second series like an ema from Nasdaq on a S&P chart?

                      Comment


                        #12
                        Originally posted by BigRol00 View Post
                        Are you able to plot a second series like an ema from Nasdaq on a S&P chart?
                        Programmatically or manually?

                        Comment


                          #13
                          I have no programming experience, but interested if it can be done

                          Comment


                            #14
                            Originally posted by BigRol00 View Post
                            I have no programming experience, but interested if it can be done
                            I'm sure it can be done, but I haven't figured it out. I'm waiting for someone from Ninja to reply and show how to programmatically achieve what is manually so easy to solve by just moving the 5min MA from the lower panel to the 1min upper panel and keeping a smooth and accurate MA.
                            Last edited by bobperez; 04-23-2023, 12:10 PM.

                            Comment


                              #15
                              Yes, it could be achieved programmatically, but as others have posted above, that's deceptive. What you would be doing to achieve it programmatically is interpolating between the two adjacent closes of the higher time frame and drawing a straight line from one to the other, even though that covers several bars on the actual charting time frame. In reality, though, the SMA or whatever it is didn't take a straight-line course during that period of time. The typical way to handle this is to "freeze" the closed bar value of the higher time frame for the entire next higher time frame bar (until that higher time frame bar closes, when it should pop to the new value - resulting in the stair-step appearance). This is analogous to running OnBarClose on the higher time frame and is the most common way this analysis would be done. Although it's easy to imagine drawing a "smooth" line on top of the higher frequency chart bars so it appears without the stair-step, that is deceptive because that is not what actually happened intrabar on that time frame. It did not smoothly go from one value to the next - it popped to the new value instantaneously when that bar closed.

                              The alternative is to intrabar update the longer time frame MA during each bar on the faster (charting) time frame or even on each price change - this would result in a sort of staggered stairstep effect where it sort of wanders until the longer time frame bar closes, then it pops to the new area to wander around that area. This is sometimes done, but usually it's the stair step appearance because that corresponds accurately to what you would have had to work with in an OnBarClose environment on that longer time frame.
                              Bruce DeVault
                              QuantKey Trading Vendor Services
                              NinjaTrader Ecosystem Vendor - QuantKey

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              601 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              347 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              559 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              558 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X