Here is the code with the CCI Supertrend. Turn strategy confirmation factor to 5 and strategy hold trend to "NO". See some good results. Will backtest this and post the results soon.
# AK Trend
input aktrend_input1 = 3;
input aktrend_input2 = 8;
input aktrend_price = close;
def aktrend_fastmaa = MovAvgExponential(aktrend_price, aktrend_input1);
def aktrend_fastmab = MovAvgExponential(aktrend_price, aktrend_input2);
def aktrend_bspread = (aktrend_fastmaa - aktrend_fastmab) * 1.001;
def cond1_UP = if aktrend_bspread > 0 then 1 else 0;
def cond1_DN = if aktrend_bspread <= 0 then -1 else 0;
# ZSCORE
def zscore_price = close;
def zscore_length = 20;
def zscore_ZavgLength = 20;
def zscore_oneSD = StDev(zscore_price, zscore_length);
def zscore_avgClose = SimpleMovingAvg(zscore_price, zscore_length);
def zscore_ofoneSD = zscore_oneSD * zscore_price[1];
def zscore_Zscorevalue = ((zscore_price - zscore_avgClose) / zscore_oneSD);
def zscore_avgZv = Average(zscore_Zscorevalue, 20);
def zscore_Zscore = ((zscore_price - zscore_avgClose) / zscore_oneSD);
def zscore_avgZscore = Average(zscore_Zscorevalue, zscore_ZavgLength);
def cond2_UP = if zscore_Zscore > 0 then 1 else 0;
def cond2_DN = if zscore_Zscore <= 0 then -1 else 0;
# Ehlers
input ehlers_length = 34;
def ehlers_price = (high + low) / 2;
def ehlers_coeff = ehlers_length * ehlers_price * ehlers_price - 2 * ehlers_price * Sum(ehlers_price, ehlers_length)[1] + Sum(ehlers_price * ehlers_price, ehlers_length)[1];
def ehlers_Ehlers = Sum(ehlers_coeff * ehlers_price, ehlers_length) / Sum(ehlers_coeff, ehlers_length);
def cond3_UP = if close > ehlers_Ehlers then 1 else 0;
def cond3_DN = if close <= ehlers_Ehlers then -1 else 0;
# Anchored Momentum
input amom_src = close;
input amom_MomentumPeriod = 10;
input amom_SignalPeriod = 8;
input amom_SmoothMomentum = no;
input amom_SmoothingPeriod = 7;
def amom_p = 2 * amom_MomentumPeriod + 1;
def amom_t_amom = if amom_SmoothMomentum == yes then ExpAverage(amom_src, amom_SmoothingPeriod) else amom_src;
def amom_amom = 100 * ( (amom_t_amom / ( Average(amom_src, amom_p)) - 1));
def amom_amoms = Average(amom_amom, amom_SignalPeriod);
def cond4_UP = if amom_amom > 0 then 1 else 0;
def cond4_DN = if amom_amom <= 0 then -1 else 0;
# 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 prrice = close + low + high;
def linDev = LinDev(prrice, lengthCCI);
def CCI = if linDev == 0
then 0
else (prrice - Average(prrice, 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);
def cond5_UP = if Pos_State then 1 else 0;
def cond5_DN = if Neg_State then -1 else 0;
# End SuperTrend CCI ATR Trend
# Strategy
input Strategy_Confirmation_Factor = 3;
input Strategy_ColoredCandlesOn = yes;
input Strategy_VerticalLinesOn = no;
input Strategy_HoldTrend = yes;
def cond_UP = cond1_UP + cond2_UP + cond3_UP + cond4_UP + cond5_UP;
def cond_DN = cond1_DN + cond2_DN + cond3_DN + cond4_DN + cond5_DN;
def direction = if cond_UP >= Strategy_Confirmation_Factor then 1
else if cond_DN <= -Strategy_Confirmation_Factor then -1
else if !Strategy_HoldTrend and direction[1] == 1 and cond_UP < Strategy_Confirmation_Factor and cond_DN > -Strategy_Confirmation_Factor then 0
else if !Strategy_HoldTrend and direction[1] == -1 and cond_DN > -Strategy_Confirmation_Factor and cond_UP < Strategy_Confirmation_Factor then 0
else direction[1];
plot signal_up = direction == 1 and direction[1] < 1;
signal_up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal_up.SetDefaultColor(Color.WHITE);
signal_up.Hide();
signal_up.HideBubble();
signal_up.HideTitle();
plot signal_dn = direction == -1 and direction[1] > -1;
signal_dn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signal_dn.SetDefaultColor(Color.WHITE);
signal_dn.Hide();
signal_dn.HideBubble();
signal_dn.HideTitle();
AssignPriceColor(if Strategy_ColoredCandlesOn then if direction == 1 then Color.LIGHT_GREEN else if direction == -1 then Color.RED else Color.GRAY else Color.CURRENT);
AddVerticalLine(Strategy_VerticalLinesOn and signal_up, "Buy", Color.LIGHT_GREEN);
AddVerticalLine(Strategy_VerticalLinesOn and signal_dn, "Sell", Color.RED);
Alert(signal_up, "Buy", Alert.BAR, Sound.DING);
Alert(signal_dn, "Sell", Alert.BAR, Sound.DING);