#Four Independent Indicators with the Choice of 7 Moving Averages + VWAP
# VWAP only available for Indicator1 (ind1)
#==GLOBAL ====================
declare upper;
input aggPeriod = AggregationPeriod.DAY;
def nan = double.NaN;
#==INDICATOR 1-4 INPUTS====================
input selectAvg1 = {default "Select_an_Indicator1", "ExponentialMA", "HullMA", "SimpleMA", "TriangularMA", "VolWeightedMA", "VWAPenhanced", "WeightedMA", "WildersMA"};
#hint selectAvg1 : The following are only found in the 1st indicator: <li>VWAP</li>
input price1 = {default "Select_a_Price1", "close_", "high_", "low_", "open_"};
input length1 = 0;
input displace1 = 0;
input selectAvg2 = {default "Select an Indicator1", "ExponentialMA", "HullMA", "SimpleMA", "TriangularMA", "VolWeightedMA", "WeightedMA", "WildersMA"};
input price2 = {default "close_", "high_", "low_", "open_"};
input length2 = 0;
input displace2 = 0;
input selectAvg3 = {default "Select an Indicator1", "ExponentialMA", "HullMA", "SimpleMA", "TriangularMA", "VolWeightedMA", "WeightedMA", "WildersMA"};
input price3 = {default "close_", "high_", "low_", "open_"};
input length3 = 0;
input displace3 = 0;
input selectAvg4 = {default "Select an Indicator1", "ExponentialMA", "HullMA", "SimpleMA", "TriangularMA", "VolWeightedMA", "WeightedMA", "WildersMA"};
input price4 = {default "close_", "high_", "low_", "open_"};
input length4 = 0;
input displace4 = 0;
#==INDICATOR 1-4 DEFINED VARIABLES====================
def vPrice1;
def avg1;
def vPrice2;
def avg2;
def vPrice3;
def avg3;
def vPrice4;
def avg4;
#==INDICATOR 1-4 PLOTS====================
plot ind1 = avg1;
plot ind2 = avg2;
plot ind3 = avg3;
plot ind4 = avg4;
#==SETTING PRICE====================
if (price1 == price1.close_) {
vPrice1 = close;
} else {
if price1 == price1.high_ {
vPrice1 = high;
} else {
if price1 == price1.low_ {
vPrice1 = low;
} else {
if price1 == price1.open_ {
vPrice1 = open;
} else {
vPrice1 = nan;
}}}}
if (price2 == price2.close_) {
vPrice2 = close;
} else {
if price2 == price2.high_ {
vPrice2 = high;
} else {
if price2 == price2.low_ {
vPrice2 = low;
} else {
if price2 == price2.open_ {
vPrice2 = open;
} else {
vPrice2 = nan;
}}}}
if (price3 == price3.close_) {
vPrice3 = close;
} else {
if price3 == price3.high_ {
vPrice3 = high;
} else {
if price3 == price3.low_ {
vPrice3 = low;
} else {
if price3 == price3.open_ {
vPrice3 = open;
} else {
vPrice3 = nan;
}}}}
if (price4 == price4.close_) {
vPrice4 = close;
} else {
if price4 == price4.high_ {
vPrice4 = high;
} else {
if price4 == price4.low_ {
vPrice4 = low;
} else {
if price4 == price4.open_ {
vPrice4 = open;
} else {
vPrice4 = nan;
}}}}
#==SCRIPTS====================
script enhVWAP {
# Inspiration: VWAP with period - Assembled by BenTen at useThinkScript.com
# Found at: https://usethinkscript.com/threads/enhanced-vwap-indicator-for-thinkorswim.806/
input vwapLength = 0;
def vhigh = high;
def vlow = low;
def vclose = close;
def typicalPrice = (vhigh + vlow + vclose) / 3;
def typicalPriceVolume = typicalPrice * volume;
def cumulativeTypicalPriceVolume = Sum(typicalPriceVolume, vwapLength);
def cumulativeVolume = Sum(volume, vwapLength);
def vwapValue = cumulativeTypicalPriceVolume / cumulativeVolume;
plot warp = vwapValue;
}
#==CONDITIONALS====================
if selectAvg1 == selectAvg1.ExponentialMA {
# plot ind1 = MovingAverage(AverageType.EXPONENTIAL, Fundamental(vPrice1[-displace1], period=aggPeriod), length=length1);
avg1 = MovAvgExponential(price=vPrice1, length=length1, displace=displace1);
} else {
if selectAvg1 == selectAvg1.VWAPenhanced {
avg1 = enhVWAP(length1) / length1;
} else {
if selectAvg1 == selectAvg1.SimpleMA {
avg1 = SimpleMovingAvg(price=vPrice1, length=length1, displace=displace1);
} else {
if selectAvg1 == selectAvg1.HullMA {
avg1 = HullMovingAvg(price=vPrice1, length=length1, displace=displace1);
} else {
if selectAvg1 == selectAvg1.WeightedMA {
avg1 = MovAvgWeighted(price=vPrice1, length=length1, displace=displace1);
} else {
if selectAvg1 == selectAvg1.WildersMA {
avg1 = WildersAverage(data=vPrice1[-displace1], length=length1);
} else {
if selectAvg1 == selectAvg1.TriangularMA {
avg1 = MovAvgTriangular(price=vPrice1[-displace1], length=length1, displace=displace1);
} else {
if selectAvg1 == selectAvg1.VolWeightedMA {
avg1 = Sum(data=(volume * vPrice1[-displace1]), length=length1) / Sum(data=volume[-displace1], length=length1);
} else {
avg1 = nan;
}}}}}}}}
if selectAvg2 == selectAvg2.ExponentialMA {
avg2 = MovAvgExponential(price=vPrice2, length=length2, displace=displace2);
} else {
if selectAvg2 == selectAvg2.SimpleMA {
avg2 = SimpleMovingAvg(price=vPrice2, length=length2, displace=displace2);
} else {
if selectAvg2 == selectAvg2.HullMA {
avg2 = HullMovingAvg(price=vPrice2, length=length2, displace=displace2);
} else {
if selectAvg2 == selectAvg2.WeightedMA {
avg2 = MovAvgWeighted(price=vPrice2, length=length2, displace=displace2);
} else {
if selectAvg2 == selectAvg2.WildersMA {
avg2 = WildersAverage(data=vPrice2[-displace2], length=length2);
} else {
if selectAvg2 == selectAvg2.TriangularMA {
avg2 = MovAvgTriangular(price=vPrice2[-displace2], length=length2, displace=displace2);
} else {
if selectAvg2 == selectAvg2.VolWeightedMA {
avg2 = Sum(data=(volume * vPrice2[-displace2]), length=length2) / Sum(data=volume[-displace2], length=length2);
} else {
avg2 = nan;
}}}}}}}
if selectAvg3 == selectAvg3.ExponentialMA {
avg3 = MovAvgExponential(price=vPrice3, length=length3, displace=displace3);
} else {
if selectAvg3 == selectAvg3.SimpleMA {
avg3 = SimpleMovingAvg(price=vPrice3, length=length3, displace=displace3);
} else {
if selectAvg3 == selectAvg3.HullMA {
avg3 = HullMovingAvg(price=vPrice3, length=length3, displace=displace3);
} else {
if selectAvg3 == selectAvg3.WeightedMA {
avg3 = MovAvgWeighted(price=vPrice3, length=length3, displace=displace3);
} else {
if selectAvg3 == selectAvg3.WildersMA {
avg3 = WildersAverage(data=vPrice3[-displace3], length=length3);
} else {
if selectAvg3 == selectAvg3.TriangularMA {
avg3 = MovAvgTriangular(price=vPrice3[-displace3], length=length3, displace=displace3);
} else {
if selectAvg3 == selectAvg3.VolWeightedMA {
avg3 = Sum(data=(volume * vPrice3[-displace3]), length=length3) / Sum(data=volume[-displace3], length=length3);
} else {
avg3 = nan;
}}}}}}}
if selectAvg4 == selectAvg4.ExponentialMA {
avg4 = MovAvgExponential(price=vPrice4, length=length4, displace=displace4);
} else {
if selectAvg4 == selectAvg4.SimpleMA {
avg4 = SimpleMovingAvg(price=vPrice4, length=length4, displace=displace4);
} else {
if selectAvg4 == selectAvg4.HullMA {
avg4 = HullMovingAvg(price=vPrice4, length=length4, displace=displace4);
} else {
if selectAvg4 == selectAvg4.WeightedMA {
avg4 = MovAvgWeighted(price=vPrice4, length=length4, displace=displace4);
} else {
if selectAvg4 == selectAvg4.WildersMA {
avg4 = WildersAverage(data=vPrice4[-displace4], length=length4);
} else {
if selectAvg4 == selectAvg4.TriangularMA {
avg4 = MovAvgTriangular(price=vPrice4[-displace4], length=length4, displace=displace4);
} else {
if selectAvg4 == selectAvg4.VolWeightedMA {
avg4 = Sum(data=(volume * vPrice4[-displace4]), length=length4) / Sum(data=volume[-displace4], length=length4);
} else {
avg4 = nan;
}}}}}}}
#==END====================