На основе этого индюка считается дельта. В стратегии только сделки в лонг прописаны.
namespace NinjaTrader.NinjaScript.Indicators
{
public class A01 : Indicator
{
private double buys;
private double sells;
private int activeBar = 0;
double delta = 0;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionBuySellVolume;
Name = "A01";
BarsRequiredToPlot = 1;
Calculate = Calculate.OnEachTick;
DrawOnPricePanel = false;
IsOverlay = false;
DisplayInDataBox = true;
// Plots will overlap each other no matter which one of these comes first
// in NT8, we would add the Sells first in code and then Buys, and the "Sells" was always in front of the buys.
AddPlot(new Stroke(Brushes.DarkCyan, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.BuySellVolumeBuys);
AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.BuySellVolumeSells);
}
else if (State == State.Historical)
{
if (Calculate != Calculate.OnEachTick)
{
Draw.TextFixed(this, "NinjaScriptInfo", string.Format(NinjaTrader.Custom.Resource.NinjaScriptOnBarCloseError, Name), TextPosition.BottomRight);
Log(string.Format(NinjaTrader.Custom.Resource.NinjaScriptOnBarCloseError, Name), LogLevel.Error);
}
}
}
protected override void OnMarketData(MarketDataEventArgs e)
{
if(e.MarketDataType == MarketDataType.Last)
{
if(e.Price >= e.Ask)
{
buys += e.Volume;
}
else if (e.Price <= e.Bid)
{
sells += e.Volume;
}
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < activeBar || CurrentBar <= BarsRequiredToPlot)
return;
// New Bar has been formed
// - Assign last volume counted to the prior bar
// - Reset volume count for new bar
if (CurrentBar != activeBar)
{
if (delta > 0)
{
Sells[1] = 0;
Buys[1] = delta;
}
else
{
Sells[1] = delta;
Buys[1] = 0;
}
//Sells[1] = sells;
//Buys[1] = buys;
buys = 0;
sells = 0;
activeBar = CurrentBar;
}
delta = buys - sells;
if (delta > 0)
{
Sells[0] = 0;
Buys[0] = delta;
}
else
{
Sells[0] = delta;
Buys[0] = 0;
}
}