Afl problems and basic afl programming (problems which i felt difficulties )

#1
Hi,
I want to make this new thread , because i felt that programming is very import part of trading , without knowing some basic coding it's very hard to trade(designing system) , I just share difficulty in writing code, i ain't expert neither intermediate, I just wanna know some basic coding in amibroker, i just put this thread in amibroker section because it's in amibroker.
(if writing title in capital letter is forum violation, please let me know, i'll change it)
here's one thread about afl http://www.traderji.com/amibroker/60292-afl-writing-guide-new-user.html
regards
 
Last edited:
#2
This will be like i'm learning something, i'll share here and when i feel difficulties, I'll ask it here. there's many threads and posts where one can get most of their answer,but there's thousands of threads and many things are changing as technology is developing, i mentioned it because it's not for spamming.
regards
 
Last edited:
#4
Here're some candlestick formulas
candlestick formulas
https://www.amibroker.com/library/detail.php?id=149
http://forums.worden.com/default.aspx?g=posts&t=7989
http://www.wisestocktrader.com/indicators/3212-candle-pattern-exploration
http://www.traderji.com/amibroker/86563-afl-needed-candlestick-pattern-eploration.html
http://www.amibroker.org/userkb/2008/03/06/candle-stick-evaluation-2/

and i got this code from internet
O1 = Ref(O,-1);O2 = Ref(O,-2);
H1 = Ref(H,-1);H2 = Ref(H,-2);
L1 = Ref(L,-1);L2 = Ref(L,-2);
C1 = Ref(C,-1);C2 = Ref(C,-2);

BullishEngulfing = ((O1>C1) AND (C>O) AND (C>= O1) AND (C1>= O) AND ((C-O)>(O1-C1)));
BearishEngulfing = ((C1>O1) AND (O>C) AND (O>= C1) AND (O1>= C) AND ((O-C)>(C1-O1)));

DarkCloudCover = (C1>O1 AND ((C1+O1)/2)>C AND O>C AND O>C1 AND C>O1 AND (O-C)/(0.001+(H-L)>0.6));
c_Status =
WriteIf(DarkCloudCover, "Dark Cloud Cover",
WriteIf(BearishEngulfing, "Bearish Engulfing",
WriteIf(BullishEngulfing, "Bullish Engulfing",
"" )));
// Success rate of dark cloud candle is 60% , since it's half formed bearish engulfing.
for example : here's a pic of a candlestick pattern dark cloud


and these pattern shows candlestick like it's should be .. Candle A (left side) and Candle B(right side), in dark cloud, candle A (close) should be less than candle B (open).
many times when you scan.. Candle A close and CandleB open are same and it shows still dark cloud candle.. in reality it should not be. why is that ?? So first i wanna divide formula to know , how is it formed ?
According to upper pic, what formula should be that fulfill all upper conditions ?
(if mentioning website is illegal, please let me know ,i'll remove them)
regards
 
Last edited:
#5
DarkCloudCover = (C1>O1 AND ((C1+O1)/2)>C AND O>C AND O>C1 AND C>O1 AND (O-C)/(0.001+(H-L)>0.6));

In this O1,C1 is bullish candlestick and 0,C is bearish candlestick.


lets divide formula of candlestick , learn first how's it formed,then we go for whether , is it right or wrong ?

C1 > O1 (it's for bullish candlestick)
(C1+O1)/2)>C (it's looks like 50% of bullish candlestick > bearish candlestick close ( I didn't get it, why is that for ? Isn't it like that bearish candle close should be less than 50% of bullish candle)
O>C (it's for bearish candlestick)
O>C1 (it's for bearish candlestick is bigger than bullish candlestick)
O-C only red rectangle bearish body
H-L lenght of full of bearish candle (toe to head)
0.001 I've no idea what's that?
(H-L) is greater than 0.6? (why is that?)
 
Last edited:
#6
When Scan is done then i need buy and sell signal of certain condition , so one should not see candle according to date time?
Will it be like this ?
PlotShapes(Buy*shapeUpArrow, colorWhite, 0, Array name);
PlotShapes(Sell*shapeDownArrow, colorPink, 0, Array name);
What'll we use for in case of dark cloud candle?
regards
 

KelvinHand

Well-Known Member
#7
DarkCloudCover = (C1>O1 AND ((C1+O1)/2)>C AND O>C AND O>C1 AND C>O1 AND (O-C)/(0.001+(H-L)>0.6));

In this O1,C1 is bullish candlestick and 0,C is bearish candlestick.


lets divide formula of candlestick , learn first how's it formed,then we go for whether , is it right or wrong ?
C1 > O1 (it's for bullish candlestick)

(C1+O1)/2)>C (it's looks like 50% of bullish candlestick > bearish candlestick
close ( I didn't get it, why is that for ? Isn't it like that bearish candle close should be less than 50% of bullish candle)

What the different if you use C< (C1+O1)/2) ?
Still the message trying to tell u, i only interest in the condition when Close below the 1/2 body of the previous bullish candle.

O>C1 (it's for bearish candlestick is bigger than bullish candlestick)
O-C only red rectangle bearish body
H-L lenght of full of bearish candle (toe to head)
0.001 I've no idea what's that?
(H-L) is greater than 0.6? (why is that?)

Next time Please copy the formula properly.
(O-C)/(0.001+(H-L)>0.6)

Should be
(O-C)/(0.001+(H-L))>0.6

O-C is the body.
H-L is the range.
Body/Range will give you the ratio. The ratio cannot exceed 1.
If the ratio is >0.6 then you want the body to be 60% longer.

Because High can be same as Low in some cases, so when Range (H-L) =0 that also means Body (C-O) also 0.
What will happen if Body/Range => 0/0 = ?????
Answer is Divide by Zero Exception!!!!
So what can we do to prevent this problem ???
Add a small number like 0.001 to the Range

Simple Right NOT Left ?
 
Last edited:

KelvinHand

Well-Known Member
#8
Here're some candlestick formulas
candlestick formulas
https://www.amibroker.com/library/detail.php?id=149
http://forums.worden.com/default.aspx?g=posts&t=7989
http://www.wisestocktrader.com/indicators/3212-candle-pattern-exploration
http://www.traderji.com/amibroker/86563-afl-needed-candlestick-pattern-eploration.html
http://www.amibroker.org/userkb/2008/03/06/candle-stick-evaluation-2/

and i got this code from internet
O1 = Ref(O,-1);O2 = Ref(O,-2);
H1 = Ref(H,-1);H2 = Ref(H,-2);
L1 = Ref(L,-1);L2 = Ref(L,-2);
C1 = Ref(C,-1);C2 = Ref(C,-2);

BullishEngulfing = ((O1>C1) AND (C>O) AND (C>= O1) AND (C1>= O) AND ((C-O)>(O1-C1)));
BearishEngulfing = ((C1>O1) AND (O>C) AND (O>= C1) AND (O1>= C) AND ((O-C)>(C1-O1)));

DarkCloudCover = (C1>O1 AND ((C1+O1)/2)>C AND O>C AND O>C1 AND C>O1 AND (O-C)/(0.001+(H-L)>0.6));
c_Status =
WriteIf(DarkCloudCover, "Dark Cloud Cover",
WriteIf(BearishEngulfing, "Bearish Engulfing",
WriteIf(BullishEngulfing, "Bullish Engulfing",
"" )));
// Success rate of dark cloud candle is 60% , since it's half formed bearish engulfing.
for example : here's a pic of a candlestick pattern dark cloud


and these pattern shows candlestick like it's should be .. Candle A (left side) and Candle B(right side), in dark cloud, candle A (close) should be less than candle B (open).
many times when you scan.. Candle A close and CandleB open are same and it shows still dark cloud candle.. in reality it should not be. why is that ?? So first i wanna divide formula to know , how is it formed ?
According to upper pic, what formula should be that fulfill all upper conditions ?
(if mentioning website is illegal, please let me know ,i'll remove them)
regards
Based on your Dark Cloud, you already specify O>C1
which means Current Open should be higher then Previous Close.

The only issue is the O to C1 can be 1 ticks nearer, it is still satisfy the condition.

Go and use the ruler to measure the distance then you will know it is not equal.
 
#9
C1 > O1 (it's for bullish candlestick)

(C1+O1)/2)>C (it's looks like 50% of bullish candlestick > bearish candlestick
close ( I didn't get it, why is that for ? Isn't it like that bearish candle close should be less than 50% of bullish candle)

What the different if you use C< (C1+O1)/2) ?
Still the message trying to tell u, i only interest in the condition when Close below the 1/2 body of the previous bullish candle.

O>C1 (it's for bearish candlestick is bigger than bullish candlestick)
O-C only red rectangle bearish body
H-L lenght of full of bearish candle (toe to head)
0.001 I've no idea what's that?
(H-L) is greater than 0.6? (why is that?)

Next time Please copy the formula properly.
(O-C)/(0.001+(H-L)>0.6)

Should be
(O-C)/(0.001+(H-L))>0.6

O-C is the body.
H-L is the range.
Body/Range will give you the ratio. The ratio cannot exceed 1.
If the ratio is >0.6 then you want the body to be 60% longer.
Thank you sir for reply,



just for understanding , i didn't add 0.001. i tried to ask question on pic.


Because High can be same as Low in some cases, so when Range (H-L) =0 that also means Body (C-O) also 0.
What will happen if Body/Range => 0/0 = ?????
Answer is Divide by Zero Exception!!!!
So what can we do to prevent this problem ???
Add a small number like 0.001 to the Range

Simple Right NOT Left ?

Just wondering these kind of candle exit? most cases it could be little high low with doji.
"(H-L) =0 that also means Body (C-O) also 0."
IN this case , candle will be a dot or a straight horizontal line.
regards
 
Last edited:
#10
Based on your Dark Cloud, you already specify O>C1
which means Current Open should be higher then Previous Close.

The only issue is the O to C1 can be 1 ticks nearer, it is still satisfy the condition.

Go and use the ruler to measure the distance then you will know it is not equal.

Sir, would it be?
regards
 

Similar threads