Fuzzy logic makes it clear. | Futures (Cedar Falls, Iowa) | Professional Journal archives from AllBusiness.com
Facebook Twitter You Tube RSS Feed
Recommends

Fuzzy logic makes it clear.

Wednesday, February 1 1995
Published on AllBusiness.com

More

Let's see how to design your own candlestick recognition software.

We'll begin by designing a fuzzy logic candlestick recognition utility. First, we need to define the needed membership functions, which is done in the main story. Next, graph these on paper. Then develop formulas and/or rules that represent these functions. For the shape set (defined in the main text) of membership functions we have three functions: long, small and doji.

Now take a look at the fuzzy membership function for a long shaped candlestick. (Comments are in boldfaced type and in brackets.) The TradeStation code for this function is:

{Fuzzy Logic to define a long candlestick}

Inputs:

OPrice(NUMERICSERIES),CPrice(NUMERICSERIES),LBack(NUMERIC), OneCof(NUMERIC),ZeroCof(NUMERIC);

Variables:

PrevLong(0),CRange(0),AveRange(0),Z

Trig(0),OneTrig(0),Tall(0),Scale(0);

{Calculate the size of the body}

CRange=absvalue(OPrice-CPrice);

{Calculate the Zero and One Trigger}

ZTrig=Average(CRange,LBack)*ZeroCof; OneTrig=Average(CRange,LBack)*One Cof;

{Calculate the Scale}

Scale=OneTrig-ZTrig;

{If Scale is zero then set to 99.99 since FuzzyLong should output a 0}

if Scale=0 then Scale=99.99;

{Calculate value of tall so it can be used in fuzzy long}

Tall=maxlist(0,minlist(1,(CRange-OneTrig)/(Scale)));

{If the previous candle is tall then relax requirement for tall so that we don't get ridiculous requirements for consecutive tall candles. Only that they must be bigger than previous candle to output a 1}

if Tall[1]=1 then Tall=maxlist(0,minlist(1,(CRange-CRange[1])/(CRange[1]-ZTrig))); FuzzyLong=Tall;

The fuzzy long membership function is similar to our tall height function from our child height example except for the rule involving consecutive tall candles. Without this rule it is possible a second tall candle would not be identified even if it was taller than the first.

Here are the definitions for a simple set of membership functions developed for TradeStation that can be used to identify most of the common candlestick patterns.

Candlestick color

* CandleColor(Open,Close)

Candlestick shape

* FuzzyLong(Open,Close,Lookback, OneTrigger,ZeroTrigger)

* FuzzySmall(Open,Close,Lookback, OneTrigger,ZeroTrigger)

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