This one gets every price update on level 1 (MarketDataType.Last is trade). An event driven method which is called and guaranteed to be in the correct sequence for every change in level one market data for the underlying instrument. OnMarketData() can include but is not limited to the bid, ask, last price and volume.
protected override void
OnMarketData (MarketDataEventArgsmarketDataUpdate)
{
// Print some data to the Output window
if(marketDataUpdate.MarketDataType==MarketDataType.Last)
Print(string.Format("Last = {0} {1} ",marketDataUpdate.Price,marketDataUpdate.Volume));
elseif(marketDataUpdate.MarketDataType==MarketDataType.Ask)
Print(string.Format("Ask = {0} {1} ",marketDataUpdate.Price,marketDataUpdate.Volume));
elseif(marketDataUpdate.MarketDataType==MarketDataType.Bid)
Print(string.Format("Bid = {0} {1}",marketDataUpdate.Price,marketDataUpdate.Volume));
}
This one gets every price update on all level 2s that are available. An event driven method which is called and guaranteed to be in the correct sequence for every change in level two market data (market depth) for the underlying instrument. The OnMarketDepth() method can be used to build your own level two book.
protected override void
OnMarketDepth (MarketDepthEventArgsmarketDepthUpdate)
{
// Print some data to the Output window
if(marketDepthUpdate.MarketDataType==MarketDataType.Ask&&marketDepthUpdate.Operation==Operation.Update)
Print(string.Format("The most recent ask change is {0} {1}",marketDepthUpdate.Price,marketDepthUpdate.Volume));
}
This one just triggered for every bar update aka trade, basically each incoming tick similar to OnMarketData, but you can slow it down to only calculate on bar close for example, it is a setting. An event driven method which is called whenever a bar is updated. The frequency in which OnBarUpdate is called will be determined by the "
Calculate" property. OnBarUpdate() is the method where all of your script's core bar based calculation logic should be contained.
protected override void
OnBarUpdate()
{
if(CurrentBar<1)
return;
// Compares the primary bar's low price to the 5-minute bar's low price
if(Low[0]>Lows[1])
Print("The current bar's low price is greater");
}
Essentially you open particular instrument chart, and set it to monthly bars for example, and load you script, it will run continuously on each incoming tick or level 2 change.