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 DavidHP, Today, 07:56 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by kujista, Today, 06:23 AM
    3 responses
    6 views
    0 likes
    Last Post kujista
    by kujista
     
    Started by Mindset, Yesterday, 02:04 AM
    2 responses
    18 views
    0 likes
    Last Post NinjaTrader_RyanS  
    Started by f.saeidi, Today, 08:03 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by samish18, 04-17-2024, 08:57 AM
    15 responses
    53 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X