Lighting candlesticks with fuzzy logic. | Futures (Cedar Falls, Iowa) | Professional Journal archives from AllBusiness.com
Facebook Twitter You Tube RSS Feed
Recommends

Lighting candlesticks with fuzzy logic.

By Ruggiero, Murray A., Jr.

Friday, March 1 1996
Published on AllBusiness.com

More

Programming software to recognize candlestick patterns can save time and money. Here's how to do it with more complex patterns using fuzzy logic to ease the recognition process.

(Editor's note: Our February 1995 piece "Artificial Trader Jumps Candlesticks" introduced the use of fuzzy logic to program recognition of candlestick patterns. A copy of that article is available for $5.00 through our Cedar Falls editorial office at 1-800-553-2746.)

A single candlestick has these characteristics: color, shape, upper and lower shadow size. But not all characteristics require fuzzy logic. For example, "color" doesn't because it is simply the sign of the close minus the open.

The other attributes aren't so specific. For example, size requires fuzzy logic because a candle's size is relative to nearly all other candles. Also, if a candle with the size of 2 is large, a candle with a size of 1.9 is nearly large, not small. Here's an example of a fuzzy logic function (improved from the version in the February 1995 issue) that identifies a candle with a long shape:

Inputs: OPrice(NUMERICSERIES), CPrice(NUMERICSERIES),LBack(NUMERIC),OneCof(NUMERIC),ZeroCof (NUMERIC); Vars: PrevLong(0),CRange(0),Ave Range(0), ZTrig(0), OneTrig(0), Tall(0), Scale(0); {Calculate the range for the candle} CRange = absvalue(OPrice-CPrice); {Calculate what level represents a 0} ZTrig = Average[(CRange, LBack).sup.*] ZeroCof; {Calculate what level represents a 1} OneTrig = Average[(CRange, LBack).sup.*] OneCof; {Calculate the difference between the zero and one level} Scale = OneTrig-ZTrig; {If one level and zero level are the same set to 99.99 so it can't be a large bar} if Scale = 0 then Scale = 99.99; {Calculate the fuzzy membership to tall} Tall = maxlist(0, minlist(1, (CRange-OneTrig)/(Scale))); {If previous bar is big relax requirements} if Tall[1] = 1 and CRange[1]-ZTrig < > 0 then Tall = maxlist(0,min-list(1, (CRange-CRange[1])/(CRange[1]-ZTrig))); FuzzyLong = Tall;

This function will return a 1 when the current candle size is greater than or equal to OneCof times the average candle size over the last lookback days. It will return a 0 when it is less than ZeroCof times the average size. When the candle size is between these ranges it returns a scaled value between 0 and 1.

This function also can handle the case when the previous candle was very long and the next candle also should be long, but using the general rule based on the average size, the candle would not have been identified correctly. It also handles divide-by-zero conditions that occur when the open and close are the same.

TRENDING NOW:   Save. Spend. Do.,  Free Downloads!,  Credit Crunch Plagues Small Businesses,  Business Resource Center,
BootCamps

AllBusiness Slideshows

seeallslideshows

New On AllBusiness

Find Pre-Screened Suppliers. VoIP, Web Designers, Credir Card Processing, Online Marketing, Telemarketing, Payroll Services VoIP Web Designers Credir Card Processing Online Marketing Telemarketing Payroll Services View all 100 categories