####################################################
Declare Upper;
Def price =(Open+Close)/2;
Input Length1 =3;
Input Length2 =6;
Input Length3 =9;
Input Length4 =12;
Input Length5 =15;
Input Length6 =30;
Input Length7 =45;
Input Length8 =60;
input averageType = AverageType.exponential;
input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = no;
###I don't use this paint bar of the Supertrend########
input aggregationPeriod = AggregationPeriod.MIN;
input trailType = {default modified, unmodified};
input ATRPeriod = 28;
input ATRFactor = 5;
input firstTrade = {default long, short};
input averageType2 = AverageType.WILDERS;
#### 4 EMA Rank##########
def D1 = MovingAverage(AveragetYPE,Price,length1);
def D2 = MovingAverage(AverageType,price,Length2);
def D3 = MovingAverage(AverageType,price,Length3);
def D4 = MovingAverage(AverageType,price,Length4);
def W1 = MovingAverage(AveragetYPE,Price,length5);
def W2 = MovingAverage(AverageType,price,Length6);
def W3 = MovingAverage(AverageType,price,Length7);
def W4 = MovingAverage(AverageType,price,Length8);
def DCondition1 = If(D1 > D2 and D2 > D3 and D3 > D4, 5,
If((D1 > D2 and D2 > D4 and D4 > D3) or (D1 > D3 and D3 > D2 and D2 > D4) or
(D2 > D1 and D1 > D3 and D3 > D4), 4, If(D2 > D1 and D1 > D4 and D4 > D3, 3,
If((D1 > D3 and D3 > D4 and D4 > D2) or ( D1 > D4 and D4 > D2 and D2 > D3) or
(D2 > D3 and D3 > D1 and D1 > D4) or (D3 > D1 and D1 > D2 and D2 > D4) , 2,
If((D1 > D4 and D4 > D3 and D3 > D2) or (D3 > D2 and D2 > D1 and D1 > D4), 1, 0)))));
def DCondition2 = If(D4 > D3 and D3 > D2 and D2 > D1, -5,
If((D3 > D4 and D4 > D2 and D2 > D1) or (D4 > D2 and D2 > D3 and D3 > D1) or
(D4 > D3 and D3 > D1 and D1 > D2), -4, If(D3 > D4 and D4 > D1 and D1 > D2, -3,
If((D2 > D4 and D4 > D3 and D3 > D1) or (D3 > D2 and D2 > D4 and D4 > D1) or
(D4 > D1 and D1 > D3 and D3 > D2) or (D4 > D2 and D2 > D1 and D1 > D3) , -2,
If((D2 > D3 and D3 > D4 and D4 > D1) or (D4 > D1 and D1 > D2 and D2 > D3), -1, 0)))));
def WCondition1 = If(W1 > W2 and W2 > W3 and W3 > W4, 50,
If((W1 > W2 and W2 > W4 and W4 > W3) or (W1 > W3 and W3 > W2 and W2 > W4) or
(W2 > W1 and W1 > W3 and W3 > W4), 40, If(W2 > W1 and W1 > W4 and W4 > W3, 30,
If((W1 > W3 and W3 > W4 and W4 > W2) or ( W1 > W4 and W4 > W2 and W2 > W3) or
(W2 > W3 and W3 > W1 and W1 > W4) or (W3 > W1 and W1 > W2 and W2 > W4) , 20,
If((W1 > W4 and W4 > W3 and W3 > W2) or (W3 > W2 and W2 > W1 and W1 > W4), 10, 0)))));
def WCondition2 = If(W4 > W3 and W3 > W2 and W2 > W1, -50,
If((W3 > W4 and W4 > W2 and W2 > W1) or (W4 > W2 and W2 > W3 and W3 > W1) or
(W4 > W3 and W3 > W1 and W1 > W2), -40, If(W3 > W4 and W4 > W1 and W1 > W2, -30,
If((W2 > W4 and W4 > W3 and W3 > W1) or (W3 > W2 and W2 > W4 and W4 > W1) or
(W4 > W1 and W1 > W3 and W3 > W2) or (W4 > W2 and W2 > W1 and W1 > W3) , -20,
If((W2 > W3 and W3 > W4 and W4 > W1) or (W4 > W1 and W1 > W2 and W2 > W3), -10, 0)))));
def WT = (WCondition1+WCondition2);
def TT = (WCondition1+WCondition2+DCondition1+DCondition2);
DefineGlobalColor(“Long”,Color.Cyan);
DefineGlobalColor(“Short”,Color.Orange);
DefineGlobalColor("Neutral”,Color.YELLOW);
Def Long = TT > WT;
Def Short = TT < WT;
AssignPriceColor(If Long then GlobalColor(“Long”) else if Short then GlobalColor(“Short”) else GlobalColor("Neutral"));
plot arrowup=if TT crosses above WT then Low - ATR(1) else double.Nan;
arrowup.setPaintingStrategy(paintingStrategy.ARROW_UP);
arrowup.setDefaultColor(color.Cyan);
plot arrowdown=if TT crosses below WT then High + ATR(1) else double.NaN;
arrowdown.setPaintingStrategy(paintingStrategy.ARROW_dowN);
arrowdown.setDefaultColor(color.Dark_Orange);
Input Label = yes;
AddLabel(Label, if TT >WT then "4MR > W" else "4MR < W", if TT > WT then Color.Cyan else Color.Orange);
##########Supertrend###############
def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);
def LW_Band_Basic = HL2 + (-AtrMult * ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];
def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;
plot SuperTrend = ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
AssignPriceColor(if PaintBars and close < ST
then Color.Dark_Orange
else if PaintBars and close > ST
then Color.Cyan
else Color.CURRENT);
SuperTrend.setLineWeight(3);
plot ArrowDownST = Supertrend crosses above close;
ArrowDownST.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDownST.SetDefaultColor(Color.RED);
ArrowDownST.SetLineWeight(3);
plot ArrowUpST = Supertrend crosses below close;
ArrowUpST.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUpST.SetDefaultColor(Color.GREEN);
ArrowUpST.SetLineWeight(3);
##############swingArm#################
def fib0Level = 0;
def fib1Level = 12.5;
def fib2Level = 25;
def fib3Level = 37.5;
def fib4Level = 50.0;
def fib5Level = 62.5;
def fib6Level = 75;
def fib7Level = 87.5;
Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);
def open = Open(Period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def close = close(period = aggregationPeriod);
def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
then high - close[1]
else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
then close[1] - low
else (close[1] - low) - 0.5 * (low[1] - high);
def trueRange;
switch (trailType) {
case modified:
trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
trueRange = TrueRange(high, close, low);
}
def loss = ATRFactor * MovingAverage(averageType2, trueRange, ATRPeriod);
def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
if (!IsNaN(loss)) {
switch (firstTrade) {
case long:
state = state.long;
trail = close - loss;
case short:
state = state.short;
trail = close + loss;
}
} else {
state = state.init;
trail = Double.NaN;
}
case long:
if (close > trail[1]) {
state = state.long;
trail = Max(trail[1], close - loss);
} else {
state = state.short;
trail = close + loss;
}
case short:
if (close < trail[1]) {
state = state.short;
trail = Min(trail[1], close + loss);
} else {
state = state.long;
trail = close - loss;
}
}
def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);
def ex = if BuySignal then high else if SellSignal then low else if state == state.long then Max(ex[1], high) else if state == state.short then Min(ex[1], low) else ex[1];
plot TrailingStop = trail;
TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
TrailingStop.DefineColor("Long", Color.GREEN);
TrailingStop.DefineColor("Short", Color.RED);
TrailingStop.SetLineWeight(5);
TrailingStop.AssignValueColor(if state == state.long
then TrailingStop.Color("Long")
else TrailingStop.Color("Short"));
#TrailingStop.hide();
plot Extremum = ex;
Extremum.SetPaintingStrategy(PaintingStrategy.POINTS);
Extremum.DefineColor("HH", Color.GREEN);
Extremum.DefineColor("LL", Color.RED);
Extremum.AssignValueColor(if state == state.long
then Extremum.Color("HH")
else Extremum.Color("LL"));
Extremum.Hide();
def f0 = ex + (trail - ex) * fib0Level / 100;
def f1 = ex + (trail - ex) * fib1Level / 100;
def f2 = ex + (trail - ex) * fib2Level / 100;
def f3 = ex + (trail - ex) * fib3Level / 100;
def f4 = ex + (trail - ex) * fib4Level / 100;
def f5 = ex + (trail - ex) * fib5Level / 100;
def f6 = ex + (trail - ex) * fib6Level / 100;
def f7 = ex + (trail - ex) * fib7Level / 100;
def l100 = trail + 0;
plot Fib0 = f0;
Fib0.SetPaintingStrategy(PaintingStrategy.dashes);
Fib0.DefineColor("Long", Color.Dark_Red);
Fib0.DefineColor("Short", Color.Dark_Green);
Fib0.AssignValueColor(if state == state.long
then Fib0.Color("Long")
else Fib0.Color("Short"));
Fib0.SetLineWeight(2);
plot Fib1 = f1;
Fib1.SetPaintingStrategy(PaintingStrategy.dashes);
Fib1.DefineColor("Long", Color.Dark_Red);
Fib1.DefineColor("Short", Color.Dark_Green);
Fib1.AssignValueColor(if state == state.long
then Fib1.Color("Long")
else Fib1.Color("Short"));
Fib1.SetLineWeight(2);
plot Fib2 = f2;
Fib2.SetPaintingStrategy(PaintingStrategy.dashes);
Fib2.DefineColor("Long", Color.Light_Red);
Fib2.DefineColor("Short", Color.Light_Green);
Fib2.AssignValueColor(if state == state.long
then Fib2.Color("Long")
else Fib2.Color("Short"));
plot Fib3 = f3;
Fib3.SetPaintingStrategy(PaintingStrategy.dashes);
Fib3.DefineColor("Long", Color.Light_Red);
Fib3.DefineColor("Short", Color.Light_Green);
Fib3.AssignValueColor(if state == state.long
then Fib3.Color("Long")
else Fib3.Color("Short"));
Fib3.SetLineWeight(1);
plot Fib4 = f4;
Fib4.SetPaintingStrategy(PaintingStrategy.points);
Fib4.SetDefaultColor(Color.White);
Fib4.SetLineWeight(1);
plot Fib5 = f5;
Fib5.SetPaintingStrategy(PaintingStrategy.dashes);
Fib5.DefineColor("Long", Color.Light_Green);
Fib5.DefineColor("Short", Color.Light_Red);
Fib5.AssignValueColor(if state == state.long
then Fib5.Color("Long")
else Fib5.Color("Short"));
Fib5.SetLineWeight(1);
plot Fib6 = f6;
Fib6.SetPaintingStrategy(PaintingStrategy.dashes);
Fib6.DefineColor("Long", Color.Light_Green);
Fib6.DefineColor("Short", Color.Light_Red);
Fib6.AssignValueColor(if state == state.long
then Fib6.Color("Long")
else Fib6.Color("Short"));
Fib6.SetLineWeight(2);
plot Fib7 = f7;
Fib7.SetPaintingStrategy(PaintingStrategy.dashes);
Fib7.DefineColor("Long", Color.Dark_Green);
Fib7.DefineColor("Short", Color.Dark_Red);
Fib7.AssignValueColor(if state == state.long
then Fib7.Color("Long")
else Fib7.Color("Short"));
Fib7.SetLineWeight(2);
AddCloud(f0, f1, Color.dark_Red, Color.Dark_Green, no);
AddCloud(f1, f2, Color.Red, Color.Green, no);
AddCloud(f2, f3, Color.Light_Red, Color.Light_Green, no);
AddCloud(f5, f6, Color.LIGHT_GREEN, Color.LIGHT_RED, no);
AddCloud(f6, f7, Color.GREEN, Color.RED, no);
AddCloud(f7, l100, Color.DARK_GREEN, Color.DARK_RED, no);
def l5 = state[1] == state.long and close crosses below f5[1];
def l6 = state[1] == state.long and close crosses below f6[1];
def l7 = state[1] == state.long and close crosses below f7[1];
def s5 = state[1] == state.short and close crosses above f5[1];
def s6 = state[1] == state.short and close crosses above f6[1];
def s7 = state[1] == state.short and close crosses above f7[1];
def atrSA = Average(TrueRange(high, close, low), 14);
plot LS1 = if l5 then low - atrSA else Double.NaN;
plot LS2 = if l6 then low - 1.5 * atrSA else Double.NaN;
plot LS3 = if l7 then low - 2 * atrSA else Double.NaN;
plot SS1 = if s5 then high + atrSA else Double.NaN;
plot SS2 = if s6 then high + 1.5 * atrSA else Double.NaN;
plot SS3 = if s7 then high + 2 * atrSA else Double.NaN;
LS1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LS1.SetDefaultColor(Color.GREEN);
LS1.SetLineWeight(1);
LS1.Hide();
LS2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LS2.SetDefaultColor(Color.GREEN);
LS2.SetLineWeight(1);
LS2.Hide();
LS3.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LS3.SetDefaultColor(Color.GREEN);
LS3.SetLineWeight(1);
LS3.Hide();
SS1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SS1.SetDefaultColor(Color.RED);
SS1.SetLineWeight(1);
SS1.Hide();
SS2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SS2.SetDefaultColor(Color.RED);
SS2.SetLineWeight(1);
SS2.Hide();
SS3.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SS3.SetDefaultColor(Color.RED);
SS3.SetLineWeight(1);
SS3.Hide();
#Alert(l1, "Price crossed below Fib5 level in long trend", Alert.BAR, Sound.Bell);
#Alert(l2, "Price crossed below Fib6 level in long trend", Alert.BAR, Sound.Bell);
#Alert(l3, "Price crossed below Fib7 level in long trend", Alert.BAR, Sound.Bell);
#Alert(s1, "Price crossed above Fib5 level in short trend", Alert.BAR, Sound.Bell);
#Alert(s2, "Price crossed above Fib6 level in short trend", Alert.BAR, Sound.Bell);
#Alert(s3, "Price crossed above Fib7 level in short trend", Alert.BAR, Sound.Bell);
# *******************************************************
# DAY TRADING SETTINGS USING 1 AND 5 MINUTE CHARTS
#AddLabel(yes, "Alt SA Period: " + aggregationPeriod/60000 +"m",color.WHITE);
AddLabel(yes, if price> TrailingStop then "BUY SUPPORT - BUY ZONES 5,6 or 7" else "SELL RESISTANCE - SELL ZONES 5,6 or 7", if price > TrailingStop then Color.GREEN else Color.Red);
# SWING TRADING SETTINGS USING 4 HOUR CHART ( needs work below )
AddLabel(yes," SWING TRADING STRATEGY : ",color.WHITE);
AddLabel(yes, if price> TrailingStop then "* IF * SWINGARM Is BULLISH - Wait For Entry Confirmation" else "* IF * SWINGARM - Is BEARISH - Wait For Entry Confirmation", if price> TrailingStop then Color.GREEN else Color.RED);
########### End of indicator code############