Initial commit of Put / Call Ratio indicator

This commit is contained in:
moshferatu 2024-11-19 07:55:31 -08:00
parent 519b82fb0e
commit e00ceedeb0

View File

@ -0,0 +1,108 @@
#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<double> 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<PutCallRatio>(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<double> 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<double> input )
{
return indicator.PutCallRatio(input);
}
}
}
#endregion