This is an adaptation of the Deviation Trend Profile converted from Tradingview to Thinkorswim.
Original Link: https://www.tradingview.com/script/6Wr1CEuo-Deviation-Trend-Profile-BigBeluga/
A statistical trend analysis tool that combines moving average dynamics with standard deviation zones and trend-specific price distribution.
The shaded areas are the 3-4 standard deviation from a moving average (default 50 SMA). Notice in the below picture of /GC on the four-hour timeframe, price was rejected every single time when it hit the ±4 levels.
Color Candles can be turned on/off in settings and align with the Standard Deviation Zones.
If you would like a WATCHLIST, then use the below code.
Original Link: https://www.tradingview.com/script/6Wr1CEuo-Deviation-Trend-Profile-BigBeluga/
A statistical trend analysis tool that combines moving average dynamics with standard deviation zones and trend-specific price distribution.
- Standard Deviation Zones: Calculates ±1, ±2, ±3 and ±4 levels from the SMA using ATR, forming dynamic envelopes around the mean.
The shaded areas are the 3-4 standard deviation from a moving average (default 50 SMA). Notice in the below picture of /GC on the four-hour timeframe, price was rejected every single time when it hit the ±4 levels.
Color Candles can be turned on/off in settings and align with the Standard Deviation Zones.
Code:
# Deviation Trend Profile [BigBeluga] - Thinkorswim Adaptation
# Converted from Pine Script v6
# Box plotting omitted (not supported in Thinkorswim)
# Assembled by Chewie 08/2025
input ColorBar = yes;
input length = 50;
input mult1 = 1;
input mult2 = 2;
input mult3 = 3;
input mult4 = 4;
input atrLength = 200;
input showTrendSignals = yes;
input averageType = AverageType.Simple;
# Theme colors
DefineGlobalColor("UpColor", Color.CYAN);
DefineGlobalColor("DownColor", Color.RED);
# Core calculations
def avg = movingAverage(averageType, close, length);
def atr = Average(TrueRange(high, close[1], low), atrLength);
def stdv1 = avg + atr * mult1;
def stdv2 = avg + atr * mult2;
def stdv3 = avg + atr * mult3;
def stdv4 = avg + atr * mult4;
def stdv_1 = avg - atr * mult1;
def stdv_2 = avg - atr * mult2;
def stdv_3 = avg - atr * mult3;
def stdv_4 = avg - atr * mult4;
# SMA slope
def avgDiff = avg - avg[5];
# Normalize slope for color intensity
def maxSlope = Highest(avgDiff, 500);
def minSlope = Lowest(avgDiff, 500);
def avgColNorm = if maxSlope != minSlope then (avgDiff - minSlope) / (maxSlope - minSlope) else 0;
# Gradient color simulation
def slopeUp = avgColNorm > 0.4;
def slopeDn = avgColNorm < 0.4;
# Trend detection
def trend = CompoundValue(1,
if avgColNorm crosses above 0.55 then 1
else if avgColNorm crosses below 0.45 then 0
else trend[1], 0);
# Plotting deviation lines
plot pStdv1 = stdv1;
plot pStdv2 = stdv2;
plot pStdv3 = stdv3;
plot pStdv4 = stdv4;
plot pStdv_1 = stdv_1;
plot pStdv_2 = stdv_2;
plot pStdv_3 = stdv_3;
plot pStdv_4 = stdv_4;
pStdv4.setlineWeight(2);
pStdv_4.setlineWeight(2);
pStdv1.SetDefaultColor(Color.LIGHT_GRAY);
pStdv2.SetDefaultColor(Color.dark_orange);
pStdv3.SetDefaultColor(Color.red);
pStdv4.SetDefaultColor(Color.magenta);
pStdv_1.SetDefaultColor(Color.LIGHT_GRAY);
pStdv_2.SetDefaultColor(Color.LIGHT_GREEN);
pStdv_3.SetDefaultColor(Color.GREEN);
pStdv_4.SetDefaultColor(Color.CYAN);
AddCloud(pStdv_3, pStdv_4, COLOR.dark_green, COLOR.gray);
AddCloud(pStdv3, pStdv4, COLOR.gray, COLOR.dark_red);
# Plot average with dynamic color
plot pAvg = avg;
#pAvg.AssignValueColor(
# if slopeUp then GlobalColor("UpColor")
# else if slopeDn then GlobalColor("DownColor")
# else Color.GRAY);
PAvg.assignvalueColor(if PAvg < PAvg[3] then color.red else color.green);
pAvg.SetLineWeight(2);
# Trend markers
AddChartBubble(showTrendSignals and trend crosses above 0.4, avg, "UpT", GlobalColor("UpColor"), no);
AddChartBubble(showTrendSignals and trend crosses below 0.4, avg, "DnT", GlobalColor("DownColor"), yes);
AssignPriceColor(if !ColorBar then Color.CURRENT else if low < pstdv_4 then color.cyan else if high > pstdv4 then color.magenta else if close > pstdv_2 and close < pstdv_1 then color.light_green else if close > pstdv_3 and close < pstdv_2 then color.green else if close > pstdv_4 and close < pstdv_3 then color.dark_green else if low < pstdv_4 then color.cyan else if close < pstdv4 and close > pstdv3 then color.dark_red else if close < pstdv3 and close > pstdv2 then color.red else if close > pstdv1 and close < pstdv2 then color.dark_orange else if close < pstdv2 and close > pavg then color.gray else if close < pavg and close > pstdv_2 then color.gray else Color.dark_gray);
# END CODE
If you would like a WATCHLIST, then use the below code.
Code:
# WATCHLIST Deviation Trend Profile [BigBeluga] - Thinkorswim Adaptation
# Converted from Pine Script v6
# Box plotting omitted (not supported in Thinkorswim)
# Assembled by Chewie 08/2025
input ColorBar = yes;
input length = 50;
input mult1 = 1;
input mult2 = 2;
input mult3 = 3;
input mult4 = 4;
input atrLength = 200;
input showTrendSignals = yes;
input averageType = AverageType.Simple;
# Theme colors
DefineGlobalColor("UpColor", Color.CYAN);
DefineGlobalColor("DownColor", Color.RED);
# Core calculations
def avg = movingAverage(averageType, close, length);
def atr = Average(TrueRange(high, close[1], low), atrLength);
def stdv1 = avg + atr * mult1;
def stdv2 = avg + atr * mult2;
def stdv3 = avg + atr * mult3;
def stdv4 = avg + atr * mult4;
def stdv_1 = avg - atr * mult1;
def stdv_2 = avg - atr * mult2;
def stdv_3 = avg - atr * mult3;
def stdv_4 = avg - atr * mult4;
# SMA slope
def avgDiff = avg - avg[5];
# Normalize slope for color intensity
def maxSlope = Highest(avgDiff, 500);
def minSlope = Lowest(avgDiff, 500);
def avgColNorm = if maxSlope != minSlope then (avgDiff - minSlope) / (maxSlope - minSlope) else 0;
# Gradient color simulation
def slopeUp = avgColNorm > 0.4;
def slopeDn = avgColNorm < 0.4;
# Trend detection
def trend = CompoundValue(1,
if avgColNorm crosses above 0.55 then 1
else if avgColNorm crosses below 0.45 then 0
else trend[1], 0);
# Plotting deviation lines
def pStdv1 = stdv1;
def pStdv2 = stdv2;
def pStdv3 = stdv3;
def pStdv4 = stdv4;
def pStdv_1 = stdv_1;
def pStdv_2 = stdv_2;
def pStdv_3 = stdv_3;
def pStdv_4 = stdv_4;
# Plot average with dynamic color
plot pAvg = avg;
PAvg.assignvalueColor(if PAvg < PAvg[3] then color.red else color.green);
pAvg.SetLineWeight(3);
AssignBACKGROUNDColor(if !ColorBar then Color.CURRENT else if low < pstdv_4 then color.cyan else if high > pstdv4 then color.magenta else if close > pstdv_2 and close < pstdv_1 then color.light_green else if close > pstdv_3 and close < pstdv_2 then color.green else if close > pstdv_4 and close < pstdv_3 then color.dark_green else if low < pstdv_4 then color.cyan else if close < pstdv4 and close > pstdv3 then color.dark_red else if close < pstdv3 and close > pstdv2 then color.red else if close > pstdv1 and close < pstdv2 then color.dark_orange else if close < pstdv2 and close > pavg then color.gray else if close < pavg and close > pstdv_2 then color.gray else Color.dark_gray);
AddLabel(yes, if low < pstdv_4 then "XBUY" else if high > pstdv4 then "XSELL" else " ", if low < pstdv_4 THEN COLOR.blue ELSE IF high > pstdv4 then color.black else Color.BLACK);
Last edited: