Working on a scalping-type indicator that points out the setup using a painted diamond on the bar that triggers it. Here's what I need to paint:
Diamond on any bar that has its wick cross the mean of the Donchian channel but does not open nor close on that side. Thus only the wick crosses. E.g. Donchian mean is 100, the low of the bar is 95 (crosses) but the bar opened at 102 and closes at 105 (only wick touches the mean).
I also would only like to paint the diamond if the ADX is above a certain threshold, and if the price is, for longs, at least two ticks above the EMA on the low or, for shorts, at least two ticks below the EMA on the high.
I'm kinda bummed - I thought I wrote out the indicator logic very well. Yet it's just leaving me with this (attached image, red arrow shows the bar that SHOULD have a painted diamond), which is a blank panel at the bottom and no painted markers.
Code:
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "RenkoScalper";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = false;
DrawOnPricePanel = true;
DrawHorizontalGridLines = false;
DrawVerticalGridLines = false;
PaintPriceMarkers = false;
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;
DonchianPeriod = 12;
RequireOutsideWave = false;
ADXPeriod = 6;
RequireADXCutoff = false;
ADXCutoff = 25;
WavePeriod = 34;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
// Booleans
bool fireLong = false;
bool fireShort = false;
bool valid = true;
// Get Donchian mean 1 bar ago
double meanValue = DonchianChannel(Close, DonchianPeriod).Mean[1];
// Determine if buy or sell wick signal
if ((Low[1] < meanValue)
&& (Open[1] > meanValue)
&& (Close[1] > meanValue))
{
fireLong = true;
}
else if ((High[1] > meanValue)
&& (Open[1] < meanValue)
&& (Close[1] < meanValue))
{
fireShort = true;
}
// Determine if signal is valid
if (RequireADXCutoff)
{
// Last ADX reading
double CurrentADX = ADX(Close, ADXPeriod)[1];
// Lose validity if last ADX is under cutoff
if (CurrentADX < ADXCutoff)
valid = false;
}
if (RequireOutsideWave)
{
if (fireLong)
{
double HiEMA = EMA(High, WavePeriod)[1];
if (Open[0] <= HiEMA)
valid = false;
}
else if (fireShort)
{
double LoEMA = EMA(Low, WavePeriod)[1];
if (Open[0] >= LoEMA)
valid = false;
}
}
// Last validity check
if (fireLong)
{
double LoEMA = EMA(Low, WavePeriod)[1];
if (Open[0] < (LoEMA + TickSize*2))
valid = false;
}
else if (fireShort)
{
double HiEMA = EMA(High, WavePeriod)[1];
if (Open[0] > (HiEMA - TickSize*2))
valid = false;
}
// If valid, now let's paint our signal
if (valid && fireLong)
{
Draw.Diamond(this, "LongSignal", true, 0, (Low[0] - TickSize*4), Brushes.Lime);
PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\FireLong.wav");
}
else if (valid && fireShort)
{
Draw.Diamond(this, "LongSignal", true, 0, (High[0] + TickSize*4), Brushes.Red);
PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\FireShort.wav");
}
}
Comment