- Platform
-
- Thinkorswim
Code:
# Trend Magic Indicator based on https://ninjatraderecosystem.com/user-app-share-download/trend-magic/
# converted to ToS
# v1.0 NPTechs
input cciPeriod = 20;
input atrPeriod = 14;
input atrMult = 1.0;
def cciVal = CCI(cciPeriod);
def atrVal = ATR(atrPeriod);
def upTrend = low - atrVal * atrMult;
def downTrend = high + atrVal * atrMult;
def Trend = if (cciVal >= 0) and upTrend < Trend[1] then Trend[1]
else if (cciVal >= 0) and upTrend >= Trend[1] then upTrend
else if (cciVal < 0) and (downTrend > Trend[1]) then Trend[1]
else downTrend;
def iTrend = if Trend>Trend[1] then 1 else if Trend < Trend[1] then -1 else iTrend[1];
plot tmline = Trend;
tmline.AssignValueColor(if iTrend > 0 then Color.GREEN else Color.RED);
tmline.SetLineWeight(2);
Last edited: