I'm a beginner when it comes to creating indicators for NT8.
Unfortunately I have the problem that in the following script
barsType == null
and therefore nothing is displayed.
I downloaded the original script from the support page.
Can anyone help me with why barsType == null and what I need to do to display the print output of the bars.
NT v8.1.3.1 64-bit
NQ 12-24 Tick900
Playback - mode
Regards Falke07
#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 BarData : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Bar Daten";
Name = "BarData";
Calculate = Calculate.OnBarClose;
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;
}
else if (State == State.Configure)
{}
}
protected override void OnBarUpdate()
{
if (Bars == null)
return;
// 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;
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = Bars.BarsSeries.BarsType as
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
if (barsType == null)
return;
try
{
double price;
Print("=========================================================================");
Print("Bar: " + CurrentBar);
Print("Trades: " + barsType.Volumes[CurrentBar].Trades);
Print("Total Volume: " + barsType.Volumes[CurrentBar].TotalVolume);
Print("Total Buying Volume: " + barsType.Volumes[CurrentBar].TotalBuyingVolume);
Print("Total Selling Volume: " + barsType.Volumes[CurrentBar].TotalSellingVolume);
Print("Delta for bar: " + barsType.Volumes[CurrentBar].BarDelta);
Print("Delta for bar (%): " + barsType.Volumes[CurrentBar].GetDeltaPercent());
Print("Delta for Close: " + barsType.Volumes[CurrentBar].GetDeltaForPrice(Close[0]));
Print("Ask for Close: " + barsType.Volumes[CurrentBar].GetAskVolumeForPrice(Close[0]));
Print("Bid for Close: " + barsType.Volumes[CurrentBar].GetBidVolumeForPrice(Close[0]));
Print("Volume for Close: " + barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close[0]));
Print("Maximum Ask: " + barsType.Volumes[CurrentBar].GetMaximumVolume(true, out price) + " at price: " + price);
Print("Maximum Bid: " + barsType.Volumes[CurrentBar].GetMaximumVolume(false, out price) + " at price: " + price);
Print("Maximum Combined: " + barsType.Volumes[CurrentBar].GetMaximumVolume(null, out price) + " at price: " + price);
Print("Maximum Positive Delta: " + barsType.Volumes[CurrentBar].GetMaximumPositiveDelta());
Print("Maximum Negative Delta: " + barsType.Volumes[CurrentBar].GetMaximumNegativeDelta());
Print("Max seen delta (bar): " + barsType.Volumes[CurrentBar].MaxSeenDelta);
Print("Min seen delta (bar): " + barsType.Volumes[CurrentBar].MinSeenDelta);
Print("Cumulative delta (bar): " + barsType.Volumes[CurrentBar].CumulativeDelta);
Print("Delta Since High (bar): " + barsType.Volumes[CurrentBar].DeltaSh);
Print("Delta Since Low (bar): " + barsType.Volumes[CurrentBar].DeltaSl);
}
catch{}
}
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private BarData[] cacheBarData;
public BarData BarData()
{
return BarData(Input);
}
public BarData BarData(ISeries<double> input)
{
if (cacheBarData != null)
for (int idx = 0; idx < cacheBarData.Length; idx++)
if (cacheBarData[idx] != null && cacheBarData[idx].EqualsInput(input))
return cacheBarData[idx];
return CacheIndicator<BarData>(new BarData(), input, ref cacheBarData);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.BarData BarData()
{
return indicator.BarData(Input);
}
public Indicators.BarData BarData(ISeries<double> input )
{
return indicator.BarData(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.BarData BarData()
{
return indicator.BarData(Input);
}
public Indicators.BarData BarData(ISeries<double> input )
{
return indicator.BarData(input);
}
}
}
#endregion
Comment