• 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

AddChartIndicator() add the indicator of the higher timeframe

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

    AddChartIndicator() add the indicator of the higher timeframe

    Hello friends.
    I'm trying to add the indicator of the higher timeframe (m60) to the current schedule (m5) of the strategy with this code:

    Code:
    else if (State == State.Configure)
    {       
    AddDataSeries(Data.BarsPeriodType.Minute, 60);
    }
    …
    else if (State == State.DataLoaded)
    {
           AddChartIndicator(SMA(BarsArray[1], 14)); 
    }

    But the graph is not displayed. Help me achieve this display.
    Thank you.

    #2
    Hello Kostiantyn,

    Thanks for your post and welcome to the NinjaTrader forums!

    With reference to the helpguide on AddChartIndicator(): An indicator being added via AddChartIndicator() cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code. Link: http://ninjatrader.com/support/helpG...tindicator.htm

    The AddChartIndicator() method is used to show an indicator on the chart. As the SMA is based on an added dataseries to the strategy, per the helpguide notes this will not work. Note that this does not impact the strategies ability to reference the added dataseries for your strategies calculations, this only impacts the charted display.

    There are two alternatives:
    1) Per the note above, recode a copy of the SMA to add the 60 Minute dataseries and then use that copy in the strategy
    2) Add a hidden 60 minute data series to the chart and then add an SMA to the chart based on the hidden data series.

    To add a hidden dataseries to the chart:
    1) Right mouse click on the chart and select "Data Series...".
    2) In the dataseries window add the 60 minute time frame
    3) In the properties of the 60 minute time frame:
    a) Set the type to minute and the value to 60
    b) Set the days to load to match the chart
    c) Change the chart style to "Line on Close"
    d) Set the chart style color to "Transparent"
    e) Set the panel to be the same as the main chart (Panel 1 typically)
    f) Turn off "text and Markers"
    g) click OK
    This will add the dataseries to the chart but you will not see the 60 minute candles. Next add an SMA to the chart and in the SMA indicator properties, edit the "input series" and select the 60 minute "close" as the SMA's input series. Now you will have a 60 minute SMA on your base chart.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick response. But I do not understand how to implement in the code: "1) Per the note above, recode a copy of the SMA to add the 60 Minute dataseries and then use that copy in the strategy". May I ask you to give me an example of the code. Thank you.

      Comment


        #4
        Hello Kostiantyn,

        Thanks for your reply.

        In the support department at NinjaTrader we do not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients.

        You would make a copy of the SMA indicator and just like in the strategy add the 60 minute data series. Change the references in the indicator to point to the added dataseries. Adding the dataseries would then change the indicator to a multi time frame indicator and you would need to change the bar references according to: http://ninjatrader.com/support/helpG...nstruments.htm

        This would be more difficult than the alternative approach provided in my initial response for the purposes of displaying the indicator.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thank you. I will follow your recommendations.

          Comment


            #6
            Originally posted by NinjaTrader_Paul View Post
            Hello Kostiantyn,

            Thanks for your reply.

            In the support department at NinjaTrader we do not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients.

            You would make a copy of the SMA indicator and just like in the strategy add the 60 minute data series. Change the references in the indicator to point to the added dataseries. Adding the dataseries would then change the indicator to a multi time frame indicator and you would need to change the bar references according to: http://ninjatrader.com/support/helpG...nstruments.htm

            This would be more difficult than the alternative approach provided in my initial response for the purposes of displaying the indicator.
            Originally posted by Kostiantyn View Post
            Thanks for the quick response. But I do not understand how to implement in the code: "1) Per the note above, recode a copy of the SMA to add the 60 Minute dataseries and then use that copy in the strategy". May I ask you to give me an example of the code. Thank you.
            Hello, Paul
            Its a very simple question and to unswer you don't need to programming or debuggin the code. I don't really understand why you can't advise Kostyantin with this issue.....

            Kostyantin, You don't need to have a copy of M60 of SMA, what you need is to add a dataseries and then use it as you wish:
            http://ninjatrader.com/support/helpG...e.htm?add3.htm

            Code:
            Add(PeriodType.Minute, SeniorTimeframePeriod);
            where SeniorTimeframePeriodis = 60 in your example. And user can define it in property.

            For example, I am using more complex approach. As you see, you can define period for different PeriodType.

            Code:
            		public int SeniorTimeframePeriodis
            		{
            			get 
            			{
            				// коефіцієнт кратності
            				int multiplicity = 5;
            
            				switch (BarsPeriod.Id) {
            					case PeriodType.Minute:
            					{
            						return BarsPeriod.Value * multiplicity;
            					}
            					break;
            
            					case PeriodType.Second:
            						switch (BarsPeriod.Value) {
            							case 12:
            								return 1;
            								break;
            						}
            						break;
            				}
            				return 0;
            			}
            		}
            Then, when you have additional dataseries, you can use it in a indicator/strategy like this:

            Code:
            this.ema233 = EMA(BarsArray[1], emaPeriod)[0];
            More details about BarsArray: http://ninjatrader.com/support/helpG...?barsarray.htm

            Comment


              #7
              Hello akushyn,

              Thanks for your post.

              Please note that this is NinjaTrader8 and you are answering based on NinjaTrader7. The original query was how to add an indicator for the purposes of display through the strategy with a different time frame, not on how to use in the strategy for calculation purposes.

              Your EMA example is correct for using in the strategy with the higher time frame for the purposes of calculation.
              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by frankduc, Today, 09:00 AM
              0 responses
              1 view
              0 likes
              Last Post frankduc  
              Started by Kabua, Yesterday, 11:24 PM
              1 response
              6 views
              0 likes
              Last Post koganam
              by koganam
               
              Started by KandI, Today, 08:03 AM
              2 responses
              7 views
              0 likes
              Last Post KandI
              by KandI
               
              Started by kujista, Yesterday, 10:33 PM
              5 responses
              14 views
              0 likes
              Last Post NinjaTrader_ChrisL  
              Started by tonynt, Today, 07:27 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Working...
              X