private double entryBar;
private double prevATRBar;
private double highestHigh;
private double lowestLow;
private double atrX2;
private double stopLoss;
private double Target;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "aStopTrgtDemo";
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;
MaxLookBackPeriod = 10;
RewardMultiplier = 1.5;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < MaxLookBackPeriod)
return;
NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12) { Size = 12, Bold = false };
int lwstlwindx = LowestBar(Low, MaxLookBackPeriod);
double lwstlw = MIN(Low, MaxLookBackPeriod)[0];
int hghsthghindx = HighestBar(High, MaxLookBackPeriod);
double hghsthgh = MAX(High, MaxLookBackPeriod)[0];
if (EMA(144)[0] > EMA(390)[0] )
{
Draw.Text(this,"L",true,"L",lwstlwindx,lwstlw - (TickSize * 4),0,Brushes.Black,myFont,TextAlignment.Center,Bru shes.Transparent,Brushes.Black,1);
if (Close[1] <= SMA(9)[1] && Close[0] > SMA(9)[0])
{
entryBar = Close[0] + .5;
prevATRBar = ATR(7)[1];
lowestLow = MIN(Low, MaxLookBackPeriod)[0];
atrX2 = prevATRBar * 2;
stopLoss = lowestLow - atrX2;
Target = entryBar + ((entryBar - stopLoss) * RewardMultiplier);
Draw.HorizontalLine(this, "Stop", true, stopLoss, Brushes.Red, DashStyleHelper.Solid,2);
Draw.HorizontalLine(this, "Target", true, Target, Brushes.Lime, DashStyleHelper.Solid,2);
}
}
else if (EMA(144)[0] < EMA(390)[0])
{
Draw.Text(this,"H",true,"H",hghsthghindx,hghsthgh + (TickSize * 4),0,Brushes.Black,myFont,TextAlignment.Center,Bru shes.Transparent,Brushes.Black,1);
if (Close[1] >= SMA(9)[1] && Close[0] < SMA(9)[0])
{
entryBar = Close[0] - .5;
prevATRBar = ATR(7)[1];
highestHigh = MAX(High, MaxLookBackPeriod)[0];
atrX2 = prevATRBar * 2;
stopLoss = highestHigh + atrX2;
Target = entryBar - ((stopLoss - entryBar) * RewardMultiplier);
Draw.HorizontalLine(this, "Stop", true, stopLoss, Brushes.Red, DashStyleHelper.Solid,2);
Draw.HorizontalLine(this, "Target", true, Target, Brushes.Lime, DashStyleHelper.Solid,2);
}
}
}

Comment