Trading Instrument Data
FinInfo - current quotes on paper
The ISecurity.FinInfo property provides current data on paper. For example, you can see the current bid / ask prices, open price, open interest, expiration date, if any, warranty and more.
The full list can be found here.
An example of a script that logs the current bid and ask prices at each recount:
using TSLab.Script;
using TSLab.Script.Handlers;
namespace MyLib
{
public class GetFinInfo : IExternalScript
{
public void Execute(IContext ctx, ISecurity sec)
{
var fi = sec.FinInfo;
var txt = string.Format("{0}: {1} ({2}) - {3} ({4})", fi.LastUpdate, fi.Bid, fi.BuySqty, fi.Ask, fi.SellSqty);
ctx.Log(txt);
}
}
}

Bars - candle list
The ISecurity.Bars property provides a list of candles. This list consists of IDataBar objects that contain time, price, volume, open interest.
A detailed description of the source text files can be found here.
An example script that calculates and displays the median price in bars on a chart:
using System.Linq;
using TSLab.Script;
using TSLab.Script.Handlers;
namespace MyLib
{
public class GetMedian : IExternalScript
{
public void Execute(IContext ctx, ISecurity sec)
{
var prices = sec.Bars.Select(x => (x.High + x.Low) / 2).ToList();
ctx.First.AddList("Median", prices, ListStyles.LINE, ScriptColors.Magenta, LineStyles.SOLID, PaneSides.RIGHT);
}
}
}

Price list
For convenience, the ISecurity interface provides various price lists:
OpenPrices
List of open prices
ClosePrices
List of close prices
HighPrices
List of highs
LowPrices
List of minimums
Volumes
List of volumes
An example of a script that displays the maximum and minimum prices on a chart:
using TSLab.Script;
using TSLab.Script.Handlers;
namespace MyLib
{
public class GetPrices : IExternalScript
{
public void Execute(IContext ctx, ISecurity sec)
{
ctx.First.AddList("HighPrices", sec.HighPrices, ListStyles.LINE, ScriptColors.Green, LineStyles.DOT, PaneSides.RIGHT);
ctx.First.AddList("LowPrices", sec.LowPrices, ListStyles.LINE, ScriptColors.Red, LineStyles.DOT, PaneSides.RIGHT);
}
}
}

Last updated
Was this helpful?