Tyche Trading

Bar Count/Bars Ago

Bar Info

Debugging

Derivatives

Matrix Handling

Price Rounding

Regression Lines

Statistics

User Tracking

Example Strategies

Bar Count / Bars Ago

Description:

This code will draw the CurrentBar number above each individual bar, and the BarsAgo number bellow each individual bar.

 

Use Case:

  • When NinjaTrader tells you there is an error on bar X you can use this to determine exactly where the error occured.
  • When you want to know exactly how many bars ago you want to draw something, or execute something, this can be used to check the bars.
				
					public TotalBarsCheck = true;
public BarsAgoCheck = true;

protected override void OnBarUpdate()
{
	if (TotalBarsCheck)
		TotalBars();

	if (BarsAgoCheck)
		BarsAgo();
}

private void TotalBars()
{
	Draw.Text(this, "Total Bars " + CurrentBar, CurrentBar.ToString(), 0, High[0] + 1 * TickSize, TBBrush);
}

private void BarsAgo()
{
    // The zeroith bar is the last completed bar when calculating on bar OnBarClose
    // The zeroith bar is the current developing bar otherwise
	if (Calculate == Calculate.OnBarClose)
		Draw.Text(this, "Bars Ago " + CurrentBar, (Count - CurrentBar - 2).ToString(), 0, Low[0] - 1 * TickSize, BABrush);
	else if (Calculate == Calculate.OnEachTick || Calculate == Calculate.OnPriceChange)
		Draw.Text(this, "Bars Ago " + CurrentBar, (Count - CurrentBar - 1).ToString(), 0, Low[0] - 1 * TickSize, BABrush);
}