public class j2TrendBias : Indicator
{
private SMA SMA1;
private NinjaTrader.NinjaScript.Indicators.j2.j2CumDelta j2CumDelta1;
private NinjaTrader.NinjaScript.Indicators.j2.j2BarCounter j2BarCounter1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"This indicator identifies higher timeframe bias by price action. Current Beta is for use specifically on a 30 min chart";
Name = "j2TrendBias";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
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;
soundAlert = false;
TickDistance = 4;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Tick, 1);
}
else if (State == State.DataLoaded)
{
SMA1 = SMA(Close, 14);
j2CumDelta1 = j2CumDelta(Close, Brushes.Red, Brushes.LimeGreen, Brushes.White, 1, 0, false);
j2BarCounter1 = j2BarCounter(Close, true, Brushes.Gray, 14, 50, true);
}
}
region Codesets
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 0)
return;
// Set 1 Opens = Lows
if (
// Open = Low
((Open[0] == Low[0])
&& (SMA1[0] > SMA1[1])
&& (j2CumDelta1.DeltaOpen[0] > -1000)
&& (j2BarCounter1[0] > 18)
&& (Close[0] > Open[0]))
// Open = Low - 1 tick
|| ((Close[0] > Open[0])
&& (j2CumDelta1.DeltaOpen[0] > -1000)
&& (Low[0] == (Open[0] + (-1 * TickSize))
&& (j2BarCounter1[0] > 18)
&& (SMA1[0] > SMA1[1]))))
{
Draw.ArrowUp(this, "TrendBiasUp"+CurrentBar, false, 0, Low[0] - (TickDistance * TickSize), Brushes.Cyan); // Alert[0] = 1 maybe add later
if (soundAlert == true)
PlaySound(@"C:\Program Files\NinjaTrader 8\sounds\j2TrendAlert.wav");
}
// Set 2 Opens = Highs
if (
// Open = High
((Open[0] == High[0])
&& (SMA1[0] < SMA1[1])
&& (j2CumDelta1.DeltaOpen[0] < 1000)
&& (j2BarCounter1[0] > 18)
&& (Close[0] < Open[0]))
// Open = High + 1 tick
|| ((Close[0] > Open[0])
&&(j2CumDelta1.DeltaOpen[0] < 1000)
&& (High[0] == (Open[0] + (1 * TickSize))
&& (j2BarCounter1[0] > 18)
&& (SMA1[0] < SMA1[1]))))
{
Draw.ArrowDown(this, "TrendBiasDown"+CurrentBar, false, 0, High[0] + (TickDistance * TickSize), Brushes.Cyan);
if (soundAlert == true)
PlaySound(@"C:\Program Files\NinjaTrader 8\sounds\j2TrendAlert.wav");
}
// Set 3 Reversing bars with equal close/open & reversal bar up
if (
((Open[0] == Close[1])
&& (Close[1] < Open[1])
&& (j2CumDelta1.DeltaOpen[0] > -1000)
&& (Close[0] > Open[0])
&& (Close[0] > Open[1])
&& (SMA1[0] > SMA1[1])
&& (j2BarCounter1[0] > 18)
&& (Low[0] > (Low[1] + (-3 * TickSize)))))
{
Draw.ArrowUp(this, "TrendBiasUp"+CurrentBar, false, 0, Low[0] - (TickDistance * TickSize), Brushes.Cyan);
if (soundAlert == true)
PlaySound(@"C:\Program Files\NinjaTrader 8\sounds\j2TrendAlert.wav");
}
// Set 4 Reversing bars with equal close/open & reversal bar down
if (
((Open[0] == Close[1])
&& (Close[1] > Open[1])
&& (j2CumDelta1.DeltaOpen[0] < 1000)
&& (Close[0] < Open[0])
&& (Close[0] < Open[1])
&& (SMA1[0] < SMA1[1])
&& (j2BarCounter1[0] > 18)
&& (High[0] < (High[1] + (3 * TickSize)))))
{
Draw.ArrowDown(this, "TrendBiasDown"+CurrentBar, false, 0, High[0] + (TickDistance * TickSize), Brushes.Cyan);
if (soundAlert == true)
PlaySound(@"C:\Program Files\NinjaTrader 8\sounds\j2TrendAlert.wav");
}
// Set 5 Massive bars typically reversing and in negative CumDelta territory
if (
((Close[0] > (Open[0] + (51 * TickSize))
&& (SMA1[0] > SMA1[1])
&& (j2BarCounter1[0] > 29)
&& (j2CumDelta1.DeltaOpen[0] < -1000))))
{
Draw.ArrowUp(this, "TrendBiasUp"+CurrentBar, false, 0, Low[0] - (TickDistance * TickSize), Brushes.Yellow);
if (soundAlert == true)
PlaySound(@"C:\Program Files\NinjaTrader 8\sounds\j2TrendAlert.wav");
}
// Set 6 Massive bars typically reversing and in positive CumDelta territory
if (
((Close[0] < (Open[0] - (51 * TickSize))
&& (SMA1[0] < SMA1[1])
&& (j2BarCounter1[0] > 30)
&& (j2CumDelta1.DeltaOpen[0] > 1000))))
{
Draw.ArrowDown(this, "TrendBiasDown"+CurrentBar, false, 0, High[0] + (TickDistance * TickSize), Brushes.Yellow);
if (soundAlert == true)
PlaySound(@"C:\Program Files\NinjaTrader 8\sounds\j2TrendAlert.wav");
}
}
#endregion
region Properties
[NinjaScriptProperty]
[Display(Name="SoundAlert", Description="plays sound on firing signal", Order=1, GroupName="Parameters")]
public bool soundAlert
{ get; set; }
[NinjaScriptProperty]
[Range(-100, int.MaxValue)]
[Display(Name="TickDistance", Description="distance from top or bottom of candle for chart arrow position. ", Order=7, GroupName="Parameters")]
public int TickDistance
{ get; set; }
#endregion
}
}



... Cheers!
Comment