Trend Direction Force Index (TDFI) For ThinkOrSwim

ccrkk

New member
I found this trend trading indicator on Tradingview and was wondering if someone could possibly convert it into a TOS study. I scrolled though charts on Tradingview with the indicator and it really did a nice job of keeping you out of trades while in a sideways market with the ".05" high/low filter. Would like to test it out on TOS to analyze it further and conduct more backtest on it. Any help would be greatly appreciated.
 
Last edited by a moderator:

Trend Direction Force Index (TDFI) For ThinkOrSwim​

Trend Direction Force Index Indicator analyzes and transforms past market data into potential trade signals. This indicator is well-known for its unique way of demonstrating the trade signals which can be read and understood by traders with any level of experience. Moreover, this supports all sorts of time frame charts.

Code:
# thinkscript version of Tradingview's Trend Direction Force Index (TDFI)
# by Zuben

declare lower;
input lookback = 13;
input mmaLength = 13;
input smmaLength = 13;
input mmaMode = AverageType.EXPONENTIAL;
input smmaMode = AverageType.EXPONENTIAL;
input nLength = 3;
input filterHigh = 0.05;
input filterLow = -0.05;
input price = close;

def mma = MovingAverage(mmaMode, price*1000, mmaLength);
def smma = MovingAverage(smmaMode, mma, smmaLength);
#for TEMA: comment out the two above lines and uncomment the following
#def mma = TEMA(price*1000, mmaLength);
#def smma = TEMA(mma, smmaLength);
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, nLength);
def tdfi = tdf / Highest(AbsValue(tdf), lookback * nLength);

plot signal = tdfi;
plot fh = filterHigh;
plot fl = filterLow;
plot zl = 0;

signal.SetDefaultColor(GetColor(4));
fh.SetDefaultColor(GetColor(2));
fl.SetDefaultColor(GetColor(2));
zl.SetDefaultColor(GetColor(7));

signal.DefineColor("Positive", Color.UPTICK);
signal.DefineColor("Negative", Color.DOWNTICK);
signal.AssignValueColor(if signal > fh then signal.color("Positive") else if signal < fl then signal.color("Negative") else Color.ORANGE);
 
Last edited by a moderator:
@Zuben Is it possible to add two sets of inputs? How owuld i go about that thanks.

input filterHigh = 0.05;
input filterLow = -0.05;

input filterHigh = 1.00;
input filterLow = -1.00;
 
@Trading51, This indicator is range-bound between 1 and -1, so setting those as a secondary high/low filter would just put a boundary at the top and bottom. From what I understand, the very low filters are to keep you ought of sideways markets. When it's above/below those filters, it indicates movement/momentum out of the sideways move.

But a secondary filter may have good use at a .5/-.5 range, which would give you a better idea of the strength of the move.
 
@Trading51, This indicator is range-bound between 1 and -1, so setting those as a secondary high/low filter would just put a boundary at the top and bottom. From what I understand, the very low filters are to keep you ought of sideways markets. When it's above/below those filters, it indicates movement/momentum out of the sideways move.

But a secondary filter may have good use at a .5/-.5 range, which would give you a better idea of the strength of the move.
I love this indicator so far. So your saying i should have both .5 and 1 ? im trying to achieve less signals
Anyone know how to smooth this out?
 
Last edited by a moderator:
I love this indicator so far. So your saying i should have both .5 and 1 ? im trying to achieve less signals
Anyone know how to smooth this out?
You would never smooth out the TDFI. You use threshold settings.
One of the many things that I like about this indicator, is that a quick view of the historical chart tells me whether an equity works well with this indicator and where I need to set my thresholds.

This is not the common range-bound oscillator that we are used to. There is no overbought or oversold. This indicator provides insight into the direction of a trend and the strength of a trend. It will skip many great runs. Because they were high risk. Risk is determined by where you set your threshold setting.

Rules and Interpretations. The rules and interpretations are actually simple. The indicator is easy to read.
In identifying a trend. Note the zero line in the center will be your cue. To determine whether a trend is bullish or bearish, just look whether the value is below or above zero. It is a bullish trend when the value is positive, bearish, if the value falls below 0. There are significant instances when the market is sidelined in which it is in neutral trend showing a value of 0.

As to strength of the trend. Between -0.05 and 0.05 indicates lack of strong trend and/or lack of confirmed direction. There are traders that will trade the TDFI as soon as it crosses zero. It gets you in at the beginning of the trend but it's a risk. Without strength or direction, it could fizzle and result in a loss. However, whenever the value enters the area 0.06 to 1, then there is an uptrend which means that the trend is strong. In like manner, when the value further falls to -0.06 to -1 then there is a downtrend, hence, the trend is weak and losing momentum. These are the "textbook" thresholds. Not all equities / timeframes read the textbook, take care!

As to trade and exit signals. In order to determine if the signal calls for a buy or sell condition, you should consider the following factors.
• Buy if the chart shows a bullish trend and the value crosses to the positive area particularly once the line climbs and reaches to 0.06 and continues to rise then activate the buy entry and subsequently set up your stop loss below the current low. And when the value turns neutral or is near or at 0 then exit long and take profit.

• Sell Short if the chart shows a bearish trend or showing the current market low. This happens when the value assumes the area of -0.06 to -1 in which case you should have activate your sell entry. Your stop loss should then be set at the current high of the market and as soon as the value nears zero you should exit short and take profit.

I use the Buy The Dip Indicator. When I have a dip, I wait and look for the TDFI to signal that the Bullish Trend has begun.
I set my thresholds based on what has triggered historically.

It goes without saying, never trade an indicator in isolation. Support & Resistance and moving averages work nicely with this indicator across all timeframes.

Miscellaneous Observations:
  • When scalping look to lower the threshold to enter a trade and raise the threshold to exit.
  • If my other indicators are positive, I will enter a trade before .06.
  • The TDFI, for many equities and timeframes, traditionally indicates a very strong trend cannot be maintained. Use caution if TDFI has been over .9 for more than 3 bars, it could be getting ready for a significant drop or there might still be some profit to be had. What you do depends on your risk calculations.
There are no exact threshold numbers whether you are day-trading or swinging. Look at the historical plot: for that equity and for that timeframe to understand what numbers will work well.
 
Last edited:
yeah the problem with this indicator is, Sometime it reaches the 1 or - 1 but somethings it gets stopped out at like .025 .. Eh wish it was a lil better
 
Force Index Binary signals 3X MTF, assign Price color, Labels, Composite signals from 5 lengths of indicators
You can paint the price bars by setting APC to whichever line you want highlighted
Turn on labels set input to yes
Code:
Declare Lower;
#Designed by Henry Z Kaczmarczyk 1/2022
# GLOBAL DEFINITIONS
DefineGlobalColor("TrendUp", Color.Cyan);
DefineGlobalColor("TrendDown", Color.Magenta);
input agg = AggregationPeriod.FIVE_MIN;
input agg2 = AggregationPeriod.THIRTY_MIN;
input agg3 = AggregationPeriod.HOUR;
input DotSize = 3;
Input APC = 7;
Input Labels = no;
input n = 20;
def n1  = n + 1;
input F2length = 2;
input F5length = 5;
input F8length = 8;
input F13length = 13;
input F21length = 21;

def CP = close(Period = AGG);
def VP = Volume(Period = AGG);
def CP2 = close(Period = AGG2);
def VP2 = Volume(Period = AGG2);
def CP3 = close(Period = AGG3);
def VP3 = Volume(Period = AGG3);

#Aggregation 1
Def FI2 = ExpAverage(data = (CP - CP[1]) * VP,F2length);
def Bullish2 = If FI2 >0 then 1 else 0;
def Bearish2 = FI2 < 0;
def Bullish2XL = FI2 crosses above 0;
def Bearish2XS = FI2 crosses Below 0;
plot FI2_Dot = if IsNaN(close) then Double.NaN else 1;
FI2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
FI2_Dot.SetLineWeight(DotSize);
FI2_Dot.AssignValueColor(if Bullish2 <1then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 1, (agg/1000/60) + " min", Color.Yellow, yes);

