#INPUTS
#==============================================================================================
input iAggregationPeriod = AggregationPeriod.four_hours;
input iHideMidLinePrimary = no;
input iDisplacePrimary = 0;
input iFactorPrimary = 1.5;
input iLengthPrimary = 20;
input iPricePrimary = {OPEN, HIGH, LOW, default CLOSE, HL2, HLC3, OHLC4};
input iAvgTypePrimary = AverageType.SIMPLE;
input iTrueRangeAvgTypePrimary = AverageType.SIMPLE;
input iDisplace = 0;
input iFactor = 1.8;
input iLength = 20;
input iPrice = {OPEN, HIGH, LOW, default CLOSE, HL2, HLC3, OHLC4};
input iAvgType = AverageType.SIMPLE;
input iTrueRangeAvgType = AverageType.SIMPLE;
#VARS & LOGIC
#==============================================================================================
def vShiftPrimary = iFactorPrimary * MovingAverage(iTrueRangeAvgTypePrimary,
TrueRange(high(period = iAggregationPeriod),
close(period = iAggregationPeriod),
low(period = iAggregationPeriod)),
iLengthPrimary);
def vAveragePrimary;
if iPricePrimary == iPricePrimary.OPEN
then {
vAveragePrimary = MovingAverage(iAvgTypePrimary, open(period = iAggregationPeriod), iLengthPrimary);
}
else if iPricePrimary == iPricePrimary.HIGH
then {
vAveragePrimary = MovingAverage(iAvgTypePrimary, high(period = iAggregationPeriod), iLengthPrimary);
}
else if iPricePrimary == iPricePrimary.LOW
then {
vAveragePrimary = MovingAverage(iAvgTypePrimary, low(period = iAggregationPeriod), iLengthPrimary);
}
else if iPricePrimary == iPricePrimary.CLOSE
then {
vAveragePrimary = MovingAverage(iAvgTypePrimary, close(period = iAggregationPeriod), iLengthPrimary);
}
else if iPricePrimary == iPricePrimary.HL2
then {
vAveragePrimary = MovingAverage(iAvgTypePrimary, hl2(period = iAggregationPeriod), iLengthPrimary);
}
else if iPricePrimary == iPricePrimary.HLC3
then {
vAveragePrimary = MovingAverage(iAvgTypePrimary, hlc3(period = iAggregationPeriod), iLengthPrimary);
}
else if iPricePrimary == iPricePrimary.OHLC4
then {
vAveragePrimary = MovingAverage(iAvgTypePrimary, ohlc4(period = iAggregationPeriod), iLengthPrimary);
}
else {
vAveragePrimary = Double.NaN;
}
#MACD Primer Cloud
#==============================================================================================
def c = close(period = iAggregationPeriod);
input fastLength0 = 12;
input slowLength0 = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
plot ZeroLine = 0;
zeroline.hide();
def Value = MovingAverage(averageType, c, fastLength0) - MovingAverage(averageType, c, slowLength0);
def Avg0 = MovingAverage(averageType, Value, MACDLength);
def Diff = Value - Avg0;
#PLOTS
#==============================================================================================
plot pAvgPrimary = vAveragePrimary[-iDisplacePrimary];
#pAvgPrimary.hide();
plot pUpperBandPrimary = vAveragePrimary[-iDisplacePrimary] + vShiftPrimary[-iDisplacePrimary];
pUpperBandPrimary.SetDefaultColor(color.gray);
plot pLowerBandPrimary = vAveragePrimary[-iDisplacePrimary] - vShiftPrimary[-iDisplacePrimary];
pLowerBandPrimary.SetDefaultColor(color.gray);
pAvgPrimary.AssignValueColor(color.white);
pAvgPrimary.SetLineWeight(1);
pAvgPrimary.SetStyle(Curve.short_DASH);
#CLOUDS
#==============================================================================================
Addcloud(if value > zeroline then double.nan else plowerBandPrimary, pavgPrimary, color.black, color.black);
AddCloud(if value > Zeroline and value > avg0 then Double.NaN else plowerBandPrimary, pavgprimary, color.red, color.red);
AddCloud(if value > Zeroline and value < avg0 then Double.NaN else plowerBandPrimary, pavgprimary, color.green, color.green);
Addcloud(if value < zeroline then double.nan else pavgPrimary, pupperBandPrimary, color.black, color.black);
AddCloud(if value < Zeroline and value < avg0 then Double.NaN else pavgprimary, pupperBandPrimary, color.green, color.green);
AddCloud(if value < Zeroline and value > avg0 then Double.NaN else pavgprimary, pupperBandPrimary, color.red, color.red);