But my data feed is providing bid and ask so want to assign directly bid to bid volume and ask to ask volume.
How can I do that ?
namespace NinjaTrader.NinjaScript.Indicators.Infinity
{
public class MyCustomIndicator : Indicator
{
private double buys;
private double sells;
private int activeBar = 0;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionBuySellVolume;
Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meBuySellVolume;
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.NinjaScr iptOnBarCloseError, Name), TextPosition.BottomRight);
Log(string.Format(NinjaTrader.Custom.Resource.Ninj aScriptOnBarCloseError, Name), LogLevel.Error);
}
}
}
protected override void OnMarketData(MarketDataEventArgs e)
{
if(e.MarketDataType == MarketDataType.Last)
{
buys += e.Bid;
sells += e.Ask;
}
}
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
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)
{
Sells[1] = sells;
Buys[1] = buys;
//buys = 0;
//sells = 0;
activeBar = CurrentBar;
}
Sells[0] = sells;
Buys[0] = buys;
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> Sells
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> Buys
{
get { return Values[0]; }
}
#endregion
}
}
so i did change in Onmarkerdata and assigned Bid to buys ( buys =+ e.Bid) and ask to sell ( sells = + e.Ask) but it is not giving right result...attaching an image of how it is plotting output..
Comment