mamaroneck NY/usa
Experience: Beginner
Platform: tos,multichart,ninja
Trading: ES,YM,CL,GC,NQ,TF,6J,
Posts: 3 since Feb 2017
Thanks Given: 1
Thanks Received: 1
|
input displace = 1;
input length1 = 8;
input length2 = 21;
input averageType = AverageType.WILDERS;
input atrlength = 1;
plot ATR = Average(TrueRange(high, close, low), ATRLength) / close;
def h = high[displace];
def l = low[displace];
def c = close;
def bn = BarNumber();
def na = Double.NaN;
def cb = highestAll(if !IsNaN(c) and IsNaN(c[-1]) then bn else na);
#plot Lb = Lowest(l, length1);
#Lb.SetDefaultColor(GetColor(8));
def Ub = Highest(h, length1);
#Ub.SetDefaultColor(Color.cyan);
plot ubatr = ub - ub * (atr*0.01);
ubatr.SetDefaultColor(Color.green);
def Lb2 = Lowest(l, length2);
#Lb2.SetDefaultColor(Color.red);
plot lb2atr = lb2 - lb2 * (atr*0.001) ;
#Ub2.SetDefaultColor(Color.RED);
lb2atr.SetDefaultColor(Color.cyan);
#plot Ub2 = Highest(h, length2);
#Ub2.SetDefaultColor(GetColor(8));
def ubLong = high crosses above Ubatr;
def ubEntry = if ubLong then ubatr else ubEntry[1];
#def ubLong = c crosses above Ub;
#def ubEntry = if ubLong then c else ubEntry[1];
def ubStop = if ubLong then Lb2atr else ubStop[1];
def ubT1 = if ubLong then ubEntry + 1.5 * (ubEntry - ubStop) else uBT1[1];
def ubT2 = if ubLong then ubEntry +3.5* (ubEntry - ubStop) else uBT2[1];
def longTradeOn = if ubLong
then 1
else if low crosses below ubStop
# or high crosses above ubT2
then 0
else longTradeOn[1];
def activeTrade = HighestAll(if bn == cb then longTradeOn else na);
plot Buy = if activeTrade then ubEntry else na;
Buy.SetDefaultColor(Color.white);
buy.SetPaintingStrategy(PaintingStrategy.horizontal);
buy.SetLineWeight(1);
plot Stop = if activeTrade then ubStop else na;
Stop.SetDefaultColor(Color.red);
stop.SetPaintingStrategy(PaintingStrategy.horizontal);
stop.SetLineWeight(1);
plot TargetOne = if activeTrade then ubT1 else na;
TargetOne.SetDefaultColor(Color.yellow);
TargetOne.SetPaintingStrategy(PaintingStrategy.horizontal);
TargetOne.SetLineWeight(1);
plot TargetTwo = if activeTrade then ubT2 else na;
TargetTwo.SetDefaultColor(Color.cyan);
TargetTwo.SetPaintingStrategy(PaintingStrategy.horizontal);
TargetTwo.SetLineWeight(1);
def location = !IsNaN(c) and IsNaN(c[-1]);
AddChartBubble(activetrade and location, ubEntry, "Entry: "+ubEntry, Buy.TakeValueColor());
AddChartBubble(activetrade and location, ubStop, "Stop: "+ubStop, Stop.TakeValueColor());
AddChartBubble(activetrade and location, ubT1, "T1: "+ubT1, TargetOne.TakeValueColor());
AddChartBubble(activetrade and location, ubT2, "T2: "+ubT2, TargetTwo.TakeValueColor());
#need to plot only first entry unless it hits the stop loss or second target then plot entry again ,also if can be converted to ninjatrader ,thanks ,
|