Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Print Daily SMA into 5 minutes chart

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

    Print Daily SMA into 5 minutes chart

    Hi, is it possible to plot a daily or any higher time frame into a smaller time frame within the strategy?

    I tried to plot a Daily SMA into a 5-minute chart and it doesn't work.



    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Day, 1);
    }
    else if (State == State.DataLoaded)
    {

    SMAD = SMA(Closes[1], 20);

    SMAD.Plots[0].Brush = Brushes.Yellow;
    SMAD.Plots[0].Width = 5;
    AddChartIndicator(SMAD);
    }​

    Thank you!



    #2
    Hello xtremel,

    The way you passed the secondary series to the indicator is correct, that will allow the strategy to access those values in its code. AddChartIndicator does not work with indicators that use secondary series so that part can be removed.

    To plot the indicator value the strategy would need to add a plot and then you would need to set the indicator value to the plot.

    Code:
    Value[0] = SMAD[0];

    Comment


      #3
      Hi Jesse,

      I tried the following, and don't see any errors, but I can't see the plot.

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {

      // Add plots and associated Series<double> objects
      AddPlot(Brushes.Yellow, "SMAD"); // Defines the plot for Values[0]


      }
      else if (State == State.Configure)
      {
      AddDataSeries(Data.BarsPeriodType.Day, 1);
      }
      }

      protected override void OnBarUpdate()
      {


      if (CurrentBars[0] < 72
      || CurrentBars[1] < 72)
      return;
      // Variable Higher Time Frames
      Values[0][0] = SMAD[0]; // "SMAD"
      }​
      Last edited by xtremel; 11-04-2022, 09:48 AM.

      Comment


        #4
        Hello xtremel,

        You likely don't have enough data loaded. You are checking for 72 days of data:


        if (CurrentBars[0] < 72
        || CurrentBars[1] < 72)

        Try and use:

        if (CurrentBars[1] < 1)​​

        Comment


          #5
          Thank you! that fixed the problem

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CaptainJack, 05-29-2026, 05:09 AM
          0 responses
          476 views
          0 likes
          Last Post CaptainJack  
          Started by CaptainJack, 05-29-2026, 12:02 AM
          0 responses
          317 views
          0 likes
          Last Post CaptainJack  
          Started by charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          254 views
          1 like
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          340 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          306 views
          0 likes
          Last Post CarlTrading  
          Working...
          X