https://tos.mx/dDZh6eC

It looked really promising (as most strudies from Mobius are). However after working through the details, it appeared that the embedded logic was a bit complex and confusing. Hence I cleaned up the code, modified the logic, rewrote portions of the underlying engine, added state transitions, implemented buy/sell signals and arrows as well as gave it a new coloring structure.

Since the previous study did not have a name, as a placeholder I'm tagging this study as "Supertrend ATR CCI Trend". Here then is version 2.0 of the code.

Enjoy it folks!

Code:

```
# SuperTrend CCI ATR Trend
# tomsk
# 11.18.2019
# V1.0 - 08.10.2019 - dtek - Initial release of SuperTrend CCI ATR Trend
# V2.0 - 11.18.2019 - tomsk - Modified the logic, cleaned up code for consistency
# SUPERTREND BY MOBIUS AND CCI ATR TREND COMBINED INTO ONE CHART INDICATOR,
# BOTH IN AGREEMENT IS A VERY POWERFUL SIGNAL IF TRENDING. VERY GOOD AT CATCHING
# REVERSALS. WORKS WELL ON 1 AND 5 MIN CHARTS. PLOT IS THE COMBINATION LOWEST
# FOR UPTREND AND HIGHEST OF THE DOWNTREND. DOTS COLORED IF BOTH IN AGREEMENT
# OR GREY IF NOT - 08/10/2019 DTEK
# Supertrend, extracted from Mobius original code
input ST_Atr_Mult = 1.0; # was .70
input ST_nATR = 4;
input ST_AvgType = AverageType.HULL;
def ATR = MovingAverage(ST_AvgType, TrueRange(high, close, low), ST_nATR);
def UP = HL2 + (ST_Atr_Mult* ATR);
def DN = HL2 + (-ST_Atr_Mult * ATR);
def ST = if close < ST[1] then UP else DN;
# CCI_ATR measures distance from the mean. Calculates a trend
# line based on that distance using ATR as the locator for the line.
# Credit goes to Mobius for the underlying logic
input lengthCCI = 50; # Was 20
input lengthATR = 21; # Was 4
input AtrFactor = 1.0; # Was 0.7
def ATRCCI = Average(TrueRange(high, close, low), lengthATR) * AtrFactor;
def price = close + low + high;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0
then 0
else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if CCI > 0
then Max(MT1[1], HL2 - ATRCCI)
else Min(MT1[1], HL2 + ATRCCI);
# Alignment of Supertrend and CCI ATR indicators
def Pos_State = close > ST and close > MT1;
def Neg_State = close < ST and close < MT1;
# Combined Signal Approach - Supertrend and ATR CCI
plot CSA = MT1;
CSA.AssignValueColor(if Pos_State then Color.CYAN
else if Neg_State then Color.MAGENTA
else Color.YELLOW);
# Buy/Sell Signals using state transitions
def BuySignal = (!Pos_State[1] and Pos_State);
def SellSignal = !Neg_State[1] and Neg_State;
# Buy/Sell Arrows
plot BuySignalArrow = if BuySignal then 0.995 * MT1 else Double.NaN;
BuySignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignalArrow.SetDefaultColor(Color.CYAN);
BuySignalArrow.SetLineWeight(5);
plot SellSignalArrow = if SellSignal then 1.005 * MT1 else Double.NaN;
SellSignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignalArrow.SetDefaultColor(Color.PINK);
SellSignalArrow.SetLineWeight(5);
# Candle Colors
AssignPriceColor(if Pos_State then Color.GREEN
else if Neg_State then Color.RED
else Color.YELLOW);
# End SuperTrend CCI ATR Trend
```