Def FI5 = ExpAverage(data = (CP - CP[1]) * VP,F5length);
def Bullish5 =If FI5 >0 then 1 else 0;
def Bearish5 = FI5 < 0;
def Bullish5XL = FI5 crosses above 0;
def Bearish5XS = FI5 crosses Below 0;

plot FI5_Dot = if IsNaN(close) then Double.NaN else 2;
FI5_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
FI5_Dot.SetLineWeight(DotSize);
FI5_Dot.AssignValueColor(if Bullish5<1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 2, (agg/1000/60) + " min", Color.Yellow, yes);

Def FI8 = ExpAverage(data = (CP - CP[1]) * VP,F8length);
def Bullish8 = If FI8 >0 then 1 else 0;
def Bearish8 = FI8 < 0;
def Bullish8XL = FI8 crosses above 0;
def Bearish8XS = FI8 crosses Below 0;

plot FI8_Dot = if IsNaN(close) then Double.NaN else 3;
FI8_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
FI8_Dot.SetLineWeight(DotSize);
FI8_Dot.AssignValueColor(if Bullish8<1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 3, (agg/1000/60) + " min", Color.Yellow, yes);

Def FI13 = ExpAverage(data = (CP - CP[1]) * VP,F13length);
def Bullish13 = If FI13 >0 then 1 else 0;
def Bearish13 = FI13 < 0;
def Bullish13XL = FI13 crosses above 0;
def Bearish13XS = FI13 crosses Below 0;

plot FI13_Dot = if IsNaN(close) then Double.NaN else 4;
FI13_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
FI13_Dot.SetLineWeight(DotSize);
FI13_Dot.AssignValueColor(if Bullish13 <1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 4, (agg/1000/60) + " min", Color.Yellow, yes);

Def FI21 = ExpAverage(data = (CP - CP[1]) * VP,F21length);
def Bullish21 =If FI21 >0 then 1 else 0;
def Bearish21 = FI21 < 0;
def Bullish21XL = FI21 crosses above 0;
def Bearish21XS = FI21 crosses Below 0;

plot FI21_Dot = if IsNaN(close) then Double.NaN else 5;
FI21_Dot.SetPaintingStrategy(PaintingStrategy.Triangles);
FI21_Dot.SetLineWeight(DotSize);
FI21_Dot.AssignValueColor(if Bullish21<1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 5, (agg/1000/60) + " min", Color.Yellow, yes);

plot MTF_ADot = 6;
MTF_ADot.SetPaintingStrategy(PaintingStrategy.SQUARES);
MTF_ADot.SetLineWeight(lineWeight = 3);
MTF_ADot.DefineColor("Buy", Color.Green);
MTF_ADot.DefineColor("Sell", Color.red);
MTF_ADot.AssignValueColor ( if (Bullish2+ Bullish5 + Bullish8 + Bullish13+ Bullish21) >= 3 then MTF_ADot.Color("Buy") else MTF_ADot.Color("Sell"));



#Aggregation 2
Def A2FI2 = ExpAverage(data = (CP2 – CP2[1]) * VP2,F2length);
def A2Bullish2 = If A2FI2 >0 then 1 else 0;
def A2Bearish2 = A2FI2<0;
def A2Bullish2XL = A2FI2 crosses above 0;
def A2Bearish2XS = A2FI2 crosses Below 0;

plot A2FI2_Dot = if IsNaN(close) then Double.NaN else 8;
A2FI2_Dot.SetPaintingStrategy(PaintingStrategy.Points);
A2FI2_Dot.SetLineWeight(DotSize+1);
A2FI2_Dot.AssignValueColor(if A2Bullish2< 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 8, (agg2/1000/60) + " min", Color.Yellow, yes);

Def A2FI5 = ExpAverage(data = (CP2 – CP2[1]) * VP2,F5length);
def A2Bullish5 = If A2FI5 >0 then 1 else 0;
def A2Bearish5 = A2FI5<0;
def A2Bullish5XL = A2FI5 crosses above 0;
def A2Bearish5XS = A2FI5 crosses Below 0;

plot A2FI5_Dot = if IsNaN(close) then Double.NaN else 9;
A2FI5_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2FI5_Dot.SetLineWeight(DotSize+1);
A2FI5_Dot.AssignValueColor(if A2Bullish5 < 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]),9, (agg2/1000/60) + " min", Color.Yellow, yes);

Def A2FI8 = ExpAverage(data = (CP2 – CP2[1]) * VP2,F8length);
def A2Bullish8 = If A2FI8 >0 then 1 else 0;
def A2Bearish8 = A2FI8<0;
def A2Bullish8XL = A2FI8 crosses above 0;
def A2Bearish8XS = A2FI8 crosses Below 0;

plot A2FI8_Dot = if IsNaN(close) then Double.NaN else 10;
A2FI8_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2FI8_Dot.SetLineWeight(DotSize+1);
A2FI8_Dot.AssignValueColor(if A2Bullish8 < 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]),10, (agg2/1000/60) + " min", Color.Yellow, yes);

Def A2FI13 = ExpAverage(data = (CP2 – CP2[1]) * VP2,F13length);
def A2Bullish13 = if A2FI13 >0 then 1 else 0;
def A2Bearish13 = A2FI13<0;
def A2Bullish13XL = A2FI13 crosses above 0;
def A2Bearish13XS = A2FI13 crosses Below 0;

plot A2FI13_Dot = if IsNaN(close) then Double.NaN else 11;
A2FI13_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2FI13_Dot.SetLineWeight(DotSize+1);
A2FI13_Dot.AssignValueColor(if A2Bullish13 < 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 11, (agg2/1000/60) + " min", Color.Yellow, yes);

Def A2FI21 = ExpAverage(data = (CP2 – CP2[1]) * VP2,F21length);
def A2Bullish21 = If A2FI21 >0 then 1 else 0;
def A2Bearish21 = A2FI21<0;
def A2Bullish21XL = A2FI21 crosses above 0;
def A2Bearish21XS = A2FI21 crosses Below 0;

plot A2FI21_Dot = if IsNaN(close) then Double.NaN else 12;
A2FI21_Dot.SetPaintingStrategy(PaintingStrategy.Points);
A2FI21_Dot.SetLineWeight(DotSize+1);
A2FI21_Dot.AssignValueColor(if A2Bullish21< 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 12, (agg2/1000/60) + " min", Color.Yellow, yes);
plot MTF_BDot = 13;
MTF_BDot.SetPaintingStrategy(PaintingStrategy.SQUARES);
MTF_BDot.SetLineWeight(lineWeight = 4);
MTF_BDot.DefineColor("Buy", Color.Green);
MTF_BDot.DefineColor("Sell", Color.red);
MTF_BDot.AssignValueColor ( if (A2Bullish2+ A2Bullish5 +A2Bullish8 + A2Bullish13+ A2Bullish21) >= 3 then MTF_BDot.Color("Buy") else MTF_BDot.Color("Sell"));


#Aggregation 3

Def A3FI2 = ExpAverage(data = (CP3 – CP3[1]) * VP3,F2length);
def A3Bullish2 = If A3FI2 >0 then 1 else 0;
def A3Bearish2 = A3FI2<0;
def A3Bullish2XL = A3FI2 crosses above 0;
def A3Bearish2XS = A3FI2 crosses Below 0;

plot A3FI2_Dot = if IsNaN(close) then Double.NaN else 15;
A3FI2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3FI2_Dot.SetLineWeight(DotSize+2);
A3FI2_Dot.AssignValueColor(if A3Bullish2<1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 15, (agg3/1000/60) + " min", Color.Yellow, yes);

Def A3FI5 = ExpAverage(data = (CP3 – CP3[1]) * VP3,F5length);
def A3Bullish5 = If A3FI5 >0 then 1 else 0;
def A3Bearish5 = A3FI5<0;
def A3Bullish5XL = A3FI5 crosses above 0;
def A3Bearish5XS = A3FI5 crosses Below 0;

plot A3FI5_Dot = if IsNaN(close) then Double.NaN else 16;
A3FI5_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3FI5_Dot.SetLineWeight(DotSize+2);
A3FI5_Dot.AssignValueColor(if A3Bullish5< 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 16, (agg3/1000/60) + " min", Color.Yellow, yes);

