Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Predicting Trend Reversal Using TD Setup – Amibroker AFL Code

2 min read

TD Sequential is a technical analysis indicator from Tom Demark usually used to predict trend reversal points. The TD Sequential consists of two main components: the TD Setup and the TD Countdown. In this tutorial, we will be learning how to implement TD Setup to look for a trend reversal signal.

What is TD Setup?

TD Setup is composed of typically 9 consecutive price bars. For a bearish setup (indicating a potential downward trend reversal), each bar’s closing price must be lower than the closing price four bars earlier. Conversely, for a bullish setup (indicating a potential upward trend reversal), each bar’s closing price must be higher than the closing price four bars earlier.

Historically, it has been noted that when the TD Setup count surpasses 7, or reaches more than 7, there is a heightened probability of a trend reversal. Consequently, a consecutive TD Setup pattern that surpasses this threshold is often regarded as an optimal point for entering a long position.

It is also noted that bullish signals have a higher probability of winning compared to bearish signals most likely it reminds me of the drift.

Please be aware that this trading system is not flawless and does not provide definitive exit signals. Its strength lies in identifying favorable entry points and is particularly effective for long-only trade setups. However, it is strongly recommended to corroborate these signals with additional technical parameters to optimize the timing of your entry.

Signals are Designed as Non Repainting Indicators to generate signals on the close of the breaking of the TD Setup Pattern and at the very next bar open it generates the entry signal.

Recommended Timeframe:

Hourly, Daily, Weekly

TD Setup Bullish Bars are highlighted with yellow colored bars and bearish bars are highlighted with red colored bars. The end of this bullish color on a closing basis triggers a buy signal.

Here is the Amibroker AFL Code with TD Setup Long Only Signals

_SECTION_BEGIN("TD Setup Based Long Only Pullback Trading System");

SetChartOptions(0,chartShowArrows | chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));



BuyCon = C > Ref( C, -4);
Buy9Bars = BarsSince(BuyCon);



SellCon = C < Ref( C, -4);
Sell9Bars = BarsSince(SellCon);



PlotShapes(	 IIf(Buy9Bars==7, shapeDigit7,
  			 IIf(Buy9Bars==8, shapeDigit8,
  			 IIf(Buy9Bars==9, shapeDigit9,
			 IIf(Buy9Bars >9, shapeStar,shapeNone)))),colorGreen, 0, H, 20);

PlotShapes(	IIf(Sell9Bars==7, shapeDigit7,
  			IIf(Sell9Bars==8, shapeDigit8,
  			IIf(Sell9Bars==9, shapeDigit9,
			IIf(sell9bars>9, shapeHollowCircle,shapeNone)))),colorRed, 0, L, -20);
			
color = IIf(Buy9Bars>=7,colorYellow,IIf(Sell9Bars>=7,colorRed,colorDefault));
			
Plot(C,"candle",color,styleCandle);		

if(Interval()<inDaily)
{	
Buy9Bars = Ref(Buy9Bars,-1);
Sell9Bars = Ref(Sell9Bars,-1);
}


Buy = 	Buy9Bars == 0 AND Ref(Buy9Bars,-1) >=7;
Sell = 0;

_SECTION_END();

_SECTION_BEGIN("Trading Signals");


//Plot the trading signals

/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);



_SECTION_END();



Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Reversal Finder – Tradingview to Amibroker AFL Code Conversion

Reversal Finder is designed to identify potential reversal signals in a stock's price action. It highlights specific bars that meet the criteria for a...
Rajandran R
2 min read

CM Williams VIX FIX Pinescript to Amibroker AFL Conversion

Thought of converting some of the top-rated pinescript codes to Amibroker AFL code. So started with CM Williams VIX FIX with 51,000+ ratings for...
Rajandran R
1 min read

5 Paisa Webhook – Amibroker Button Trading Module

In this tutorial, we will be using 5 Paisa Webhooks to Send Orders using the Amibroker Button Trading Module. This Button trading module provides...
Rajandran R
3 min read

One Reply to “Predicting Trend Reversal Using TD Setup – Amibroker AFL…”

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More