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

Overlay Minute based indicator on bar chart trouble

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

    Overlay Minute based indicator on bar chart trouble

    I'm trying to write an indicator based on Stochastics that I can overlay onto a Range Bar chart and am having strange results.

    So here is the premise: If I am using 3 minute bars in the indicator, wouldn't I get the same results as a Stochastic on a 3 min chart? I've printed the open hi low close of the bar and it matches the 3 min chart, however the Stochastic values don't match up between the 2 charts.

    My process:
    Copy the Stochastics indicator.
    Add 3minute bars:
    Code:
    	// add the Minute bars for the STO
    			Add(PeriodType.Minute, STOPeriod);
    Only do the Stochastics computations when a new 3 min bar is formed:
    Code:
    		if (BarsInProgress == 1)
    Thoughts?

    #2
    Hi TiggerTrader,

    Thanks for your post.

    Yes, if the calculation is done during BarsInProgress 1, it will be during the secondary added data series.

    However, if you are setting a plot, there will be one plot per primary bar. (But will still use the calculations from the 3 minute.

    As an example, attached is the SMA modified (SMA3MinuteExample) to use a 3 minute series.

    Try adding this modified script to a 1 minute chart, then try adding the original SMA to a 3 minute chart.
    (The data will be the same but jagged since it isn't updated on each minute)
    Attached Files
    Last edited by NinjaTrader_ChelseaB; 11-07-2014, 09:24 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes, I get that. However the calculated values are different from the 3min in a Range chart vs the 3min chart itself.

      For example, the D = 97.99 on one and 66.56 on the other. Obviously the tick by tick price values are the same, why would the computations come up differently?

      Comment


        #4
        Hi TiggerTrader,

        I see your point.

        The issue is that the primary bar sometimes has more values than the secondary bar and sometimes is has less. The calculation is using previous values of the plot which can cause data to be included multiple times or skipped.

        Instead of using the previous value of the indicator, I've changed the script to save the values to a list and use the list.

        This prevents duplicates and items from being removed in the calculation. Test this on any time frame and it should work correctly.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by TiggerTrader View Post
          Yes, I get that. However the calculated values are different from the 3min in a Range chart vs the 3min chart itself.

          For example, the D = 97.99 on one and 66.56 on the other. Obviously the tick by tick price values are the same, why would the computations come up differently?
          • What is your line that is calling the Stochastics calculation?
          • Are you calculating it on the correct BarSeries?

          Comment


            #6
            That makes sense. Now, in theory, if you put the indicator on a non-minute chart, but use OCBC=true, they should be identical because ONLY when the 3min bar closes will you get called to calculate the data.

            I tried it and it is the same using the SMA idea. However the STO is is vastly different, even tho the theory is that it is the same data.

            @koganam: Just wrap the Stochastics with
            Code:
            	if (BarsInProgress == 1)
            and you have it.

            Comment


              #7
              Hi TiggerTrader,

              Are you referring to the Stochastics as the STO?

              Are you using a List object similar to the example I have posted?

              Are you finding there is an issue with the example I have posted?
              (I tried this on a 4 Range chart and posted a screenshot. It looks correct to me)
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Yes, STO is just short for Stochastics.

                No I did not, but that's my point. If the indicator is called OnBarUpdate ONLY when the bar (3min bar) closes, wouldn't the data be the same as the real 3min chart data & therefore the STO's would be identical?

                Comment


                  #9
                  Hi TiggerTrader,

                  If you are using the original code and you are not using a List array and the code has just been thrown in BarsInProgress 1, the number of bars is going to mess up the calculation.

                  No, it will not be the same.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    I'm not understanding this. If OCBC=true, then the code for 3min added bars (to ANY chart) will be called exactly at the same time as a 3min chart primary bar, and the data for the newly closed bars should be the same. So, then that data goes to the calculation part and should produce the same value. What am I missing?

                    Comment


                      #11
                      Hi TiggerTrader,

                      I didn't quite understand "when the bar (3min bar) closes, wouldn't the data be the same as the real 3min chart data" but I am understanding this now.

                      You are saying you have this on a 3 minute chart. If you print CurrentBars[0] and CurrentBars[1] do these match on every bar?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        I mean that on any type of chart, bar, minute, tick, if CurrentBars[1] is the 3min bar you added to the indicator, with OCBC= true a true 3min chart with the indicator and any other chart of your choice with your custom indicator with the added 3min bars will get called the same time with the same data. Isn't that correct, logically?

                        If so, the indicators should match, although on the custom one, it may look "choppy", but the current value computed should be the same at every 3min interval.

                        Comment


                          #13
                          Hi TiggerTrader,

                          No, if you use a different interval other than 3 minute, then number of bars used for calculation will be incorrect.

                          This is demonstrated in the example that I have provided for you. Have you had a moment to test this and see how it works?

                          In other words, data series are synced with the primary data series of the chart only. If you use a data series in the calculation, the number of bars is going to be incorrect and your calculation will be incorrect.

                          In the example I get around this by using a List.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Arrrg, I guess I'm not saying this correctly.

                            8 Range chart with the custom Stochastics.
                            3 min chart with the normal Stochastics.

                            The custom Stochastics has 3min bars added.
                            Both charts get OnBarUpdate calls every 3 minutes matching the 3min bars in both.
                            8 Range chart with the custom Stochastics also get6s an OnBarUpdate call when a new 8 range bar is formed.

                            However, the custom Stochastics does nothing when called for the 8 range bar and ONLY does its work when if (BarsInProgress == 1).

                            Logically, doesn't that mean they should: 1- have the same number of computations based on the same number of 3min bars, and 2- have the same values?

                            Comment


                              #15
                              Hi TiggerTrader,

                              Both scripts may be calculating at the same time, but one will be using different data if the primary data series is different and the number of bars in the plot is different.

                              So even if they calculate at the same time, the data used is different and the end result will be different.

                              What we are talking about is the difference between the modified SMA I posted in post #2 and the modified SMA I posted in post #4.

                              The number of bars causes the calculation to be wrong, even if the secondary series is a 3 minute series.
                              Last edited by NinjaTrader_ChelseaB; 11-07-2014, 02:59 PM.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by judysamnt7, 03-13-2023, 09:11 AM
                              4 responses
                              55 views
                              0 likes
                              Last Post DynamicTest  
                              Started by ScottWalsh, Today, 06:52 PM
                              4 responses
                              35 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by olisav57, Today, 07:39 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post olisav57  
                              Started by trilliantrader, Today, 03:01 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post helpwanted  
                              Started by cre8able, Today, 07:24 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post cre8able  
                              Working...
                              X