Def A3FI8 = ExpAverage(data = (CP3 – CP3[1]) * VP3,F8length);
def A3Bullish8 = If A3FI8 >0 then 1 else 0;
def A3Bearish8 = A3FI8<0;
def A3Bullish8XL = A3FI8 crosses above 0;
def A3Bearish8XS = A3FI8 crosses Below 0;

plot A3FI8_Dot = if IsNaN(close) then Double.NaN else 17;
A3FI8_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3FI8_Dot.SetLineWeight(DotSize+2);
A3FI8_Dot.AssignValueColor(if A3Bullish8 < 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 17, (agg3/1000/60) + " min", Color.Yellow, yes);

Def A3FI13 = ExpAverage(data = (CP3 – CP3[1]) * VP3,F13length);
def A3Bullish13 = If A3FI13 >0then 1 else 0;
def A3Bearish13 = A3FI13<0;
def A3Bullish13XL = A3FI13 crosses above 0;
def A3Bearish13XS = A3FI13 crosses Below 0;

plot A3FI13_Dot = if IsNaN(close) then Double.NaN else 18;
A3FI13_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3FI13_Dot.SetLineWeight(DotSize+2);
A3FI13_Dot.AssignValueColor(if A3Bullish13 <1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 18, (agg3/1000/60) + " min", Color.Yellow, yes);

Def A3FI21 = ExpAverage(data = (CP3 – CP3[1]) * VP3,F21length);
def A3Bullish21 = If A3FI21 >0 then 1 else 0;
def A3Bearish21 = A3FI21<0;
def A3Bullish21XL = A3FI21 crosses above 0;
def A3Bearish21XS = A3FI21 crosses Below 0;

plot A3FI21_Dot = if IsNaN(close) then Double.NaN else 19;
A3FI21_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3FI21_Dot.SetLineWeight(DotSize+2);
A3FI21_Dot.AssignValueColor(if A3Bullish21 < 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 19, (agg3/1000/60) + " min", Color.Yellow, yes);

plot MTF_CDot = 20;
MTF_CDot.SetPaintingStrategy(PaintingStrategy.SQUARES);
MTF_CDot.SetLineWeight(lineWeight = 5);
MTF_CDot.DefineColor("Buy", Color.Green);
MTF_CDot.DefineColor("Sell", Color.red);
MTF_CDot.AssignValueColor ( if (A3Bullish2+ A3Bullish5 + A3Bullish8 + A3Bullish13+ A3Bullish21) >= 3 then MTF_CDot.Color("Buy") else MTF_CDot.Color("Sell"));

############ Labels
AddLabel(Labels == Yes And Bullish2, "Agg1.1 Long " , Color.Green);
AddLabel(Labels == Yes And Bullish2XL, "Agg 1.1 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And Bearish2XS, "Agg 1.1 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And Bearish2, "Agg 1.1 Short" , Color.Red);
AddLabel(Labels == Yes And Bullish5, "Agg 1.2 Long " , Color.Green);
AddLabel(Labels == Yes And Bullish5XL, "Agg 1.2 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And Bearish5XS, "Agg 1.2 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And Bearish5, "Agg 1.2 Short" , Color.Red);
AddLabel(Labels == Yes And Bullish8, "Agg1.3 Long " , Color.Green);
AddLabel(Labels == Yes And Bullish8XL, "Agg 1.3 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And Bearish8XS, "Agg 1.3 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And Bearish8, "Agg 1.3 Short" , Color.Red);
AddLabel(Labels == Yes And Bullish13, "Agg1.4 Long " , Color.Green);
AddLabel(Labels == Yes And Bullish13XL, "Agg 1.4 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And Bearish13XS, "Agg 1.4 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And Bearish13, "Agg 1.4 Short" , Color.Red);
AddLabel(Labels == Yes And Bullish21, "Agg1.5 Long " , Color.Green);
AddLabel(Labels == Yes And Bullish21XL, "Agg 1.5 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And Bearish21XS, "Agg 1.5 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And Bearish21, "Agg 1.5 Short" , Color.Red);

