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

How to add indicator to the strategy from parent timeframe

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

    How to add indicator to the strategy from parent timeframe

    Hello,

    I would like to use in a strategy some indicators, which will use current bars array and parent timeframe, for example:

    ** The strategy runs on M1 and I use:
    1/ Parabolic M1
    2/ MA 21 M1
    3/ custom akSuperTrend indicator M5

    so I need some from M1 and some from M5 (current time frame and higher)
    I am trying to do smth like this:

    Code:
    protected override void Initialize()
            {
    			initParabolic();
    			initZigZag();
    			initSuperTrend();
    			
    			switch (BarsPeriod.Id) 
    			{
    				case PeriodType.Minute:
    					Add(PeriodType.Minute, ParentTimeframe); 
    					break;
    			}		
    		}
    
    .....
    		private void initParabolic()
    		{
    			double aFMax = 0.2;
    			double step = 0.02;
    			
    			this.sar = akParabolicSar(aFMax, step);
    			Add(this.sar);
    		}
    		
    		private void initZigZag()
    		{
    			double aFMax = 0.2;
    			double step = 0.02;
    
    			this.zigzag = akParabolicZigZag(aFMax, step);
    			Add(this.zigzag);
    		}
    		
    		private void initSuperTrend()
    		{
    			int length = 14; 
             	double multiplier = 2.618; 
    			
    [B]			this.superTrend = akSuperTrend([COLOR="Red"]BarsArray[1][/COLOR], length, multiplier, false);
    [/B]			Add(this.superTrend);
    		}
    with akSuperTrend indicator, which uses different Bars object it doesn't work.
    what should I do to ?

    #2
    Hello akushyn,

    Thanks for your post.

    In the case of the added indicator using an added dataseries, it is recommended that you code a separate copy of the indicator with the 5 minute data series already added to it, Then call that copy and make sure to also add the 5 minute series to your strategy.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      Hello akushyn,

      Thanks for your post.

      In the case of the added indicator using an added dataseries, it is recommended that you code a separate copy of the indicator with the 5 minute data series already added to it, Then call that copy and make sure to also add the 5 minute series to your strategy.
      Hello and thank you very much for the quick reply!

      I didn't really get your point.
      Now it looks like picture 1 and have to be like picture 2.

      I made it manually just drag and drop the additional data series to the primary and then made transparent colors of bars of the additional data series.

      And I need the same but programmatically for the strategy.
      Thank you!
      Attached Files

      Comment


        #4
        Hello akushyn,

        Thanks for your reply.

        The issue is that you cannot add a dataseries and then an indicator to display on that added data series in the strategy.

        If you are wanting to use the indicator in the strategy as well as display the indicator via the strategy using a secondary added data series you would need to recode the indicator to run by itself on the 5 minute series. You would still need to add the 5 minute series to your strategy.

        Alternatively, you can use the indicator in the strategy directly in the OnBarUpdate() method for strategy calculations. Something like if (TSSuperTrend(BarsArray[1], .... and then for chart display, you can add the indicator to the hidden dataseries as you showed in your examples.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Paul View Post
          Hello akushyn,

          Thanks for your reply.

          The issue is that you cannot add a dataseries and then an indicator to display on that added data series in the strategy.

          If you are wanting to use the indicator in the strategy as well as display the indicator via the strategy using a secondary added data series you would need to recode the indicator to run by itself on the 5 minute series. You would still need to add the 5 minute series to your strategy.

          Alternatively, you can use the indicator in the strategy directly in the OnBarUpdate() method for strategy calculations. Something like if (TSSuperTrend(BarsArray[1], .... and then for chart display, you can add the indicator to the hidden dataseries as you showed in your examples.
          Could you please, provide some examples or links of how to recode the indicator using additional dataseries

          Comment


            #6
            I've implemented copy of SuperTrend indicator, thank you.
            Have another question:

            how to make it like green one. You see in attached screen that red line and green line is the same indicator, but red one updates every M1 and green one updates every M5 minutes.

            How to make the red equal to green line?
            Attached Files

            Comment


              #7
              Hello akushyn,

              Thanks for your reply.

              Are you sure that the red line is from the 1 minute? It looks more like what I would expect for a 5 minute indicator on a 1 minute chart.
              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by wzgy0920, Yesterday, 09:53 PM
              2 responses
              49 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              191 views
              0 likes
              Last Post Hasadafa  
              Started by GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,230 views
              0 likes
              Last Post xiinteractive  
              Started by andrewtrades, Today, 04:57 PM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by chbruno, Today, 04:10 PM
              0 responses
              7 views
              0 likes
              Last Post chbruno
              by chbruno
               
              Working...
              X