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 NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          72 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          143 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          76 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          47 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          51 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X