Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DataSeries in Multiple Bars Script

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

    DataSeries in Multiple Bars Script

    Hello,

    I am trying to take the SMA of the closes within a multiple bars script I'm working. I found a previous example from the forum for exactly this. So I copied this and put it in:

    #region Variables

    private DataSeries ds1;

    #endregion

    protected override void Initialize()
    {
    Add("SHY", PeriodType.Minute, 1);
    CalculateOnBarClose = false;

    ds1 = new DataSeries(this);
    }

    protected override void OnBarUpdate()
    {
    if(BarsInProgress == 0)
    {
    ds1.Set(Closes[0][0] / Closes[1][0]);
    Value.Set(SMA(ds1, 14)[0]);
    }

    { Do something.....

    )

    }

    But when I go to compile, I keep getting an error stating ds1 and Value are not in the current context. I will check tonight, but I believe it compiles as long as I don't have the Value.Set(SMA(ds1, 14)[0]); included. What am I doing wrong?

    Thanks,

    Regards,

    Lee

    #2
    Hello,

    I will be happy to take a look at this,

    In the area where you have

    { Do something.....

    )

    Is that how the script actually is or was this information you had omitted? If this is how the script actually is this would likely be a part of the problem.

    Can you attach the script for me to look at?

    I look forward to being of further assistance.

    Comment


      #3
      Hi Jesse,

      Thank you for the reply. The Do something... was just my placeholder for the actual script. I don't have the full code at this time. The full script works fine without the added dataseries. I see if I can get it tonight if possible.

      Regards,

      Lee

      Comment


        #4
        Hi Jesse,

        I was able to get it to work by removing the Value.Set and adding a variable as follows:

        #region Variables

        private DataSeries ds1;
        private double variable1;

        #endregion

        protected override void Initialize()
        {
        Add("SHY", PeriodType.Minute, 1);
        CalculateOnBarClose = false;

        ds1 = new DataSeries(this);
        }

        protected override void OnBarUpdate()
        {
        if(BarsInProgress == 0)
        {
        ds1.Set(Closes[0][0] / Closes[1][0]);
        variable1 = (SMA(ds1, 14)[0]);
        }

        { Do something.....

        )

        }


        Now I just want to add a plot of variable1 on a second panel. What would be the best way to do this?

        Thanks,

        Lee

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        569 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        548 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X