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

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
    Paul H.NinjaTrader Customer Service

    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
      Paul H.NinjaTrader Customer Service

      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:

          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by kujista, Today, 06:23 AM
          0 responses
          1 view
          0 likes
          Last Post kujista
          by kujista
           
          Started by traderqz, Yesterday, 04:32 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by f.saeidi, Today, 05:56 AM
          1 response
          5 views
          0 likes
          Last Post Jltarrau  
          Started by Jltarrau, Today, 05:57 AM
          0 responses
          5 views
          0 likes
          Last Post Jltarrau  
          Started by Stanfillirenfro, Yesterday, 09:19 AM
          7 responses
          53 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X