#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class MarketDepthTest : Indicator
{
private double AskPrice1;
private double AskVolume1;
private double BidPrice1;
private double BidVolume1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "MarketDepthTest";
Calculate = Calculate.OnEachTick;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if(CurrentBar < 1)
return;
ClearOutputWindow();
Print("Ask Book");
Print("Ask Price=" + AskPrice1 + " Volume=" + AskVolume1);
Print("Bid Book");
Print("Bid Price=" + BidPrice1 + " Volume=" + BidVolume1);
}
protected override void OnMarketDepth(MarketDepthEventArgs marketDepthUpdate)
{
if(marketDepthUpdate.MarketDataType == MarketDataType.Ask)
{
AskPrice1 = marketDepthUpdate.Price;
AskVolume1 = marketDepthUpdate.Volume;
}
else if(marketDepthUpdate.MarketDataType == MarketDataType.Bid)
{
BidPrice1 = marketDepthUpdate.Price;
BidVolume1 = marketDepthUpdate.Volume;
}
}
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private MarketDepthTest[] cacheMarketDepthTest;
public MarketDepthTest MarketDepthTest()
{
return MarketDepthTest(Input);
}
public MarketDepthTest MarketDepthTest(ISeries<double> input)
{
if (cacheMarketDepthTest != null)
for (int idx = 0; idx < cacheMarketDepthTest.Length; idx++)
if (cacheMarketDepthTest[idx] != null && cacheMarketDepthTest[idx].EqualsInput(input))
return cacheMarketDepthTest[idx];
return CacheIndicator<MarketDepthTest>(new MarketDepthTest(), input, ref cacheMarketDepthTest);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.MarketDepthTest MarketDepthTest()
{
return indicator.MarketDepthTest(Input);
}
public Indicators.MarketDepthTest MarketDepthTest(ISeries<double> input )
{
return indicator.MarketDepthTest(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.MarketDepthTest MarketDepthTest()
{
return indicator.MarketDepthTest(Input);
}
public Indicators.MarketDepthTest MarketDepthTest(ISeries<double> input )
{
return indicator.MarketDepthTest(input);
}
}
}
#endregion
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Level II Values
Collapse
X
-
Level II Values
I am looking to grab the Level II data to use in an indicator I am creating. Specifically, I am looking to grab the 5 Ask order rows above the last price and the volume at each price. Same with the Bid side. Below is the simple code I put together to grab the first Bid & Ask row ( I believe...). Now how do I grab the subsequent rows? Do I need to do something like marketDepthUpdate.Volume[1], marketDepthUpdate.Volume[2]...or something similar? There is very limited info on the ninjascript guide for MarketDepthEventArgs. Thanks
HTML Code:Tags: None
-
Hello algospoke,
The level 2 data that is being observed by the platform is simply the level 2 events, there is no order book to where you could access prices or volumes at certain levels. To do that you would have to use your own logic which builds the orderbook based on those events. There is a sample in the link below that covers how to do that and access the values.
-
Jesse,
Thanks for directing me to the sample. When I change the list length from 10 to 25 in the sample code, it still only prints 10 lines for Bid & Ask (circled in red below). Why is that? When I enable the Order Flow Market Depth Map, it shows the orders sitting at all tick levels (circled in blue below). My goal is to grab that info to use for analysis in my indicator. It seems I am limited to 10 ticks of data whereas the Order Flow Market Depth Map can show way more than that. Why the difference?
Thanks
Comment
-
Jesse,
Interesting. I am not looking to understand how it is calculated (I understand it is proprietary), I am just looking to grab the info that is displayed on the chart by Market Depth Map indicator and use it for analysis. Is there a way to grab those values without needing access to the source code?
Thanks
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
563 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
329 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
547 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
548 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment