Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

TD Setup for Amibroker (AFL)
ferpa
over 11 years ago
Amibroker (AFL)

Rating:
3 / 5 (Votes 5)
Tags:
trading system, amibroker, advanced

A complete Perl’s trading rules using TD Setup indicator.

Screenshots

Similar Indicators / Formulas

Visual BackTest
Submitted by sethmo about 11 years ago
Nirvana XeL MOD 1.5a
Submitted by xel over 12 years ago
10 Day Moving Average System
Submitted by sonyhiren11 over 11 years ago
Komunitas Modified
Submitted by tm832 about 14 years ago
NMA-swing-trading-system-NMA I.T v-3
Submitted by cnbondre over 14 years ago
TTS system V 4
Submitted by jaipal7786 almost 12 years ago

Indicator / Formula

Copy & Paste Friendly
//TD Buy Setup
TDBuySetup = Sum(C < Ref(C, -4), 9) == 9 AND Ref(C, -9) > Ref(C, -13);

//TD Sell Setup
TDSellSetup = Sum(C > Ref(C, -4), 9) == 9 AND Ref(C, -9) < Ref(C, -13);

//TDST Support
TDST_Support = ValueWhen(TDSellSetup, LLV(L, 9));
Plot(TDST_Support, "TDST Support", colorAqua, styleLine);

//TDST Resistance
TDST_Resistance = ValueWhen(TDBuySetup, HHV(H, 9));
Plot(TDST_Resistance, "TDST Resistence", colorLightOrange, styleLine);

//TD Buy Setup "Perfection"
TDBS_P = (L <= Ref(L, -2) & L <= Ref(L, -3)) | (Ref(L, -1) <= Ref(L, -2) & Ref(L, -1) <= Ref(L, -3));

//TD Sell Setup "Perfection"
TDSS_P = (H >= Ref(H, -2) & H >= Ref(H, -3)) | (Ref(H, -1) >= Ref(H, -2) & Ref(H, -1) >= Ref(H, -3));

//Perl's Rules for Trading TD Buy Setups Objectively
TradingTDBS = TDBuySetup & TDBS_P & (LLV(C, 9) > TDST_Support);

//Perl's Rules for Trading TD Sell Setups Objectively
TradingTDSS = TDSellSetup & TDSS_P & (HHV(C, 9) < TDST_Resistance);

//TD Buy Risk Level
TDBS_RL = IIf(L < Ref(L, -1), TDST_Support - (H - L), IIf(Ref(L, -1) < L, TDST_Support - (Ref(H, -1) - Ref(L, -1)), IIf(L == Ref(L, -1), TDST_Support - Max(H - L, Ref(H, -1) - Ref(L, -1)), 0)));


//TD Sell Risk Level
TDSS_RL = IIf(H > Ref(H, -1), TDST_Resistance + (H - L), IIf(Ref(H, -1) > H, TDST_Resistance + (Ref(H, -1) - Ref(L, -1)), IIf(H == Ref(H, -1), TDST_Resistance + Max(H - L, Ref(H, -1) - Ref(L, -1)), 0)));

TDBS_C = ((TDST_Resistance - C) / (C - TDBS_RL)) >= 1.5;
Plot(IIf(TradingTDBS & TDBS_C, TDBS_RL, Null), "", colorRed, styleDots);
PlotShapes(IIf(TradingTDBS & TDBS_C, shapeSmallSquare, shapeNone), colorBrightGreen, 0, L);
TDSS_C = ((C - TDST_Support) / (TDSS_RL - C)) >= 1.5;
Plot(IIf(TradingTDSS & TDSS_C, TDSS_RL, Null), "", colorRed, styleDots);
PlotShapes(IIf(TradingTDSS & TDSS_C, shapeSmallSquare, shapeNone), colorBrightGreen, 0, H); 

//Show Numbers & Stop Loss
d = 0.5 * ATR(10);
for(i = 0; i < BarCount; i++) { 
	if (TDBuySetup[i]) {
		if (TradingTDBS[i] & TDBS_C[i]) 
			PlotText("Stop Loss\n@" + NumToStr(TDBS_RL[i], 1.2), i, TDBS_RL[i] - d[i], colorRed);
		for (j = 0; j < 9; j++) {
			PlotText(NumToStr(9 - j, 1.0), i - j, L[i - j] - d[i], colorGreen);
		}
	}
	if(TDSellSetup[i]) {
		if (TradingTDSS[i] & TDSS_C[i]) 
			PlotText("Stop Loss\n@" + NumToStr(TDSS_RL[i], 1.2), i, TDSS_RL[i] + d[i], colorRed);
		for (j = 0; j < 9; j++)
			PlotText(NumToStr(9 - j, 1.0), i - j, H[i - j] + d[i], colorRed);
	}
}

//Price
Plot(C, "Close", IIf((TDBuySetup & TDBS_P) | (TDSellSetup & TDSS_P), colorYellow, colorLavender), styleBar, Null, Null, 0, 0, 1);

