• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Secondary time series for custom indicator

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

    Secondary time series for custom indicator

    Hello everyone,

    I have a custom indicator that is very similar to keltner channels. I want to add a secondary series to this indicator such that I can overlay it onto a lower timeframe chart, specifically the indicator will calculate based upon a 4hr timeframe and be visible on a 15 minute bar chart. The channels, which should only calculate once every four hours, will look like a horizontal line above or below the 15min price action until the next calculation, and look like a stepwise line if one is to zoom out.

    Anyway, I am sorry that I even have to post about this here because I know similar threads have been opened in the past. I have read all of them, and while I think it has gotten me on the right track, I still haven't been able to produce the desired result.

    The "SampleSecondarySeriesAsInputSeries" reference sample is what I have based my code on. So per the reference sample, I have added the secondary timeframe, and then in the variables, I specified the BarsArray that the two EMA's should calculate on, like so...

    Code:
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Minute, 240);
                }
                else if (State == State.DataLoaded)
                {
                    EMADiff               = EMA(ATR(BarsArray[1],(1)), ATRPeriod);
                    EMAClose              = EMA(BarsArray[1], Period);
                }
    Then I wrapped the indicator logic in BarsInProgress == 1 { //logic; }

    What else do I need to do? Am I taking the wrong approach based upon the desired results I described in the first paragraph of this post? When I add the indicator to a 15 minute bar chart nothing shows up.

    Thank you for reading, hope someone can offer some insight!

    #2
    Hello lunardiplomacy,

    Thanks for your post.

    If i understand correctly, you are calculating on a different time frame from the primary series (chart bars) and you want to display on the chart bars a plot from the secondary series calculations. You would need to assign the calculated values to the Plot which would need to be done under BarsInprogress 0.
    For example:

    if (BarsInProgress == 0)
    {
    yourplot[0] = EMADiff[0]; // pull the current value of theEMA of the ATR on the 4 hrs series and plot on the chart. this will update the chart on every bar.
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul!

      Thank you for getting back to me in a timely manner. I think your understanding of what I am trying to do is correct. Assume it is an EMA, for example, I would just want the 4hr EMA of some period to be visible on a lower timeframe. But, of course, in the stepwise fashion that I described above, where the EMA is represented on the LTF chart as a flat line until it is time to calculate again, at which point the new flat line would have a (potentially) different value.

      Anyway, you are telling me that I need to calculate my logic in OnBarUpdate under the BarsInProgress that matches the primary series? Which in this case would be BarsInProgress == 0, and in the example you gave, you reference the value using "EMADiff[0]", but wouldn't that reference the primary series because you are using [0]? Or is it already established that the value is from the secondary series because of what I did to it in state == state.configure using BarsArray?

      Please clarify if that is what you mean, and please let me know if there is anything further I would need to add to get the plot to be flat at the value and change every four hours. In the meantime I will try running it on the BarsInProgress that you suggested and let you know what I come up with.

      Thanks, Paul!

      Comment


        #4
        Hello lunardiplomacy,

        Thanks for your reply and confirmation.

        Let me change my example to using just the EMAClose as this is what you would actually plot on the price chart. The EMA(ATR... would be a small value that would not be able to be plotted on the price panel (or if it was it would severely distort the chart).

        if (BarsInProgress == 0)
        {
        yourplot[0] = EMAClose[0]; // pull the current value of the EMA of 4 hrs series and plot on the chart. this will update the chart on every chart bar.
        }


        The above is performed in BarsInProgress 0 because that is what the chart bars use. You want your plots to always be updated when the chart bars update. In state data loaded you have already assigned the EMA to the added dataseries 240 minutes so in the above statement, each time the chart bars update it will pull the current bar [0] value of the EMA of the 240 minute series.

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi again Paul,

          Sorry, I should have been more descriptive than "it's like a keltner channel". The EMA of the ATR is multiplied by an offset value which is added to the standard EMA.

          But anyway, I figured out how to do it and it looks fantastic. I initialized the variables in state.configure, and then calculated the EMA and EMA + Offset * emaATR in BarsInProgress == 1 and then in BarsInProgress == 0 I used IsValidDataPoint to set EMA[0] = EMA[1] and viola.

          Thanks, Paul.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by KINGKODA, Today, 12:08 PM
          0 responses
          2 views
          0 likes
          Last Post KINGKODA  
          Started by [email protected], Today, 10:54 AM
          2 responses
          14 views
          0 likes
          Last Post sabankaradeniz@gmail.com  
          Started by wbennettjr, Today, 11:18 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by Induna, Today, 05:38 AM
          2 responses
          6 views
          0 likes
          Last Post Induna
          by Induna
           
          Started by Alfred, Today, 10:20 AM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_PatrickG  
          Working...
          X