Author Message:
The Squeeze & Release by Algo Alert is an innovative tool designed to capture price volatility dynamics using a combination of EMA-based calculations and ATR principles. This script aims to provide traders with clear visual cues to spot potential market squeezes and release scenarios.
More details: https://www.tradingview.com/v/2GQIc9Ms/
CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0
#// © Algo_Alert
#indicator(title="Squeeze & Release [Algo Alert]", shorttitle="?&? [Algo Alert]", overlay=false, timeframe="",
# Converted by Sam4Cok@Samer800 - 11/2023
declare lower;
input colorBars = yes;
input CalculationPeriod = 14; # "Calculation Period"
input SmoothingLength = 7; # "Smoothing Length"
input HyperSqueezeDetectionLength = 5; # "Hyper Squeeze Detection Length"
input applySmoothing = yes;
def na = Double.NaN;
def last = IsNaN(close);
DefineGlobalColor("green", CreateColor(0, 135, 255));# "Release Color"
DefineGlobalColor("red", CreateColor(255, 17, 0));# "Squeeze Color"
script rising{
input src = close;
input len = 3;
def cnt = fold i = 0 to len with p do
if src[i] > GetValue(src, i + 1) then p + 1 else p;
plot out = cnt == len;
}
def HiLo = high - low;
def tr = TrueRange(high, close, low);
def a = ExpAverage(tr, CalculationPeriod);
def ama = ExpAverage(a, CalculationPeriod * 2);
def v = ama - a;
def difEMA = ExpAverage(HiLo, CalculationPeriod * 2);
def svRegular = v / difEMA * 100;
def svSmooth = ExpAverage(svRegular, SmoothingLength);
def sv_ = if applySmoothing then svSmooth else svRegular;
def sv = sv_;
def svma = ExpAverage(sv, CalculationPeriod);
def crossUp = Crosses(sv, svma, CrossingDirection.ABOVE);
def crossDn = Crosses(sv, svma, CrossingDirection.BELOW);
def raise = sv > 0 and rising(sv, HyperSqueezeDetectionLength);
#== PLot
plot ma = svma;
ma.SetDefaultColor(Color.GRAY);
plot val = sv; # "ATR"
val.AssignValueColor(if sv > svma then GlobalColor("red") else GlobalColor("green"));
plot mid = if last then na else 0;
mid.SetPaintingStrategy(PaintingStrategy.POINTS);
mid.AssignValueColor(if raise then Color.WHITE else Color.DARK_GRAY);
plot SigUp = if crossUp then svma - 10 else na;#, "Squeeze"
plot SigDn = if crossDn then svma + 10 else na;#, "Release"
SigUp.SetPaintingStrategy(PaintingStrategy.SQUARES);
SigDn.SetPaintingStrategy(PaintingStrategy.SQUARES);
SigUp.SetDefaultColor(GlobalColor("red"));
SigDn.SetDefaultColor(GlobalColor("green"));
def fillcol = ma + (val - ma)/2;
AddCloud(val, fillcol, GlobalColor("red"), GlobalColor("green"));
#-- Bar Color
def col = if sv > 0 then
if sv > svma then 2 else 1 else
if sv < 0 then
if sv < svma then -2 else -1 else 0;
AssignPriceColor(if !colorBars then Color.CURRENT else
if col==2 then Color.GREEN else
if col==1 then Color.DARK_GREEN else
if col==-2 then Color.RED else
if col==-1 then Color.DARK_RED else Color.GRAY);
#-- END of CODE