Title = "{{DATE}} - "+ Name() + " - " + " Open = " + NumToStr(O, 1.2) + ", High = " + NumToStr(H, 1.2) + ", Low = " + NumToStr(L, 1.2) + ", Close = " + NumToStr(C, 1.2) + "\n" + 
EncodeColor(colorAqua) + "TDST Support" + EncodeColor(colorDefault) + " = " + NumToStr(TDST_Support, 1.2) + ", " + EncodeColor(colorLightOrange) + "TDST Resistance" + EncodeColor(colorDefault) + " = " + NumToStr(TDST_Resistance, 1.2) + "\n" + 
WriteIf(TDBuySetup, WriteIf(TDBS_P, EncodeColor(colorYellow) + "Perfected" + EncodeColor(colorDefault), "Unperfected ") + " TD Buy Setup\n", "") + 
WriteIf(TDSellSetup, WriteIf(TDSS_P, EncodeColor(colorYellow) + "Perfected" + EncodeColor(colorDefault), "Unperfected ") + " TD Sell Setup\n", "") + 
WriteIf(TDBuySetup, "\nPerl's Rules for Trading TD Buy Setups Objectively\n" + 
"1. When the TD Buy Setup has been perfected, that is, the low of TD Buy Setup bar eight or nine is less than the lows of TD Buy Setup bars six and seven, " + WriteIf(TDBS_P, "[" + EncodeColor(colorBrightGreen) + "Yes" + EncodeColor(colorDefault) + "]", "[" + EncodeColor(colorRed) + "No" + EncodeColor(colorDefault) + "]") + "\n" + 
"2. When none of the bars within the TD Buy Setup has closed below TDST support, " + WriteIf((LLV(C, 9) > TDST_Support), "[" + EncodeColor(colorBrightGreen) + "Yes" + EncodeColor(colorDefault) + "]", "[" + EncodeColor(colorRed) + "No" + EncodeColor(colorDefault) + "]") + "\n" +  
"3. When the Close of TD Buy Setup bar nine is in Close proximity to TDST support. " + WriteIf(TDBS_C, "[" + EncodeColor(colorBrightGreen) + "Yes" + EncodeColor(colorDefault) + "]", "[" + EncodeColor(colorRed) + "No" + EncodeColor(colorDefault) + "]"), "") + 
WriteIf(TDSellSetup, "\nPerl's Rules on When to Initiate a Short Position Following a Completed TD Sell Setup\n" + 
"1. When the TD Sell Setup has been perfected,that is,when the high of TD Sell Setup bar eight or nine is greater than the highs of TD Sell Setup bars six and seven, " + WriteIf(TDSS_P, "[" + EncodeColor(colorBrightGreen) + "Yes" + EncodeColor(colorDefault) + "]", "[" + EncodeColor(colorRed) + "No" + EncodeColor(colorDefault) + "]") + "\n" + 
"2. When none of the bars within the TD Sell Setup has closed above TDST resistance, " + WriteIf((HHV(C, 9) < TDST_Resistance), "[" + EncodeColor(colorBrightGreen) + "Yes" + EncodeColor(colorDefault) + "]", "[" + EncodeColor(colorRed) + "No" + EncodeColor(colorDefault) + "]") + "\n" +  
"3. When the close of TD Sell Setup bar nine is in close proximity to TDST resistance. " + WriteIf(TDSS_C, "[" + EncodeColor(colorBrightGreen) + "Yes" + EncodeColor(colorDefault) + "]", "[" + EncodeColor(colorRed) + "No" + EncodeColor(colorDefault) + "]"), "") + 
WriteIf(TradingTDBS & TDBS_C, "\n\n" + EncodeColor(colorBrightGreen) + "Trading a TD Buy Setup" + EncodeColor(colorDefault) + "\nEntry price = " + NumToStr(C, 1.2) + "\nStop loss = " + NumToStr(TDBS_RL, 1.2) + "\nRisk return = " + NumToStr((TDST_Resistance - C) / (C - TDBS_RL), 1.2), "") + 
WriteIf(TradingTDSS & TDSS_C, "\n\n" + EncodeColor(colorBrightGreen) + "Trading a TD Sell Setup" + EncodeColor(colorDefault) + "\nEntry price = " + NumToStr(C, 1.2) + "\nStop loss = " + NumToStr(TDSS_RL, 1.2) + "\nRisk return = " + NumToStr((C - TDST_Support) / (TDSS_RL - C), 1.2), "");

Buy = TradingTDBS & TDBS_C;
Short = TradingTDSS & TDSS_C;  

11 comments

1. val2004

Hi,

did you program other demark indicators ?

2. sam21

Hi,

Thanks for sharing a afl of TD Setup with explanation .

Regards,
Sam21

3. ferpa

val2004, i’m developing the TD Sequencial Countdown but i need a few days to complete the program.

4. Alok

Thanks

5. Alok

Hi,

HOpe to see how the perl TD and sequential works when you complete the other one, best of luck.

Thanks

6. val2004

keep up the good work.do you consider coding later on TD Wave ?

7. vivekkumarbhat15

getting a syntax error,
ln 62, col 127error 16, too many arguments

8. ferpa

vivekkumarbhat15, are you using Amibroker 5.6? if not, update else try copy & paste formula again.

9. vivekkumarbhat15

nope i am using 5.3. anyways got it sorted. thanks

10. sahasra
ferpa

Did you consider gaps while coding…

11. derek2209

Hi,

Many thanks for sharing your afl of TD Setup with explanation

Kind regards,

Derek2209

Leave Comment

Please login here to leave a comment.

Back