- Platform
-
- Thinkorswim
Code:
# thinkscript version of Tradingview's Trend Direction Force Index (TDFI)
# by Zuben
# Blue Magik SSL
# I assume this is based on the popular SSL indicator
# Converted from https://www.tradingview.com/script/i85H2tZ8-blue-magik/
# Assembled by BenTen at useThinkScript.com
# Combined TDFI and SSL, added cloud and bar colors (based on SSL Channel or TDFI) by NPTechs
# Added Daily, Weekly, Monthly VWAP
input len = 200;
def smaHigh = simpleMovingAvg(high, len);
def smaLow = simpleMovingAvg(low, len);
def Hlv = if close > smaHigh then 1 else if close<smaLow then -1 else Hlv[1];
def sslDown = if Hlv< 0 then smaHigh else smaLow;
def sslUp = if Hlv< 0 then smaLow else smaHigh;
plot up = sslUp;
plot down = sslDown;
# Daily, Weekly, Monthly VWAP
plot DailyVWAP = vwap(period = AggregationPeriod.DAY);
DailyVWAP.SetPaintingStrategy(PaintingStrategy.DASHES);
DailyVWAP.SetLineWeight(2);
DailyVWAP.SetDefaultColor(Color.VIOLET);
plot WeeklyVWAP = vwap(period = AggregationPeriod.WEEK);
WeeklyVWAP.SetPaintingStrategy(PaintingStrategy.DASHES);
WeeklyVWAP.SetLineWeight(1);
WeeklyVWAP.SetDefaultColor(Color.YELLOW);
plot MonthlyVWAP = vwap(period = AggregationPeriod.MONTH);
MonthlyVWAP.SetPaintingStrategy(PaintingStrategy.DASHES);
MonthlyVWAP.SetLineWeight(1);
MonthlyVWAP.SetDefaultColor(Color.RED);
up.SetDefaultColor(GetColor(1));
up.AssignValueColor(if close > smaHigh then Color.GREEN else Color.RED);
down.SetDefaultColor(GetColor(0));
down.AssignValueColor(if close > smaHigh then Color.GREEN else Color.RED);
AddCloud(sslUp,sslDown,Color.LIGHT_GREEN,Color.LIGHT_RED);
input mmaMode = AverageType.EXPONENTIAL;
input smmaMode = AverageType.EXPONENTIAL;
input TDFIEmaOrTema = { default "EMA", "TEMA" };
def mma = if TDFIEmaOrTema == TDFIEmaOrTema.EMA then MovingAverage(mmaMode, close*1000, 13) else TEMA(close*1000, 13) ;
def smma = if TDFIEmaOrTema == TDFIEmaOrTema.EMA then MovingAverage(smmaMode, mma, 13) else TEMA(mma, 13) ;
def impetmma = mma - mma[1];
def impetsmma = smma - smma[1];
def divma = AbsValue(mma - smma);
def averimpet = (impetmma + impetsmma) / 2;
def tdf = Power(divma, 1) * Power(averimpet, 3);
def tdfi = tdf / Highest(AbsValue(tdf), 13 * 3);
input BarColor = { "None", default "TDFI", "SSL" }; #hint BarColor: Paint bars with TDFI or SSL Channel
AssignPriceColor(
if BarColor == BarColor.TDFI then
if tdfi > 0.05 then Color.GREEN else if tdfi < -0.05 then Color.RED else Color.LIGHT_GRAY
else if BarColor == BarColor.SSL then
if close > smaHigh then Color.GREEN else Color.RED
else Color.CURRENT
);
Last edited: