CDLEngulfing() what does it return?

Posted By: swingtraderkk

CDLEngulfing() what does it return? - 10/22/13 16:54

Hi all,

What exactly does CDLEngulfing() return?

I've been playing with this and can't make sense of the returns. The manual says:
"The CDL functions return a value of -100% for bearish patterns, +100% for bullish patterns, and 0 for no pattern match. They use the current asset price series."

I expected then that bullish engulfing candles would return either 1 or 100, & bearish engulfing would return -1 or -100 but that does not appear to be the case.

Code:
function run()
{
	BarPeriod = 30;
	
	vars cl	= series(priceClose());	
	
	vars ema	= series(EMA(cl,67));
	vars sma	= series(SMA(cl,13));

	
	if ((sma[0]>ema[0]) and (CDLEngulfing() == 100))	reverseLong(1);
	
	if ((sma[0]<ema[0]) and (CDLEngulfing() == -100))	reverseShort(1);
	
	plot("EMA",ema[0],0,GREEN);
	plot("SMA",sma[0],0,ORANGE);
	plot("CDL",CDLEngulfing(),NEW,BLUE);	
	
}



How do the cdl functions work?

should they return a % similarity to the patterns or simply a 100%, -100%, 0?
Posted By: jcl

Re: CDLEngulfing() what does it return? - 10/22/13 17:05

Originally Posted By: manual
The CDL functions return a value of -100% for bearish patterns, +100% for bullish patterns, and 0 for no pattern match.

I'm not familiar with candle patterns and have never used them, but there are books where you probably find a description what an engulfing pattern is. A candle pattern can be bearish or bullish, but I think it can not be both, so your algorithm will probably not work.
Posted By: swingtraderkk

Re: CDLEngulfing() what does it return? - 10/22/13 17:16

Engulfing candle patterns can be either bullish or bearish.

Quote:
The bullish engulfing candlestick is a well-known candle pattern composed of two candle lines. The first one is black and the second is a white one that is taller than the prior black candle, engulfing it or overlapping the black candle’s body.

from Thomas Bulkowski's pattern site: http://thepatternsite.com/BullEngulfing.html

Opposite for Bearish engulfing.

The manual then needs to be amended to indicate whether the CDLEngulfing is either for bullish or bearish patterns.

Quote:
CDLEngulfing(): int
Engulfing Pattern. Bullish + Bearish.




I also suspect that it is not returning correct values even assuming it is only returning bearish patterns. If you run the script and look at the plot, there are significant periods where it returns 100s and periods where it returns only 0.
Posted By: jcl

Re: CDLEngulfing() what does it return? - 10/22/13 17:32

From what I see in the TA-LIB, it is supposed to indeed return +100 or -100, but in fact it only returns -100.
Posted By: jcl

Re: CDLEngulfing() what does it return? - 10/23/13 10:47

Ok, after some thoughts about it, the reason of the problem is clear. The whole candle pattern is nonsense - such a pattern can normally never occur in today's markets.

According to the website that you quoted, a candle is engulfing when its body overlaps the body of the candle before. This is indeed programmed this way in the TA-LIB. But the close price of a candle is just the open price of the next candle. So there can never be an engulfing candle, unless there are gaps in the price data between two candles.

Those random gaps can be found indeed in the prices of some years of the FXCM price server. I see that they sometimes differ by one tick, but only in one direction. That's why you got random nonzero values with that candle pattern in past years, but not in 2013.

Candle patterns worked in the 18th century Japanese rice market that had real price gaps overnight. They can not work with financial assets that are traded 24 hours.
Posted By: swingtraderkk

Re: CDLEngulfing() what does it return? - 10/23/13 10:58

Yes makes sense now. Thanks jcl. May still be of use in stock trading or indices/bonds that have a daily open & close, but not with forex.

I also hadn't fully realized that these indicators were from an external library.

I re-implemented it myself as range engulfing range rather than body engulfing body, yet another published strategy that is slightly profitable, but not worth trading.
© 2024 lite-C Forums