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 geddyisodin, Today, 05:20 AM
    3 responses
    20 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by lorem, Today, 09:18 AM
    1 response
    4 views
    0 likes
    Last Post lorem
    by lorem
     
    Started by bmartz, Today, 09:30 AM
    0 responses
    3 views
    0 likes
    Last Post bmartz
    by bmartz
     
    Started by GussJ, 03-04-2020, 03:11 PM
    14 responses
    3,245 views
    0 likes
    Last Post GussJ
    by GussJ
     
    Started by ArkansasClint, Today, 09:28 AM
    0 responses
    2 views
    0 likes
    Last Post ArkansasClint  
    Working...
    X