Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Building Algo Platforms, 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 Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Interactive Brokers – Smart Order Chart Trading Module using…

The IB Controller is an interface designed to facilitate automatic trading with AmiBroker and Interactive Brokers (IB) TWS (Trader Workstation). It serves as a...
Rajandran R
8 min read

Introducing OpenAlgo V1.0: The Ultimate Open-Source Algorithmic Trading Framework…

OpenAlgo V1.0 is an open-source algorithmic trading platform to automate your trading strategies using Amibroker, Tradingview, Metatrader, Python etc. Designed with the modern trader...
Rajandran R
2 min read

[Live Coding Webinar] Build Your First Trading Bridge for…

In this course, you will be learning to build your own trading bridge using Python. This 60-minute session is perfect for traders, Python enthusiasts,...
Rajandran R
1 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