# Input Declarations:
AssignBackgroundColor(CreateColor(8, 0, 15));
input extendhighway = yes;
input gobubbleposition = 3;
input showvaluearea = yes;
input mult = 1.0; #Multiple of Average True Range to use
input length = 10; #Average True Range period
#
# Input to select Close or High/Low for switching:
#
input Style = {default Close, HighLow};
input tickdecimal = 2;
def type;
switch (Style){
case Close:
type = 1;
case HighLow:
type = 0;
}
#
# Set parameters based on switch selection:
#
def uu = if type then close else high;
def ll = if type then close else low;
def na = Double.NaN;
#
# Calculate average range for volatility:
#
def atr = ExpAverage(high – low, length);
#
# Calculate initial short and long volatility stop values:
#
def svs = low + Ceil(mult * atr / TickSize()) * TickSize();
def lvs = high – Ceil(mult * atr / TickSize()) * TickSize();
#
# Set up the trailing stop logic:
#
rec shortvs = if IsNaN(shortvs[1]) then svs else if uu > shortvs[1] then svs else Min(svs, shortvs[1]);
rec longvs = if IsNaN(longvs[1]) then lvs else if ll < longvs[1] then lvs else Max(lvs, longvs[1]);
#
# Detect if we breached the trailing stop (close or high/low):
#
def longswitch = if uu >= shortvs[1] and uu[1] < shortvs[1] then 1 else 0;
def shortswitch = if ll <= longvs[1] and ll[1] > longvs[1] then 1 else 0;
#
# This logic remembers the direction and changes when needed:
#
rec direction = CompoundValue(1, if IsNaN(direction[1]) then 0 else
if direction[1] <= 0 and longswitch then 1
else if direction[1] >= 0 and shortswitch then -1
else direction[1], 0);
#
# Set up the two plots. “na” makes the current value disappear
# if we?re trading in the opposite direction:
#
#
# Alerts:
#
def alerttrigger = if direction[1] <= 0 and longswitch then 1
else if direction[1] >= 0 and shortswitch then 1 else 0;
input alerttext = “Alert Text”;
# BLOCK CODE BELOW
input UseAlerts = {false, default true};
input AlertType = {default “BAR”, “ONCE”, “TICK”};
def at = AlertType;
input AlertSound = {“Bell”, “Chimes”, default “Ding”, “NoSound”, “Ring”};
Alert(alerttrigger and UseAlerts, alerttext, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);
def short = if direction > 0 then na else shortvs;
def long = if direction < 0 then na else longvs;
plot bestradelong = if long then long else Double.NaN;
#
# Formatting:
#
bestradelong.SetDefaultColor(Color.GREEN);
bestradelong.SetStyle(Curve.POINTS);
bestradelong.SetLineWeight(2);
bestradelong.HideBubble();
plot bestradeshort = if short then short else Double.NaN;
bestradeshort.SetDefaultColor(Color.RED);
bestradeshort.SetStyle(Curve.POINTS);
bestradeshort.SetLineWeight(2);
bestradeshort.HideBubble();
input brackets = 4;
rec shortexit3 = short – atr;
rec shortentry = short – (atr / brackets);
rec shortentry1 = short – 2 * (atr / brackets);
rec shortentry2 = short – 3 * (atr / brackets);
rec longexit3 = long + atr;
rec longentry = long + (atr / brackets);
rec longentry1 = long + 2 * (atr / brackets);
rec longentry2 = long + 3 * (atr / brackets);
AddLabel(long, “Entry ” + Round(long, tickdecimal), Color.GREEN);
AddLabel(long, “Exit ” + Round(longexit3, tickdecimal), Color.RED);
AddLabel(long, ” ATR = ” + Round(atr, tickdecimal), Color.CYAN);
AddLabel(long, “Slow Lane ” + Round(longentry, tickdecimal), Color.GREEN);
AddLabel(long, “Cruising ” + Round(longentry1, tickdecimal), Color.GREEN);
AddLabel(long, “Fast Lane ” + Round(longentry2, tickdecimal), Color.GREEN);
AddLabel(short, “Entry ” + Round(short, tickdecimal), Color.RED);
AddLabel(short, “Exit ” + Round(shortexit3, tickdecimal), Color.GREEN);
AddLabel(short, ” ATR = ” + Round(atr, tickdecimal), Color.CYAN);
AddLabel(short, “Slow Lane ” + Round(shortentry, tickdecimal), Color.RED);
AddLabel(short, “Cruising ” + Round(shortentry1, tickdecimal), Color.RED);
AddLabel(short, “Fast Lane ” + Round(shortentry2, tickdecimal), Color.RED);
def longexitdot = if long then longexit3 else Double.NaN;
def shortexitdot = if short then shortexit3 else Double.NaN;
plot longexitdot1 = if long then longexitdot else Double.NaN;
longexitdot1.SetDefaultColor(Color.RED);
longexitdot1.SetStyle(Curve.POINTS);
longexitdot1.SetLineWeight(1);
longexitdot1.HideBubble();
plot shortexitdot1 = if short then shortexitdot else Double.NaN;
shortexitdot1.SetDefaultColor(Color.GREEN);
shortexitdot1.SetStyle(Curve.POINTS);
shortexitdot1.SetLineWeight(1);
shortexitdot1.HideBubble();
# Clouds
#AddCloud(shortexitdot1, bestradeshort);
#AddCloud(longexitdot1, bestradelong);
AddCloud(shortexitdot1, bestradeshort, color1 = Color.WHITE, color2 = CreateColor(174, 74, 189));
AddCloud(longexitdot1, bestradelong, color1 = Color.YELLOW, color2 = Color.GREEN);
plot longentry14 = if long then longentry else Double.NaN;
longentry14.SetDefaultColor(Color.CYAN);
longentry14.SetStyle(Curve.SHORT_DASH);
longentry14.SetLineWeight(1);
longentry14.HideBubble();
plot halflongentry = if long then longentry1 else Double.NaN;
halflongentry.SetDefaultColor(Color.CYAN);
halflongentry.SetStyle(Curve.SHORT_DASH);
halflongentry.SetLineWeight(1);
halflongentry.HideBubble();
plot longentry34 = if long then longentry2 else Double.NaN;
longentry34.SetDefaultColor(Color.CYAN);
longentry34.SetStyle(Curve.SHORT_DASH);
longentry34.SetLineWeight(1);
longentry34.HideBubble();
plot shortentry14 = if short then shortentry else Double.NaN;
shortentry14.SetDefaultColor(Color.CYAN);
shortentry14.SetStyle(Curve.SHORT_DASH);
shortentry14.SetLineWeight(1);
shortentry14.HideBubble();
plot shorthalfentry = if short then shortentry1 else Double.NaN;
shorthalfentry.SetDefaultColor(Color.CYAN);
shorthalfentry.SetStyle(Curve.SHORT_DASH);
shorthalfentry.SetLineWeight(1);
shorthalfentry.HideBubble();
plot shortentry34 = if short then shortentry2 else Double.NaN;
shortentry34.SetDefaultColor(Color.CYAN);
shortentry34.SetStyle(Curve.SHORT_DASH);
shortentry34.SetLineWeight(1);
shortentry34.HideBubble();
input showarrows = yes;
input arrowoffset = 1;
plot longtrendarrow = showarrows and long – TickSize() * arrowoffset;
longtrendarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
longtrendarrow.SetDefaultColor(Color.GREEN);
longtrendarrow.SetLineWeight(1);
longtrendarrow.HideBubble();
plot shorttrendarrow = showarrows and short + TickSize() * arrowoffset;
;
shorttrendarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
shorttrendarrow.SetDefaultColor(Color.RED);
shorttrendarrow.SetLineWeight(1);
shorttrendarrow.HideBubble();
#Bubbles
# set right expansion to 10;
input bubbledisplace = .05;
def bubbledisplace1 = bubbledisplace * 2;
def bubbledisplace2 = bubbledisplace * 3;
def bubbledisplace3 = bubbledisplace * 4;
input lanebubbleposition = 0;
def n = lanebubbleposition;
def n1 = n + 1;
input showbubbles = yes;
def q = gobubbleposition;
def q1 = q + 1;
input lineposition = 0.75;
def r = lineposition;
def r1 = r + 1;
input showlines = yes;
def longticks = longexit3 – close;
def shorticks = close – shortexit3;
def longloss = long – close;
def shortloss = close – short;
AddChartBubble(showbubbles and !IsNaN(close[q1]) and IsNaN(close[q]) and long[q1], close[q1], if close[q1] < longentry[q1] then “Go” + “\n” + “Long!” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(longticks[q1], tickdecimal) + ” \nL: ” + Round(longloss[q1], tickdecimal) else if close[q1] < longentry1[q1] then “Long” + “\n” + “Slow” + “\n” + “Lane” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(longticks[q1], tickdecimal) + ” \nL: ” + Round(longloss[q1], tickdecimal) else if close[q1] < longentry2[q1] then “Long” + “\n” + ” Cruising” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(longticks[q1], tickdecimal) + ” \nL: ” + Round(longloss[q1], tickdecimal) else if close[q1] < longexitdot[q1] then “Long” + “\n” + ” Fast” + “\n” + ” Lane” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(longticks[q1], tickdecimal) + ” \nL: ” + Round(longloss[q1], tickdecimal) else “Exit” + “\n” + “Long” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(longticks[q1], tickdecimal) + ” \nL: ” + Round(longloss[q1], tickdecimal), if close[q1] < longentry[q1] then CreateColor(51, 255, 51) else if close[q1] < longentry1[q1] then CreateColor(0, 255, 0) else if close[q1] < longentry2[q1] then CreateColor(0, 204, 0) else Color.RED);
plot golongline = if showlines and !IsNaN(close[q1]) and IsNaN(close[q]) and long[q1] then close[q1] else Double.NaN;
golongline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
golongline.SetDefaultColor(Color.GREEN);
golongline.HideBubble();
AddChartBubble(showbubbles and !IsNaN(close[q1]) and IsNaN(close[q]) and short[q1], close[q1], if close[q1] > shortentry[q1] then “Go” + “\n” + “Short!” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(shorticks[q1], tickdecimal) + ” \nL: ” + Round(shortloss[q1], tickdecimal) else if close[q1] > shortentry1[q1] then “Short” + “\n” + “Slow” + “\n” + “Lane” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(shorticks[q1], tickdecimal) + ” \nL: ” + Round(shortloss[q1], tickdecimal) else if close[q1] > shortentry2[q1] then “Short” + “\n” + “Cruising” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(shorticks[q1], tickdecimal) + ” \nL: ” + Round(shortloss[q1], tickdecimal) else if close[q1] > shortexitdot[q1] then “Short” + “\n” + “Fast” + “\n” + “Lane” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(shorticks[q1], tickdecimal) + ” \nL: ” + Round(shortloss[q1], tickdecimal) else “Exit” + “\n” + “Short” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(shorticks[q1], tickdecimal) + ” \nL: ” + Round(shortloss[q1], tickdecimal), if close[q1] > shortentry[q1] then CreateColor(255, 102, 102) else if close[q1] > shortentry1[q1] then Color.RED else if close[q1] > shortentry2[q1] then Color.RED else Color.GREEN);
plot goshortline = if showlines and !IsNaN(close[q1]) and IsNaN(close[q]) and short[q1] then close[q1] else Double.NaN;
goshortline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
goshortline.SetDefaultColor(Color.RED);
goshortline.HideBubble();
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1]
, short[n1] + bubbledisplace, “ATR = ” + Round(atr[n1], tickdecimal), Color.CYAN);
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1], long[n1] – bubbledisplace, “ATR = ” + Round(atr[n1], tickdecimal), Color.CYAN);
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1], long[n1], “Entry ” + Round(long[n1], tickdecimal), CreateColor(102, 255, 102));
def longentrylinevalue = if IsNaN(close) then longentrylinevalue[1] else long;
plot longentryline = if !IsNaN(close) then Double.NaN else longentrylinevalue;
longentryline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
longentryline.SetDefaultColor(Color.GREEN);
longentryline.HideBubble();
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1] , longentry[n1], ” Slow Lane: ” + Round(longentry[n1], tickdecimal), Color.GREEN);
def longentry14value = if IsNaN(close) then longentry14value[1] else longentry;
plot longentryline14 = if !IsNaN(close) then Double.NaN else longentry14value;
longentryline14.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
longentryline14.SetDefaultColor(Color.GREEN);
longentryline14.HideBubble();
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1], longentry1[n1], ” Cruising: ” + Round(longentry1[n1], tickdecimal), Color.GREEN);
def longentry12value = if IsNaN(close) then longentry12value[1] else longentry1;
plot longentryline12 = if !IsNaN(close) then Double.NaN else longentry12value;
longentryline12.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
longentryline12.SetDefaultColor(Color.GREEN);
longentryline12.HideBubble();
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1], longentry2[n1], ” Fast Lane: ” + Round(longentry2[n1], tickdecimal), Color.DARK_GREEN);
def longentry34value = if IsNaN(close) then longentry34value[1] else longentry2;
plot longentryline34 = if !IsNaN(close) then Double.NaN else longentry34value;
longentryline34.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
longentryline34.SetDefaultColor(Color.GREEN);
longentryline34.HideBubble();
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1], longexit3[n1], “Exit: ” + Round(longexit3[n1], tickdecimal), Color.RED);
def longexitlinevalue = if IsNaN(close) then longexitlinevalue[1] else longexitdot;
plot longexitline = if !IsNaN(close) then Double.NaN else longexitlinevalue;
longexitline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
longexitline.SetDefaultColor(Color.RED);
longexitline.HideBubble();
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1] , short[n1], “Entry ” + Round(short[n1], tickdecimal), Color.RED);
def shortentrylinevalue = if IsNaN(close) then shortentrylinevalue[1] else short;
plot shortentryline = if !IsNaN(close) then Double.NaN else shortentrylinevalue;
shortentryline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
shortentryline.SetDefaultColor(Color.RED);
shortentryline.HideBubble();
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1] , shortexit3[n1], “Exit ” + Round(shortexit3[n1], tickdecimal), Color.GREEN);
def shortexitlinevalue = if IsNaN(close) then shortexitlinevalue[1] else shortexit3;
plot shortexitline = if !IsNaN(close) then Double.NaN else shortexitlinevalue;
shortexitline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
shortexitline.SetDefaultColor(Color.GREEN);
shortexitline.HideBubble();
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1] , shortentry[n1], ” Slow Lane: ” + Round(shortentry[n1], tickdecimal), Color.RED);
def shortentryline14value = if IsNaN(close) then shortentryline14value[1] else shortentry;
plot shortentryline14 = if !IsNaN(close) then Double.NaN else shortentryline14value;
shortentryline14.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
shortentryline14.SetDefaultColor(Color.RED);
shortentryline14.HideBubble();
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1] , shortentry1[n1], ” Cruising: ” + Round(shortentry1[n1], tickdecimal), Color.RED);
def shortentryline12value = if IsNaN(close) then shortentryline12value[1] else shortentry1;
plot shortentryline12 = if !IsNaN(close) then Double.NaN else shortentryline12value;
shortentryline12.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
shortentryline12.SetDefaultColor(Color.RED);
shortentryline12.HideBubble();
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1] , shortentry2[n1], ” Fast Lane: ” + Round(shortentry2[n1], tickdecimal), Color.DARK_RED);
def shortentryline34value = if IsNaN(close) then shortentryline34value[1] else shortentry2;
plot shortentryline34 = if !IsNaN(close) then Double.NaN else shortentryline34value;
shortentryline34.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
shortentryline34.SetDefaultColor(Color.RED);
shortentryline34.HideBubble();
input trendbubbledisplace = .10;
input chartbubbleoffset = 1;
input trendlabel = no;
AddChartBubble(trendlabel and long[1] and short , high + TickSize() * chartbubbleoffset , ” Downtrend “, Color.RED);
AddChartBubble(trendlabel and short[1] and long , low – TickSize() * chartbubbleoffset, ” Uptrend “, Color.GREEN, no);
# Extension Plot
# rec ssf = if !IsNaN(SuperSmootherFilter) then SuperSmootherFilter else ssf[1] + (ssf[1] – ssf[2]);
#plot ssfextension = if(extendssf) then ssf else double.NaN;
rec highwayextshort = if !IsNaN(shortexitdot1) then shortexitdot1 else highwayextshort[1] + (highwayextshort[1] – highwayextshort[2]);
plot highwayextensionshort = if (extendhighway) and !isNan (shortexitdot1[2]) then highwayextshort else Double.NaN;
rec highwayextshort1 = if !IsNaN(bestradeshort) then bestradeshort else highwayextshort1[1] + (highwayextshort1[1] – highwayextshort1[2]);
plot highwayextensionshort1 = if (extendhighway) and !isNan (bestradeshort[2]) then highwayextshort1 else Double.NaN;
rec highwayextlong = if !IsNaN(longexitdot1) then longexitdot1 else highwayextlong[1] + (highwayextlong[1] – highwayextlong[2]);
plot highwayextensionlong = if (extendhighway) and !isNan(longexitdot1[2]) then highwayextlong else Double.NaN;
rec highwayextlong1 = if !IsNaN(bestradelong) then bestradelong else highwayextlong1[1] + (highwayextlong1[1] – highwayextlong1[2]);
plot highwayextensionlong1 = if (extendhighway) and !isNan(bestradelong[2]) then highwayextlong1 else Double.NaN;
#Cloud Extension
AddCloud(highwayextensionshort, highwayextensionshort1, color1 = Color.red, color2 = color.red);
AddCloud(highwayextensionlong1, highwayextensionlong, color1 = Color.green, color2 = color.green);