Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot the SMA of 4 Week High/Low on 60 Mins Time Frame

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

    Plot the SMA of 4 Week High/Low on 60 Mins Time Frame

    Hello,

    I would like to plot the sma of 4 week high/low on the 60 mins time frame but no luck. please help to advise the solution.

    Code:
    else if (State == State.Configure)
    {
    	AddDataSeries(BarsPeriodType.Week, 1);
    }
    else if (State == State.DataLoaded)
    {
    	smaHigh = SMA(BarsArray[1], 4);
    	smaLow = SMA(BarsArray[1], 4);
    	
    	smaHigh.Plots[0].Brush = Brushes.Blue;
    	smaLow.Plots[0].Brush = Brushes.Red;
    	
    	AddChartIndicator(smaHigh);
    	AddChartIndicator(smaLow);
    }

    #2
    Hello matrixxx,

    Thanks for your post and welcome to the forums!

    Are the plots not showing or incorrect? Do you see just one but not the other?

    Do you see any error messages listed in the "Log" tab of the control center when you run the strategy?

    If you add print statements in your code, do you see expected values for smaHigh, smaLow?

    How many days of data are loaded on the 60-minute series? Using a weekly series would require a large number of days loaded in the charts primary series.

    It appears that you are assigning the same (Close) data to smaHigh and smaLow. If you want the High and Low values try: smaHigh = SMA(Highs[1], 4); smaLow = SMA(Lows[1], 4);

    edit: corrected smaLow assignment

    Comment


      #3
      Hello matrixxx,

      Taking a further look, besides the references to the BarsArray and the possibly the length of data would be the use of AddChartIndicator() which only allows you to plot the indicator to the primary (chart) series. The applicable note is, "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." Reference link: https://ninjatrader.com/support/help...tindicator.htm

      To have your strategy plot the 4-period SMA of the high and low data series from the added weekly series, you can add plots to the strategy and then set the plots to the values of the Highs[1] and Lows[1] when the strategy's barsInprogress is 0 (chart bars).

      Please see the attached for an example of the code and an example of the output.
      Attached Files

      Comment


        #4
        Hi Paul,

        It's work but i don't understand about the Values[0] and Values[1] that return by function SmaH and SmaL. i cannot found this logic from the ninjatrader help guide.

        Thank you for your support.

        Comment


          #5
          Hello matrixxx,

          Values[n] are added automatically when you use AddPlot(). Here is a link to the helpguide sections:

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          24 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          120 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          63 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          45 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X