
Author Message:
The High-Low Cloud Trend - ChartPrime indicator, combines the concepts of trend following and mean reversion into a dynamic cloud representation. This indicator constructs high and low bands based on lookback periods, which adjust dynamically to reflect market conditions. By highlighting the upper and lower extremes, it provides a visual gauge for potential reversals and continuation points.
CODE:
CSS:
#// Indicator for TOS
#// © ChartPrime
#indicator("High-Low Cloud Trend [ChartPrime]", overlay = true, max_labels_count = 500)
# Converted by Sam4Cok@Samer800 - 09/2024
input timeframe = AggregationPeriod.MIN;
input colorBars = yes;
input LookbackPeriod = 35; # "Lookback Period"
input showMeanReversionPoints = yes; # "Mean Reversion Points"
def na = Double.NaN;
def current = GetAggregationPeriod();
def tf = Max(current, timeframe);
#// Calculate the highest and lowest over the lookback period
def highest = Highest(high(Period = tf), LookbackPeriod); # // Highest high over the lookback period
def lowest = Lowest(low(Period = tf), LookbackPeriod); # // Lowest low over the lookback period
#// Calculate the highest and lowest over a shorter period (1/3 of the original period)
def highest1 = Highest(high(Period = tf), LookbackPeriod / 4); # // Highest high over the shortened lookback period
def lowest1 = Lowest(low(Period = tf), LookbackPeriod / 4); # // Lowest low over the shortened lookback period
#// Logic to update the 'value' variable based on certain conditions
def state = {default "ini", "HHLL"};
def value;
switch (state[1]) {
case "HHLL" :
value = if low(Period = tf) == lowest then highest else
if high(Period = tf) == highest then lowest else value[1];
state = state[1];
default :
value = na;
state = state."HHLL";
}
#// Determine the 'band' value based on the relationship between 'close' and 'value'
def band = if close > value then lowest else highest;
def band1 = if close > value then lowest1 else highest1;
#// Determine the color based on the relationship between 'close' and 'value'
def col = close > value;
def cross = (close Crosses band);
#-- plots
#// Plot a diamond shape at the 'band' value when there's a cross between 'close' and 'band'
plot diaCross = if cross[1] then band else na;
plot p1 = if cross then na else band;
def p2 = band1;
diaCross.SetPaintingStrategy(PaintingStrategy.SQUARES);
diaCross.AssignValueColor(if col then Color.GREEN else Color.RED);
p1.AssignValueColor(if col then Color.GREEN else Color.RED);
AddCloud(p1, p2, Color.DARK_RED, Color.DARK_GREEN);
#// Mean Reversion Conditions
def hCross = (high Crosses Below band1[1]);
def lCross = (low Crosses Above band1[1]);
def mean_rev_dn = hCross and band1[1]==high(Period=tf)[1] and high(Period=tf)!= band1 and !cross and band[1]==band;
def mean_rev_up = lCross and band1[1]==low(Period=tf)[1] and low(Period=tf)!= band1 and !cross and band[1]==band;
plot meanDn = if mean_rev_dn[-1] and showMeanReversionPoints then high else na;
plot meanUp = if mean_rev_up[-1] and showMeanReversionPoints then low else na;
meanDn.SetDefaultColor(Color.MAGENTA);
meanUp.SetDefaultColor(Color.CYAN);
meanDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
meanUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
# bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
if col then Color.DARK_GREEN else Color.DARK_RED);
#-- END of CODE