Squeeze Clouds based on SMA and VWAP

germanburrito

Active member
These clouds consist of a deviation scaled sma, as well as a vwap scaled sma, these clouds may act as support and resistance because of the nature of being weighted by volume and standard deviation of set period, when the bands squeeze it may indicate a reversal or a weakening trend, when the bands expand the opposite is true.

3OepiaK.png


Code:
# Nube 6.24.19

# German_burrito



input length = 24;

input price  = vwap;
input length2 = 34;

def p = if IsNaN(price) then p[1] else price;
def v = if IsNaN(volume) then v[1] else volume;
def zeros = close - close[2];
def filter = reference EhlersSuperSmootherFilter(price = zeros, "cutoff length" = 0.5 * length2);
def rms = Sqrt(Average(Sqr(filter), length2));
def scaledFilter = filter / rms;
def alpha = 5 * AbsValue(scaledFilter) / length2;
def deviationScaledMovAvg = CompoundValue(1, alpha * close + (1 - alpha) * deviationScaledMovAvg[1], close);

plot DSMA = deviationScaledMovAvg;
DSMA.SetDefaultColor(GetColor(1));


plot VWAP = if IsNaN(price) then Double.NaN else 

             Sum(p * v, length) / Sum(v, length);

addCloud(dsma, vwap, color.green, color.red);
dsma.AssignValueColor(if dsma > vwap
                           then color.green
                           else color.red);
     vwap.AssignValueColor(if dsma > vwap
                             then color.green
                             else color.red);
 
Last edited:
When I copy and paste it gives me few errors in red . I delete those red code and it worked .
 
Hello German, I found that if I use a longer length as the first length and a shorter length as the second, the indicator worked better, I also used Fib lengths.

anyway, I converted your indicator into a binary w 3 MTF the red & green squares are a consensus vote

Here is the code

Code:
###############
Declare Lower;
DefineGlobalColor("Bullish", Color.Cyan);
DefineGlobalColor("Bearish", Color.Magenta);
DefineGlobalColor("Buy", Color.Green);
DefineGlobalColor("Sell", Color.Red);

input agg1 = AggregationPeriod.FIVE_MIN;
input agg2 = AggregationPeriod.Thirty_MIN;
input agg3 = AggregationPeriod. Hour;
input length = 21;
input length2 = 8;
input show_dots=yes;
input DotSize = 3;
Def AC = Close(Period = Agg1);
Def BC = Close(Period = Agg2);
Def CC = Close(Period = Agg3);
Def Avwap = vwap(Period = Agg1);
Def Bvwap = vwap(Period = Agg2);
Def Cvwap = vwap(Period = Agg3);
Def AV = Volume(Period = Agg1);
Def BV = Volume(Period = Agg2);
Def CV = Volume(Period = Agg3);
def zerosa = AC - AC[2];
def zerosb = BC - BC[2];
def zerosc = CC - CC[2];
def filtera = reference EhlersSuperSmootherFilter(price = zerosa, "cutoff length" = 0.5 * length2);
def filterb = reference EhlersSuperSmootherFilter(price = zerosb, "cutoff length" = 0.5 * length2);
def filterc = reference EhlersSuperSmootherFilter(price = zerosc, "cutoff length" = 0.5 * length2);
def A_rms = Sqrt(Average(Sqr(filtera), length2));
def B_rms = Sqrt(Average(Sqr(filterb), length2));
def C_rms = Sqrt(Average(Sqr(filterc), length2));
def scaledFilterA = filtera / A_rms;
def scaledFilterB = filterb / B_rms;
def scaledFilterC = filterc / C_rms;
def A_alpha = 5 * AbsValue(scaledFilterA) / length2;
def B_alpha = 5 * AbsValue(scaledFilterB) / length2;
def C_alpha = 5 * AbsValue(scaledFilterC) / length2;
def A_deviationScaledMovAvg = CompoundValue(1, A_alpha * AC + (1 – A_alpha) * A_deviationScaledMovAvg[1], AC);
def B_deviationScaledMovAvg = CompoundValue(1, B_alpha * BC + (1 – B_alpha) * B_deviationScaledMovAvg[1], BC);
def C_deviationScaledMovAvg = CompoundValue(1, C_alpha * CC + (1 – C_alpha) * C_deviationScaledMovAvg[1], CC);
def A_DSMA = A_deviationScaledMovAvg;
def B_DSMA = B_deviationScaledMovAvg;
def C_DSMA = C_deviationScaledMovAvg;
def A_p = if IsNaN(Avwap) then A_p[1] else Avwap;
def B_p = if IsNaN(Bvwap) then B_p[1] else Bvwap;
def C_p = if IsNaN(Cvwap) then C_p[1] else Cvwap;
def A_v = if IsNaN(AV) then A_v[1] else AV;
def B_v = if IsNaN(BV) then B_v[1] else BV;
def C_v = if IsNaN(CV) then C_v[1] else CV;

def A_VWAP = if IsNaN(Avwap) then Double.NaN else
             Sum(A_p * A_v, length) / Sum(A_v, length);
def B_VWAP = if IsNaN(Bvwap) then Double.NaN else
             Sum(B_p * B_v, length) / Sum(B_v, length);
def C_VWAP = if IsNaN(Cvwap) then Double.NaN else
             Sum(C_p * C_v, length) / Sum(C_v, length);
def ComboBuy = (A_DSMA> A_VWAP) + (B_DSMA> B_VWAP) + (C_DSMA> C_VWAP);
def ComboSell = (A_DSMA< A_VWAP) + (B_DSMA< B_VWAP) + (C_DSMA< C_VWAP);
plot A_Dot = if IsNaN(AC) then Double.NaN else 1;
A_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A_Dot.SetLineWeight(DotSize);
A_Dot.AssignValueColor(if A_DSMA > A_VWAP then GlobalColor("Bullish") else  GlobalColor("Bearish"));
plot B_Dot = if IsNaN(BC) then Double.NaN else 2;
B_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
B_Dot.SetLineWeight(DotSize);
B_Dot.AssignValueColor(if B_DSMA > B_VWAP then GlobalColor("Bullish") else  GlobalColor("Bearish"));
plot C_Dot = if IsNaN(AC) then Double.NaN else 3;
C_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
C_Dot.SetLineWeight(DotSize);
C_Dot.AssignValueColor(if C_DSMA > C_VWAP then GlobalColor("Bullish") else  GlobalColor("Bearish"));
plot Combo_Dot = 4;
Combo_Dot.SetPaintingStrategy(PaintingStrategy.SQUARES);
Combo_Dot.SetLineWeight(lineWeight = 4);
Combo_Dot.AssignValueColor ( if ComboSell >ComboBuy then GlobalColor("Sell") else GlobalColor("Buy"));
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
168 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top