Click or drag to resize

Secondary Timeframe & Instruments

ArthaChitra supports addition of secondary bars series in a sharpScript code (Indicators and Strategies), be it in the form of different timeframe or instrument or both. To illustrate, if the primary bars is, say a 5 Minute Bars for instrument 'A', then a secondary bars series of, say 1 minute time frame (of instrument 'A') or a 3 Minute bars series of instrument 'B' can be added.

A multi-timeframe or multi-instrument Strategy also allows to place orders accross all the secondary bars series.

How to add a secondary series

Users can add a secondary bars series by calling the AddBars method. The AddBars method can be only called when the script is in Initialze state. ArthaChitra provides multiple overloads on how the new bars will be configured. Please click here to see the available overloads.

The AddBars method has a number of overloads and presents a very flexible environment on how the secondary bars will be configured. Please find below the different parameters available.

InstrumentThe string representation of the instrument. The string should formatted as mentioned in the section 'Instrument Name format' here.
BarTypeBarType of the bars
Start DateStart date of the bars
End DateEnd date of the bars
SessionSession for the bars
Is ContinuousIf the bars series is continuous or not. Valid for futures instrument only.

If any parameter is not specifically defined then that parameter will be referenced from the primary bars series. For example if the user only defines the barType then the instrument, startDate, endDate etc will be referenced from the primary bars series.

protected override void OnStateChange()
{
    if (base.State == State.Initialize)
    {
        //add a 5 minute time frame of the primary instrument
        AddBars(new Minute(5));    

        //adds a 3 minute bars of Reliance
        AddBars("RELIANCE NSE", new Minute(3));

        //add a secondary bars of 150 Ticks
        AddBars(new Tick(150));

        //add a daily bars series
        AddBars("RELIANCE NSE", new Daily(1), DataTime.Today.AddDays(-365), DateTime.Today, new Default24X7(), false));
    }
}
How the bars data are referenced

The bars data is referenced based on the time stamp of the bar. To illustrate, say the primary bars series is a 1 Minute bars and an additional bars series of say, 5 minute bars series has been added. In such scenario, ArthaChitra will first process the 1 minute bars till a 5 minute bars forms.

Secondary series properties

SharpScript exposes a host of properties which lets users to retrieve the values of secondary bars series. Below please find the popular properties pertaining to secondary series.

BarsInProgress

BarsInProgress returns the bars index for which the OnBarUpdate method is getting processed. It is important to remember that the Time, Price & volume series properties, like Time, High or Volume etc will return the values for the bars series which is currently getting processed. The below code further illustrates it.

if (BarsInProgress == 1)
{
    //Since bars in progress is 1 Close will get the value of the secondary series close
    double currentBarsIndexClose = Close[0];
    //To get the close value of the primary series when BarsInProgress is 1 please refer to the below code
    double primaryBarsIndexClose = Closes[0][0];
}

CurrentBars

The currentBars property is an array of the available CurrentBar property. User should always check if sufficient bars are available before calling any value from any price series or otherwise.

if (CurrentBars[0][0] < 0 || CurrentBars[1][0] < 0)
    return;

Time, Price and Volume series

ArthaChitra have a host of arrays which exposes the time, price and volumes values. Some of the properties ArthaChitra exposes are Times, Opens, Highs, Lows, Closes, Medians, Typicals, Weighteds, Volumes, OpenInterests

//Gets the primary bars close
double primaryBarsIndexClose = Closes[0][0];
//gets the High of first secondary series
double secClose = Highs[1][0];

BarsArray

The BarsArray property returns an array of all available Bars.

Strategy properties

Positions

Positions property returns the positions available in the strategy.

How to reference a secondary series as Input

Secondary bars series can be used as an Input in a referenced Indicator. This is useful if user wants to calculate the values of the indicator based on a different timeframe etc.

For example, if user has a secondary bars series of say, a 1 Minute bars and want to calculate the Simple Moving Average based on that bars series then he can simply call

//calculate 14 period sma based on the first secondary series
SMA secondarySma = AddOrGetIndicator<SMA>(this, this.BarsArray[1], 14);

double smaValue = secondarySma[0, true];
Limitations

The secondary bars cannot pull data from the datafeed if insufficient data is available locally (i.e. data saved in the hard disk of your PC). In such scenario you have to first download the data using the Data Manager or open a chart (and reload the historical data) of the said instrument and then apply the multi-series sharpScript code.