Any error in this AFL

#1
Hello,

The following code is the trade system of Donchian Channel which I would like to know any logic error in this code.

Buy signal = the highest price breaks the highest high price of 20 days
Buy Price = buy at that highest high price of 20 days

Short signal = the lowest price breaks the lowest low price of 20 days
Short Price = Short at that lowest low price of 20 days

SetTradeDelays(0, 0, 0, 0);

DonchianUpper =HHV(Ref(H,-1),20);
DonchianLower = LLV(Ref(L,-1),20);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;

Buy = H > DonchianUpper;
Short = L < DonchianLower;
Sell = 0;
Cover = 0;

BuyPrice = HHV(Ref(H,-1),20);
ShortPrice = LLV(Ref(L,-1),20);

ApplyStop (stopTypeProfit, stopModePercent, 3);
ApplyStop (stopTypeLoss, stopModePercent, 5);

Plot(DonchianUpper,"DU",colorBlue,styleLine);
Plot(DonchianMiddle,"DM",colorGreen,styleLine);
Plot(DonchianLower,"DL",colorRed,styleLine);

Thank you!!!
 

pratapvb

Well-Known Member
#2
nothing wrong that I can see by glancing assuming you want to trade the breakouts of range and you want to trail with 3% and 5% (which to me as a trader seems high and an arbritary figure)....why the question?
 

mastermind007

Well-Known Member
#3
Hello,

The following code is the trade system of Donchian Channel which I would like to know any logic error in this code.

Buy signal = the highest price breaks the highest high price of 20 days
Buy Price = buy at that highest high price of 20 days

Short signal = the lowest price breaks the lowest low price of 20 days
Short Price = Short at that lowest low price of 20 days

SetTradeDelays(0, 0, 0, 0);

DonchianUpper =HHV(Ref(H,-1),20);
DonchianLower = LLV(Ref(L,-1),20);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;

Buy = H > DonchianUpper;
Short = L < DonchianLower;
Sell = 0;
Cover = 0;

BuyPrice = HHV(Ref(H,-1),20);
ShortPrice = LLV(Ref(L,-1),20);

ApplyStop (stopTypeProfit, stopModePercent, 3);
ApplyStop (stopTypeLoss, stopModePercent, 5);

Plot(DonchianUpper,"DU",colorBlue,styleLine);
Plot(DonchianMiddle,"DM",colorGreen,styleLine);
Plot(DonchianLower,"DL",colorRed,styleLine);

Thank you!!!
jacklcl

Good effort put in. Here is the list of what I think you have to deal with over time

a) No exits planned; So exit is based only on the trailing stop.... You will have to figure out a way to switch directions off of apply stop

b) Who is going to sell you at high of yesterday, especially since you are waiting for that High to be broken?

So, either factor in a slippage of 0.50 above that high (or as most ppl do, Buy and short at close) and actual trade price, you get what you manage to get.

c) I would not recommend Ref inside HHV. You will not get full 20 days lookback in this manner.

d) What Win:Loss ratio do you have in mind?

e) No ability to handle excess signals
 
#4
nothing wrong that I can see by glancing assuming you want to trade the breakouts of range and you want to trail with 3% and 5% (which to me as a trader seems high and an arbritary figure)....why the question?
This version is just for illustration only and used to confirm whether the logic is correct as I am new in AFL. I will amend the rule based on this strategy. Thank you for your comment!
 
#5
jacklcl

Good effort put in. Here is the list of what I think you have to deal with over time

a) No exits planned; So exit is based only on the trailing stop.... You will have to figure out a way to switch directions off of apply stop

b) Who is going to sell you at high of yesterday, especially since you are waiting for that High to be broken?

So, either factor in a slippage of 0.50 above that high (or as most ppl do, Buy and short at close) and actual trade price, you get what you manage to get.

c) I would not recommend Ref inside HHV. You will not get full 20 days lookback in this manner.

d) What Win:Loss ratio do you have in mind?

e) No ability to handle excess signals
Thank you for your suggestion!

a) the exiting strategy for stop is just for testing only, I'm still thinking any better exit strategy to be used

b) i'm sorry that i'm not clear what is your meaning. My english may be not good enough as I come from HK.

c) You mean the 20 days high cannot be returned using this AFL? So, any suggestion to amend it?

d) I want to have win % above 40%

e) I have added the additional code in this system using exrem to remove excessive signals

Actually, this is just a first version and now I am working to amend the system so that the period (N) can be automatically changed based on the volatility rather than a fixed period.
 

Similar threads