####SLM_MTF_PullBack
####Longterm Time Frame
input applyCloud = yes;
input LT_TimeFrame = AggregationPeriod.Week;
input lengthLT =8;
input averageTypeLT = { Simple, default Exponential, Weighted, Wilders, Hull};
plot maLT = MovingAverage(averageType = averageTypeLT, close(period = LT_TimeFrame), lengthLT);
maLT.SetDefaultColor(COlor.Dark_green);
input lengthLT1 = 13;
input averageTypeLT1 = {Simple,default Exponential, Weighted, Wilders, Hull};
plot maLT1 = MovingAverage(averageType = averageTypeLT1, close(period = LT_TimeFrame), lengthLT1);
maLT1.SetDefaultColor(COlor.blue);
input lengthLT2 = 21;
input averageTypeLT2 = {Simple, default Exponential, Weighted, Wilders, Hull};
plot maLT2 = MovingAverage(averageType = averageTypeLT2, close(period = LT_TimeFrame), lengthLT2);
maLT2.SetDefaultColor(COlor.Dark_Red);
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Neutral", Color.Gray);
DefineGlobalColor("Bearish", Color.RED);
#-------------- Define the Momentum
def bullishMomentum = maLT > maLT1 and maLT1 > maLT2 ;
def bearishMomentum = maLT < maLT1 and maLT1 < maLT2 ;
#-------------- do some plots
Plot Superfast = if applyCloud then maLT else Double.NaN;
Superfast.AssignValueColor(if bullishMomentum then GlobalColor("Bullish") else if bearishMomentum then GlobalColor("Bearish") else GlobalColor("Neutral"));
Superfast.HideBubble();
plot Fast = if applyCloud then maLT1 else Double.NaN;
Fast.AssignValueColor(if bullishMomentum then GlobalColor("Bullish") else if bearishMomentum then GlobalColor("Bearish") else GlobalColor("Neutral"));
Fast.HideBubble();
plot Slow = if applyCloud then maLT2 else Double.NaN;
Slow.AssignValueColor(if bullishMomentum then GlobalColor("Bullish") else if bearishMomentum then GlobalColor("Bearish") else GlobalColor("Neutral"));
Slow.HideBubble();
AddCloud(if applyCloud and bullishMomentum then Superfast else Fast, if bullishMomentum then Slow else Fast, GlobalColor("Bullish") , GlobalColor("Bearish"));
AddCloud(if applyCloud and bearishMomentum then Slow else Fast, if bearishMomentum then Superfast else Fast, GlobalColor("Bearish"), GlobalColor("Neutral"));
AddCloud(if applyCloud and !bullishMomentum and !bearishMomentum then max(max(Fast, Slow), SuperFast) else Fast, if !bullishMomentum and !bearishMomentum then min(min(Fast, Superfast), Slow) else Fast, GlobalColor("Neutral"), GlobalColor("Neutral"));
#####Shortterm Time Frame
input length =8;
input averageType = { Simple, default Exponential, Weighted, Wilders, Hull};
plot ma = MovingAverage(averageType = averageType, close, length);
ma.SetDefaultColor(COlor.green);
input length1 = 13;
input averageType1 = {Simple,default Exponential, Weighted, Wilders, Hull};
plot ma1 = MovingAverage(averageType = averageType1, close, length1);
ma1.SetDefaultColor(COlor.cyan);
input length2 = 21;
input averageType2 = {Simple, default Exponential, Weighted, Wilders, Hull};
plot ma2 = MovingAverage(averageType = averageType2, close, length2);
ma2.SetDefaultColor(COlor.Red);
input alertonclose = yes;
def state = {default flat, long, short};
switch (state[1]) {
case flat:
state = if MA1 > MA2 and low[1] > MA1
and low <= MA1 and low >= MA2 then state.long
else if MA2 > MA1 and high[1] < MA1 and high >= MA1 and high <= MA2 then state.short else state.flat;
case long:
state = if maLT > maLT1 and maLT1 > maLT2 and low <= MA2 then state.flat else state.long;
case short:
state = if maLT < maLT1 and maLT1 < maLT2 and high >= MA2 then state.flat else state.short;
}
plot BuyDot = if maLT > maLT1 and maLT1 > maLT2 and state==state.long and state[1] != state.long
or maLT > maLT1 and maLT1 > maLT2 and ma > ma1 and ma1 > ma2 and low <= ma1 and low > ma2
then low else Double.NaN;
BuyDot.SetPaintingStrategy(PaintingStrategy.arroW_Up);
BuyDot.SetLineWeight(3);
BuyDot.SetDefaultColor(Color.Dark_GREEN);
BuyDot.HideBubble();
AddVerticalLine (BuyDot, "", Color.Dark_Green);
Alert(BuyDot, "SLM_MTF_PullBack Down", Alert.BAR, Sound.Ring);
plot SellDot = if maLT < maLT1 and maLT1 < maLT2 and state==state.short and state[1] != state.short
or maLT < maLT1 and maLT1 < maLT2 and ma < ma1 and ma1 < ma2 and high >= ma1 and high < ma2
then high else Double.NaN;
SellDot.SetPaintingStrategy(PaintingStrategy.arroW_DOWN);
SellDot.SetLineWeight(3);
SellDot.SetDefaultColor(Color.Dark_Red);
SellDot.HideBubble();
AddVerticalLine (SellDot, "", Color.Dark_Red);
Alert(SellDot, "SLM_MTF_PullBack Down", Alert.BAR, Sound.Chimes);