NinjaScript > Language Reference > Strategy >

BarsSinceExit()

Print this Topic Previous pageReturn to chapter overviewNext page

Definition
Returns the number of bars that have elapsed since the last specified exit.
 

Method Return Value

An int value that represents a number of bars. A value of -1 will be returned if a previous exit does not exist.

 

Syntax
BarsSinceExit()
BarsSinceExit(string signalName)

 

The following method signature should be used when working with multi-time frame and instrument strategies:

 
BarsSinceExit(int barsInProgressIndex, string signalName, int exitsAgo)
 

Note: When working with a multi-series strategy the BarsSinceExit() will return you the elapsed bars as determined by the first Bars object for the instrument specified in the barsInProgressIndex.

 

Parameters

signalName

The signal name of an entry order specified in an order entry method. Pass in empty string "" for default signal.

barsInProgressIndex

The index of the Bars object the entry order was submitted against. See the BarsInProgress property.

exitsAgo

Number of exits ago. Pass in 0 for the number of bars since the last exit.

 

 
Examples

protected override void OnBarUpdate()
{
    if (CurrentBar < 20)
        return;
 
    // Only enter if at least 10 bars has passed since our last exit or if we have never traded yet
    if ((BarsSinceExit() > 10 || BarsSinceExit() == -1) && CrossAbove(SMA(10), SMA(20), 1))
         EnterLong();
}