I am trying to build an OnMarketData indicator, which is supposed to show changes in the current bid ask depth.
I am getting sort of unexpected bevaviour which you can see in the print statement of the indicator.
According to my understanding the result of
InsideAuction[e.Price].deltaBid += e.Volume - InsideAuction[e.Price].depthBid;
should be a summation of the difference between the last and current offered depth, what I instead get is e.Volume;
The line
InsideAuction[e.Price].bidChange = e.Volume - InsideAuction[e.Price].depthBid;
returns the desired result. (What should be accumulated above).
Whats the reason for this?
attached code
regards and thanks
#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 TestOnMarketData : Indicator
{
internal class insideItem
{
public double depthBid;
public double deltaBid;
public double bidChange;
}
private SortedList <double, insideItem> InsideAuction =
new SortedList <double, insideItem>();
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "TestOnMarketData";
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 = false;
}
else if (State == State.Configure)
{
}
}
protected override void OnMarketData(MarketDataEventArgs e)
{
if (e.MarketDataType == MarketDataType.Bid)
{
if (!InsideAuction.ContainsKey(e.Price))
InsideAuction.Add(e.Price, new insideItem());
InsideAuction[e.Price].bidChange = e.Volume - InsideAuction[e.Price].depthBid;
InsideAuction[e.Price].deltaBid += e.Volume - InsideAuction[e.Price].depthBid;
Print("Price " + e.Price + " Depth " + InsideAuction[e.Price].depthBid + " Volume " + e.Volume + " Delta " + InsideAuction[e.Price].deltaBid + " BidChange " + InsideAuction[e.Price].bidChange);
InsideAuction[e.Price].depthBid = e.Volume;
}
}
}
}
Comment