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];
    JesseNinjaTrader Customer Service

    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)​​
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you! that fixed the problem

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by nrgful, Today, 04:19 AM
          1 response
          9 views
          0 likes
          Last Post nrgful
          by nrgful
           
          Started by trdninstyle, 01-06-2025, 01:36 PM
          3 responses
          36 views
          0 likes
          Last Post trdninstyle  
          Started by Mindset, Today, 10:16 AM
          0 responses
          6 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by lois_baker, Today, 07:39 AM
          0 responses
          25 views
          0 likes
          Last Post lois_baker  
          Started by popecapllc, 08-09-2023, 07:42 PM
          13 responses
          3,978 views
          0 likes
          Last Post tradgrad  
          Working...
          X