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

Using Multi-Time frame instruments

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

    Using Multi-Time frame instruments

    Hello,
    I modified an indicator to show 10 range bars on a 12 range chart. As it prints there are blank spaces where the 10 range value of the indicator is N/A. I have read the support material on multi-time frame instruments and I have a decent understanding of why it's printing this way. Unfortunately I have a strategy that is using this 10 range indicator on a 12 range chart and the algorithm is messed up because during those N/A times the Close[0] is input instead of the actual value of that indicator on a 10 range chart. Is there a way around this?
    Thanks

    #2
    Hello CaptainAmericaXX,

    Thank you for your post.

    Please clarify: Do you have an indicator that adds a 10 range series using AddDataSeries or are you actually rendering these bars to the chart, replacing the bars of the primary series?

    It seems like you are running into invalid data points on the 10 range series. See this help guide page on IsValidDataPoint(), it is a method that returns true if a data point exists at the barsAgo parameter.

    I look forward to your reply.

    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Chris thanks for responding.
      To begin with I'm using NT7.
      Here is the code to the indicator:
      Code:
       public class A1DerivitiveOss10Range : Indicator
          {
              #region Variables
                  private int period = 14;
                  private int smooth1 = 5;
                  private int smooth2 = 3;
                  private int smooth3 = 9;
              #endregion
      
              protected override void Initialize()
              {
                  Add(PeriodType.Range, 10);
                  BarsRequired        = 20;
                  Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "DerivativeOscUp"));
                  Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "DerivativeOscDn"));
                  Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "DerivativeOsc"));
                  Add(new Line(Color.FromKnownColor(KnownColor.DarkOliveGreen), 0, "Zero"));
                  Overlay                = false;
                  PriceTypeSupported    = true;
                  PaintPriceMarkers   = true;
                  VerticalGridLines   = false;
      
                  Plots[0].Pen.Width = 2;
                  Plots[1].Pen.Width = 2;
                  Plots[2].Pen.Width = 2;            
      
                  Plots[0].PlotStyle = PlotStyle.Bar;
                  Plots[1].PlotStyle = PlotStyle.Bar;
      
                  Plots[0].Min = 0;
                  Plots[1].Max = 0;
              }
              protected override void OnBarUpdate()
              {
                  if(CurrentBar < BarsRequired || CurrentBars[1] < BarsRequired){
                      return;
                  }
                  if(BarsInProgress == 1){
                      double smooth1 = EMA(EMA(RSI(Input, Period, 1), Smooth1), Smooth2)[0];
                      double smooth2 = SMA(EMA(EMA(RSI(Input, Period, 1), Smooth1), Smooth2), Smooth3)[0];
      
                      DerivativeOsc.Set(smooth1 - smooth2);
                      DerivativeOscUp.Set(smooth1 - smooth2);
                      DerivativeOscDn.Set(smooth1 - smooth2);
                  }
              }
      When I add this indicator to a 12 range chart I do have invalid data points.
      I am also referencing this indicator in a method which also produces invalid data points.
      Is there a method in NT7 to solve this?
      Thanks

      Comment


        #4
        Hello CaptainAmericaXX,

        Thank you for your reply.

        This data sparsity always happen with different range charts. The plotting system is plotting the data values at the time of calculation. It does not seem like a 10 range series is needed anyway, since the indicators you are using use the Input series (your primary series.) changing the primary series to match whatever the secondary series is will produce a correct graph (with range charts specificaly).

        Please let me know if I can assist further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          So how can I get the proper data? I'm trying to determine if the indicator value is rising or falling.
          In my method I simply have:
          Code:
          if(der_Oss[several_Bars_Back] > der_Oss[several_Bars_Back + 1]){
                          higher_Low_DO_rising                = true;
                      }
          But during those times of data sparsity the input used by NT is Close[0] or Close[1]. That value, of course, messes everything up. Why am I getting Close and how can I get the right Input?

          Thanks.

          Comment


            #6
            Hello CaptainAmericaXX,

            Thank you for your reply.

            The data is correct, it is just that the plotting will always be synced to the primary series. To get a correct plot (with range charts especially) you would need to plot within BarsInProgress == 0 instead of BarsInProgress == 1.

            Please let me know if I can assist further.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Ok, I guess I'm not being clear on what my issue is. When I use this indicator with BarsInProgress == 1 on a 12 range chart there are invalid data points which when printed to the Output show Close[0] instead of DrivativeOsc. When I change to BarsInProgress == 0 the data is changed from a 10 range to the primary bars series of the range of the chart (in this case 12 range) and yes, all the data is THEN accurate, but that isn't what I want.
              I want to get data from a 10 range indicator while on a primary 12 range bars series and use that data in a method. When I choose BarsInProgress == 1 (10 range) almost all the data is accurate. Occasionally there are invalid data points. When I print those points, as I said before, to the Output I see that the Input used is Close[0] instead of DrivativeOsc.Set(smooth1 - smooth2). Nowhere in my method did I ask for the Close[0]! How can I get the ALL the 10 range data accurately while on a 12 range primary bars series?

              Comment


                #8
                Hello CaptainAmericaXX,

                Thanks for the reply.

                Close[0 ] is the default for a datapoint if none is found from the indicator. What is happening is that the 10 range chart has a close value but nothing exists for the 12 range chart. You would need to move your plotting to the primary series and use the values from the secondary series e.g.

                Code:
                protected override void OnBarUpdate()
                        {
                            if(CurrentBar < BarsRequired || CurrentBars[1] < BarsRequired){
                                return;
                            }
                            if(BarsInProgress == 0){
                                double smooth1 = EMA(EMA(RSI(Closes[1], Period, 1), Smooth1), Smooth2)[0];
                                double smooth2 = SMA(EMA(EMA(RSI(Closes[1], Period, 1), Smooth1), Smooth2), Smooth3)[0];
                
                                Values[0].Set(smooth1 - smooth2);
                                Values[1].Set(smooth1 - smooth2);
                                Values[2].Set(smooth1 - smooth2);
                            }
                        }
                Please let me know if I can assist further.
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  That did it! Thank you so much!
                  I was trying
                  Code:
                  [B][B]double smooth1 = EMA(EMA(RSI(Input, Period, 1), Smooth1), Smooth2)[1][0];
                  double smooth2 = SMA(EMA(EMA(RSI(Input, Period, 1), Smooth1), Smooth2), Smooth3)[1][0];[/B][/B]
                  and getting errors. Now I understand what I was doing wrong. Thanks again!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by CortexZenUSA, Today, 12:53 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by CortexZenUSA, Today, 12:46 AM
                  0 responses
                  0 views
                  0 likes
                  Last Post CortexZenUSA  
                  Started by usazencortex, Today, 12:43 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post usazencortex  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  168 responses
                  2,262 views
                  0 likes
                  Last Post sidlercom80  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  3 responses
                  10 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X