declare lower;
input ImedLength = 31; # orig std = 31
input MomentumLength = 5; # orig std = 31
input NearLength = 3; # orig std = 3
input length = 14;
input calcLength = 5;
input smoothLength = 3;
input fastLength = 6;
input slowLength = 13;
input MACDLength = 6;
input AverageTypeMACD = {SMA, default EMA, Wilders};
input price = close;
input displace = 0;
def MACD_Data = MACD(fastLength = fastLength, slowLength = slowLength, MACDLength = MACDLength);
def MACD_Line = MACD_Data;
def Value;
def Avg;
switch (AverageTypeMACD) {
case SMA:
Value = Average(price, fastLength) - Average(price, slowLength);
Avg = Average(Value, MACDLength);
case EMA:
Value = ExpAverage(price, fastLength) - ExpAverage(price, slowLength);
Avg = ExpAverage(Value, MACDLength);
case Wilders:
Value = WildersAverage(price, fastLength) - WildersAverage(price, slowLength);
Avg = ExpAverage(Value, MACDLength);
}
#plot BB;
#Bollinger BandsSMA,EMA
input AverageTypeBB = {default SMA, EMA, HMA};
input displaceBB = 0;
input lengthBB = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
def upperBand;
def lowerBand;
def midline;
switch (AverageTypeBB) {
case SMA:
upperBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up).UpperBand;
lowerBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up).LowerBand;
midline = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up).Midline;
case EMA:
upperBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).UpperBand;
lowerBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).LowerBand;
midline = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).Midline;
case HMA:
upperBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).UpperBand;
lowerBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).LowerBand;
midline = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).Midline;
}
def midline1 = midline;
def o = open;
def c = close;
def dataa = fold i = 0 to length
with s
do s + (if c > GetValue(o, i)
then 1
else if c < GetValue(o, i)
then - 1
else 0);
def EMA5 = ExpAverage(dataa, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);
def zero = if IsNaN(c) then Double.NaN else 0;
def ob = if IsNaN(c) then Double.NaN else Round(length * .7);
def os = if IsNaN(c) then Double.NaN else -Round(length * .7);
def c1I = close - Lowest(low, ImedLength);
def c2I = Highest(high, ImedLength) - Lowest(low, ImedLength);
def FastK_I = c1I / c2I * 100;
def c1N = close - Lowest(low, NearLength);
def c2N = Highest(high, NearLength) - Lowest(low, NearLength);
def FastK_N = c1N / c2N * 100;
def c1M = close - Lowest(low, MomentumLength);
def c2M = Highest(high, MomentumLength) - Lowest(low, MomentumLength);
def FastK_M = c1M / c2M * 100;
def Intermediate = Average(FastK_I, 5); # = TMF's GreenLine
def NearTerm = Average(FastK_N, 2); # = TMF's BlueLine
def Min1 = Min(low, low[1]);
def Min2 = Min(Min1, Min(low[2], low[3]));
def Max1 = Max(high, Max(high[1], Max(high[2], high[3])));
def momentum = ((close - Min1) / (Max1 - Min2)) * 100;
def bottomline = 0;
def topLine = 100;
def UpperRevZone = 80;
def LowerRevZone = 40;
def UpLimit = 120;
plot data = (Intermediate < LowerRevZone) and (Main > Signal) and (-length <= ob + 5) and (upperBand > upperBand[1] and lowerBand < lowerBand[1]);