AddLabel(Labels == Yes And A2Bullish2, "Agg2.1 Long " , Color.Green);
AddLabel(Labels == Yes And A2Bullish2XL, "Agg 2.1 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A2Bearish2XS, "Agg 2.1 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A2Bearish2, "Agg 2.1 Short" , Color.Red);
AddLabel(Labels == Yes And A2Bullish5, "Agg2.2 Long " , Color.Green);
AddLabel(Labels == Yes And A2Bullish5XL, "Agg 2.2 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A2Bearish5XS, "Agg 2.2 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A2Bearish5, "Agg 2.2 Short" , Color.Red);
AddLabel(Labels == Yes And A2Bullish8, "Agg 2.3 Long " , Color.Green);
AddLabel(Labels == Yes And A2Bullish8XL, "Agg 2.3 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A2Bearish8XS, "Agg 2.3 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A2Bearish8, "Agg 2.3 Short" , Color.Red);
AddLabel(Labels == Yes And A2Bullish13, "Agg 2.4 Long " , Color.Green);
AddLabel(Labels == Yes And A2Bullish13XL, "Agg 2.4 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A2Bearish13XS, "Agg 2.4 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A2Bearish13, "Agg 2.4 Short" , Color.Red);
AddLabel(Labels == Yes And A2Bullish21, "Agg 2.5 Long " , Color.Green);
AddLabel(Labels == Yes And A2Bullish21XL, "Agg 2.5 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A2Bearish21XS, "Agg 2.5 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A2Bearish21, "Agg 2.5 Short" , Color.Red);

AddLabel(Labels == Yes And A3Bullish2, "Agg 3.1 Long " , Color.Green);
AddLabel(Labels == Yes And A3Bullish2XL, "Agg 3.1 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A3Bearish2XS, "Agg 3.1 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A3Bearish2, "Agg 3.1 Short" , Color.Red);
AddLabel(Labels == Yes And A3Bullish5, "Agg 3.2 Long " , Color.Green);
AddLabel(Labels == Yes And A3Bullish5XL, "Agg 3.2 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A3Bearish5XS, "Agg 3.2 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A3Bearish5, "Agg 3.2 Short" , Color.Red);
AddLabel(Labels == Yes And A3Bullish8, "Agg 3.3 Long " , Color.Green);
AddLabel(Labels == Yes And A3Bullish8XL, "Agg 3.3 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A3Bearish8XS, "Agg 3.3 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A3Bearish8, "Agg 3.3 Short" , Color.Red);
AddLabel(Labels == Yes And A3Bullish13, "Agg 3.4 Long " , Color.Green);
AddLabel(Labels == Yes And A3Bullish13XL, "Agg 3.4 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A3Bearish13XS, "Agg 3.4 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A3Bearish13, "Agg 3.4 Short" , Color.Red);
AddLabel(Labels == Yes And A3Bullish21, "Agg 3.5 Long " , Color.Green);
AddLabel(Labels == Yes And A3Bullish21XL, "Agg 3.5 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A3Bearish21XS, "Agg 3.5 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A3Bearish21, "Agg 3.5 Short" , Color.Red);

