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

OnBarUpdate

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

    OnBarUpdate

    Hi everyone,
    This is my OnBarUpdate.I am getting the indicator output only for the last bar where as it should appear for all the bars on the chart.
    Given below is my OnBarUpdate code:

    protected override void OnBarUpdate()
    {
    this._price = (this.Open[0] + this.High[0] + this.Low[0] + this.Close[0]) / 4.0;
    if (Bars.IsFirstBarOfSession)
    {
    this._VolumeSUM[0] = this.Volume[0];

    this._VolumePriceSUM[0] = this.Volume[0] * this._price;
    this._VolumePrice2SUM[0] = this.Volume[0] * this._price * this._price;
    }
    else
    {
    this._VolumeSUM[0] = this._VolumeSUM[1] + this.Volume[0];
    this._VolumePriceSUM[0] = this._VolumePriceSUM[1] + this.Volume[0] * this._price;
    this._VolumePrice2SUM[0] = this._VolumePrice2SUM[1] + this.Volume[0] * this._price * this._price;
    }

    this.Values[0][0] = this._VolumePriceSUM[0] / this._VolumeSUM[0];

    this._deviation = Math.Sqrt(Math.Max(0, this._VolumePrice2SUM[0] / this._VolumeSUM[0] - this.Values[0][0] * this.Values[0][0]));
    if (this._std1 > 0)
    {
    this.Values[1][0] = this.Values[0][0] + this._std1 * this._deviation;
    this.Values[2][0] = this.Values[0][0] - this._std1 * this._deviation;
    }
    else
    {
    this.Values[1].Reset();
    this.Values[2].Reset();
    }
    if (this._std2 > 0)
    {
    this.Values[3][0] = this.Values[0][0] + this._std2 * this._deviation;
    this.Values[4][0] = this.Values[0][0] - this._std2 * this._deviation;
    }
    else
    {
    this.Values[3].Reset();
    this.Values[4].Reset();
    }
    }


    I am not understanding how to loop through and display output for all the visible bars,can anyone post examples to loop through all the bars

    #2
    Hello,

    You could see at the following link an example of how to loop through all bars rendered on a chart,



    The following would be an example of how to print to the output window, the close of the last 10 bars.

    Code:
    for(int x =0; x<10; x++)
    {
    Print(Close[x].ToString());
    }
    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NRITV, Today, 01:15 PM
    2 responses
    8 views
    0 likes
    Last Post NRITV
    by NRITV
     
    Started by frankthearm, Today, 09:08 AM
    7 responses
    31 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by maybeimnotrader, Yesterday, 05:46 PM
    5 responses
    26 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by quantismo, Yesterday, 05:13 PM
    2 responses
    19 views
    0 likes
    Last Post quantismo  
    Started by adeelshahzad, Today, 03:54 AM
    5 responses
    33 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X