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

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.
    JesseNinjaTrader Customer Service

    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 funk10101, Today, 12:02 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by GLFX005, Today, 03:23 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by nandhumca, Yesterday, 03:41 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by The_Sec, Yesterday, 03:37 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by vecnopus, Today, 06:15 AM
        0 responses
        1 view
        0 likes
        Last Post vecnopus  
        Working...
        X