GetBar()
Previous Topic  Next Topic 

Definition
Returns the number of bars ago starting with the 1st bar from oldest to newest that matches the time stamp based on the DateTime parameter passed in. If the time stamp passed in is older than the 1st bar, the value returned reflects the number of bars ago for the 1st bar of the series. If  the time stamp is newer than the last bar, a value of zero is returned.

Method Return Value

An int value that represents the number of bars ago.


Syntax
GetBar(DateTime time)

GetBar(int barSeriesIndex, DateTime time)

Method Of

Custom Indicator, Custom Strategy


Parameters

time

An instance of time.

barSeriesIndex

Index value of bars object in a multiseries strategy


Examples

// Check that its past 9:45 AM
if (ToTime(Time[0]) >= ToTime(9, 45, 00))
{
    // Calculate the bars ago value for the 9 AM bar for the current day
    int barsAgo = GetBar(new DateTime(2006, 12, 18, 9, 0, 0));

    // Print out the 9 AM bar closing price
    Print("The close price on the 9 AM bar was: " + Close[barsAgo].ToString());
}