#region Using declarations using NinjaTrader.Gui; using System.Windows.Media; #endregion namespace NinjaTrader.NinjaScript.Indicators { public class PutCallRatio : Indicator { private const int PrimaryBars = 0; private const int PutVolumeBars = 1; private const int CallColumeBars = 2; protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "Put / Call Ratio"; Description = @"Total Put Options Volume / Total Call Options Volume"; Calculate = Calculate.OnPriceChange; IsOverlay = false; AddPlot(new Stroke(Brushes.Yellow, DashStyleHelper.Solid, 3), PlotStyle.Line, "Put / Call Ratio"); } else if (State == State.Configure) { AddDataSeries("VPOT"); AddDataSeries("VCOT"); } } protected override void OnBarUpdate() { if (PrimaryBars != BarsInProgress) return; if (CurrentBars[PutVolumeBars] < 1 || CurrentBars[CallColumeBars] < 1) return; double putVolume = BarsArray[PutVolumeBars].GetClose(BarsArray[PutVolumeBars].GetBar(Time[0])); double callVolume = BarsArray[CallColumeBars].GetClose(BarsArray[CallColumeBars].GetBar(Time[0])); Value[0] = putVolume / callVolume; } public override string DisplayName { get { return Name; } } } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private PutCallRatio[] cachePutCallRatio; public PutCallRatio PutCallRatio() { return PutCallRatio(Input); } public PutCallRatio PutCallRatio(ISeries input) { if (cachePutCallRatio != null) for (int idx = 0; idx < cachePutCallRatio.Length; idx++) if (cachePutCallRatio[idx] != null && cachePutCallRatio[idx].EqualsInput(input)) return cachePutCallRatio[idx]; return CacheIndicator(new PutCallRatio(), input, ref cachePutCallRatio); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.PutCallRatio PutCallRatio() { return indicator.PutCallRatio(Input); } public Indicators.PutCallRatio PutCallRatio(ISeries input ) { return indicator.PutCallRatio(input); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.PutCallRatio PutCallRatio() { return indicator.PutCallRatio(Input); } public Indicators.PutCallRatio PutCallRatio(ISeries input ) { return indicator.PutCallRatio(input); } } } #endregion