AssignPriceColor( if APC == 1 and FI2 >0 then Color.Cyan else if apc == 1 and FI2 < 0 then Color.Magenta else if APC == 2 and FI5 >0 then Color.Cyan else if APC == 2 and FI5 <0 then Color.Magenta else if APC == 3 and FI8 >0 then Color.Cyan else if APC == 3 and FI8 <0 then Color.Magenta else if APC == 4 and FI13 >0 then Color.Cyan else if APC == 4 and FI13 <0 then Color.Magenta else if APC == 5 and FI21 >0 then Color.Cyan else if APC == 5 and FI21 <0 then Color.Magenta else if APC == 6 and (Bullish2+ Bullish5 + Bullish8 + Bullish13+ Bullish21) >= 3 then Color.Green else if APC == 6 and (Bullish2+ Bullish5 + Bullish8 + Bullish13+ Bullish21) < 3 then Color.Red else if APC == 8 and A2FI2 >0 then Color.Cyan else if APC == 8 and A2FI2 <0 then Color.Magenta else if APC == 9 and A2FI5 >0 then Color.Cyan else if APC == 9 and A2FI5 <0 then Color.Magenta else if APC == 10 and A2FI8 >0 then Color.Cyan else if APC == 10 and A2FI8 <0 then Color.Magenta else if APC == 11 and A2FI13 >0 then Color.Cyan else if APC == 11 and A2FI13 <0 then Color.Magenta else if APC == 12 and A2FI21 >0 then Color.Cyan else if APC == 12 and A2FI21 <0 then Color.Magenta else if APC == 13 and
(A2Bullish2+ A2Bullish5 +A2Bullish8 + A2Bullish13+ A2Bullish21) >= 3 then Color.Green else if APC == 13 and (A2Bullish2+ A2Bullish5 +A2Bullish8 + A2Bullish13+ A2Bullish21) < 3 then Color.Magenta else if APC == 15 and A3FI2 >0 then Color.Cyan else if APC == 15 and A3FI2 <0 then Color.Magenta else if APC == 16 and A3FI5 >0 then Color.Cyan else if APC == 16 and A3FI5 <0 then Color.Magenta else if APC == 17 and A3FI8 >0 then Color.Cyan else if APC == 17 and A3FI8 <0 then Color.Magenta else if APC == 18 and A3FI13 >0 then Color.Cyan else if APC == 18 and A3FI13 <0 then Color.Magenta else if APC == 19 and A3FI21 >0 then Color.Cyan else if APC == 19 and A3FI21 <0 then Color.Magenta else if APC == 20 and (A3Bullish2+ A3Bullish5 + A3Bullish8 + A3Bullish13+ A3Bullish21) >= 3 then Color.Green else if APC == 20 and (A3Bullish2+ A3Bullish5 + A3Bullish8 + A3Bullish13+ A3Bullish21) < 3 then Color.Red else  Color.Current);
 

Trend Direction Force Index (TDFI) For ThinkOrSwim​


def tdf = Power(divma, 1) * Power(averimpet, nLength);
def tdfi = tdf / Highest(AbsValue(tdf), lookback * nLength);

plot signal = tdfi;
plot fh = filterHigh;
plot fl = filterLow;
plot zl = 0;

signal.SetDefaultColor(GetColor(4));
fh.SetDefaultColor(GetColor(2));
fl.SetDefaultColor(GetColor(2));
zl.SetDefaultColor(GetColor(7));

signal.DefineColor("Positive", Color.UPTICK);
signal.DefineColor("Negative", Color.DOWNTICK);
signal.AssignValueColor(if signal > fh then signal.color("Positive") else if signal < fl then signal.color("Negative") else Color.ORANGE);

[/CODE]
I want to add the MTF feature to this code, I have to add the (Period = Aggregation) could someone point me in the direction of what "Def" gets this?

declare lower;
input Aggregation = AggregationPeriod.Day;
input lookback = 13;
input mmaLength = 13;
input smmaLength = 13;
input mmaMode = AverageType.EXPONENTIAL;
input smmaMode = AverageType.EXPONENTIAL;
input nLength = 3;
input filterHigh = 0.05;
input filterLow = -0.05;
input price = close;

def mma = MovingAverage(mmaMode, price*1000, mmaLength);
def smma = MovingAverage(smmaMode, mma, smmaLength);
#for TEMA: comment out the two above lines and uncomment the following
#def mma = TEMA(price*1000, mmaLength);
#def smma = TEMA(mma, smmaLength);
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, nLength);
def tdfi = tdf / Highest(AbsValue(tdf), lookback * nLength);
 
Last edited:
I like the Force Index indicator but it's difficult to use in a strategy if you're looking at how much it changes. The values can be in the hundreds of millions at one time frame (or one stock) and thousands for a different time frame (or stock).

Any thoughts on how to 'normalize' it between different time frames/stocks? For example, make it into a -100 to 100 indicator, so you can say 'a value of 5 is a small change, but a value of 50 is a large change. I don't have the math chops to figure it out. Any help/thoughts would be appreciated. Thanks!
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
530 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top