protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "VolumetricTest"; Calculate = Calculate.OnEachTick; IsOverlay = false; 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; AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.BuySellPressureBuyPressure); AddPlot(Brushes.Crimson, NinjaTrader.Custom.Resource.BuySellPressureSellPressure); AddLine(Brushes.DimGray, 75, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUpper); AddLine(Brushes.DimGray, 25, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLower); } else if (State == State.DataLoaded) { barsType = ChartBars.Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType; } }
protected override void OnBarUpdate() { if (Bars == null) { return; } if (CurrentBar < 10) { return; } lastBar = CurrentBar - 1; // This sample assumes the Volumetric series is the primary DataSeries on the chart, if you would want to add a Volumetric series to a // script, you could call AddVolumetric() in State.Configure and then for example use // NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = BarsArray[1].BarsType as // NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType; barsType = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType; if (barsType == null) { return; } Print("\n========================================================================="); Print("Bar: " + CurrentBar); SetUpPriceBar(); try { double price; /// need to see imabalance /// loop thru ask with the index of bid -1 and do math BarList.Clear(); int index2 = 1; for (int index = 0; index <= priceList.Count; index++) { /// eval bid = shift ask up, means increace bid index by 1 double bidVol = barsType.Volumes[CurrentBar].GetBidVolumeForPrice(priceList[index + 1]); double askVol = barsType.Volumes[CurrentBar].GetAskVolumeForPrice(priceList[index]); if (index <= priceList.Count - 1) { Print(index + " Seeking bid imbal " + bidVol + " to ask vol " + askVol); if ((bidVol / 2) > askVol) { BarData barData = new BarData(); barData.Price = priceList[index + 1]; barData.BidImbalance = true; barData.Barnum = CurrentBar; BarList.Add(barData); Print("\tbid " + bidVol + " has ask imbalance of " + askVol.ToString() + " red color"); //Draw.Dot(this, "resistance"+CurrentBar+index, false, 0, priceList[index+1], Brushes.Red); } } if (index2 <= priceList.Count - 1) { /// eval ask = shift ask down, means decrease ask index by 1 bidVol = barsType.Volumes[CurrentBar].GetBidVolumeForPrice(priceList[index2]); askVol = barsType.Volumes[CurrentBar].GetAskVolumeForPrice(priceList[index2 - 1]); Print(index2 + " seeking ASK imbal " + askVol + " to bid vol " + bidVol); if ((askVol / 2) > bidVol) { BarData barData2 = new BarData(); barData2.Price = priceList[index2 - 1]; barData2.Barnum = CurrentBar; barData2.AskImbalance = true; BarList.Add(barData2); Print("\task " + askVol + " has ask imbalance of " + bidVol.ToString() + " blue color"); //Draw.Dot(this, "support"+CurrentBar+index, false, -1, priceList[index2-1], Brushes.DodgerBlue); } index2 += 1; } } } catch {} RemoveDuplicates(); FindConsecutiveZones(); //Draw.Text(this, "CurrentBar"+CurrentBar, CurrentBar.ToString(), 0, High[0] + 2 * TickSize, Brushes.AntiqueWhite); /// prove the list Print("Bar: " + CurrentBar); Print("----------------------------------"); double lastPrice = 0.0; for (int i = 0; i < BarList.Count; i++) { Print(BarList[i].Price.ToString("N2") + " \t\t" + BarList[i].BidImbalance + " \t\t" + BarList[i].AskImbalance); } /// remove old ask imbalances for (int index = 0; index < ImbalanceList.Count; index++) { if (High[0] > ImbalanceList[index].Price + 0.5 && ImbalanceList[index].AskImbalance) { Print("--> \tRemoved Price " + ImbalanceList[index].Price); ImbalanceList.RemoveAt(index); } else if (Low[0] < ImbalanceList[index].Price - 0.5 && ImbalanceList[index].BidImbalance) { Print("--> \tRemoved Price " + ImbalanceList[index].Price); ImbalanceList.RemoveAt(index); } } /// show ask imbalances foreach (Imbalances row in ImbalanceList) { if (row.AskImbalance) { string name = "resistLine" + row.Price + row.Barnum; RemoveDrawObject(name + lastBar); int lineLength = CurrentBar - row.Barnum; Draw.Rectangle(this, name + CurrentBar, false, lineLength, row.Price, 1, row.Price + TickSize, Brushes.Transparent, Brushes.Red, 20); } if (row.BidImbalance) { string name = "supportLine" + row.Price + row.Barnum; RemoveDrawObject(name + lastBar); int lineLength = CurrentBar - row.Barnum; Draw.Rectangle(this, name + CurrentBar, false, lineLength, row.Price, 1, row.Price + TickSize, Brushes.Transparent, Brushes.DodgerBlue, 20); } } }