OnMarketDepth()
Previous Topic  Next Topic 

Definition
The OnMarketDepth() method is called for every change in level two market data (market depth) for the underlying instrument. This method can be used to build your own level two book.



Method Return Value

This method does not return a value.


Method Parameters

MarketDepthEventArgs e


Syntax
You must override the method in your strategy or indicator with the following syntax.


protected override void OnMarketDepth(MarketDepthEventArgs e)
{


}


Method Of

Custom Indicator, Custom Strategy

Examples

protected override void OnMarketDepth(MarketDepthEventArgs e)
{
    // Print some data to the Output window
    if (e.MarketDataType == MarketDataType.Ask && e.Operation == Operation.Update)
        Print("The most recent ask change is " + e.Price + " " + e.Volume);
}



Additional Reference Samples
Additional reference code samples are available the NinjaScript Educational Resources section of our support forum.

Tips
1. With multi-time frame and instrument strategies, OnMarketDepth will be called for all unique instruments in your strategy. Use the BarsInProgress to filter the OnMarketDepth() method for a specific instrument.
2. Do not leave an unused OnMarketDepth() method declared in your NinjaScript object. This will unnecessarily attached a data stream to your strategy which uses unnecessary CPU cycles.