Technical traders realize that technical analysis is more of an art than
science. Until you draw a plethora of lines to fill your chart, which
would render it practically useless, prices rarely "hit the spot" based
on your doodles. This doesn't matter though because trading is not about
charts and guessing numbers. It is about costs and risks (pardon me if
you've heard this a thousand times already). To whom this would matter
though, are the mechanical traders using technical analysis. It may be
*obvious* to a human to discern price patterns because a trading setup
*looks like* something you know. However, figuring out "obvious" and
"looks like" is not trivial in a program. Common ways of tackling this
problem is with stochastic algorithms or Bayesian logic. The drawback
with using these methods though, is that they are difficult to conjure
unless you have some vigorous background in math. Hereby I suggest an
alternative--fuzzy logic. In it's simplest implmentation, fuzzy logic
are mere if-then statements. Here's a sample fuzzy logic control system
for regulating temperature with a fan (it is also a trick solution to
the infamous hysteresis problem in control theory...but I
digress),`IF temperature IS very cold THEN stop fan IF temperature IS cold THEN turn down fan IF temperature IS normal THEN maintain level IF temperature IS hot THEN speed up fan`

As you can see, there can be more than two values for a result. The
classic and ubiquitous TRUE or FALSE boolean is thrown out the window.
Let's dive right into an example of applying fuzzy logic to technical
analysis. Say you are using the RSI as one of your indicators.
Typically, you set a pair of threshold values to determine if the
instrument is overbought or oversold.
`String rsiCondition; if (RSI > 70) rsiCondition = "Overbought"; if (RSI >= 30 && RSI <= 70) rsiCondition = "Neutral"; if (RSI < 30) rsiCondition = "Oversold";`

Then here is what a fuzzy logic implementation would look
like.`String rsiCondition; if (RSI > 90) rsiCondition = "Very overbought!"; if (RSI > 70) rsiCondition = "Overbought"; if (RSI > 60) rsiCondition = "a little overbought"; if (RSI >= 40 && RSI <= 60) rsiCondition = "Neutral"; if (RSI < 40) rsiCondition = "a little oversold"; if (RSI < 30) rsiCondition = "Oversold"; if (RSI < 10) rsiCondition = "Very oversold!";`

In fact, you may have noticed that the first RSI example is already a
3-valued fuzzy logic. And you're right! Fuzzy logic is that easy. So
what can you do with that second RSI example? Well, perhaps you want to
implement fuzzy logic on a MACD as a second indicator. Then you can
implement a "conviction" algorithm (which isn't possible with TRUE/FALSE
algorithms) by summing the two fuzzy logic (see wiki or google for more
information on performing fuzzy logic operations). And then... well.
This is a basic example of exploiting the benefits of fuzzy logic in
automated trading strategies. More advanced use of fuzzy logic is
demonstrated in this seminal work by Lin and Lee, Neural-network-based
fuzzy logic control and decision system, 1991. Fuzzy logic + neural
net! Well, as you can see, this is only the tip of the iceberg. P.S. I
have discussed a lot recently about the frontend work that I have been
working on. This post is a break for the reader and a glimpse at what I
am really doing behind the scenes. Let me know in the comments below
if this is your cup of tea and I'll write more of this type of posts in
the future.

# On technical analysis and fuzzy logic for mechanical trading

Posted 02 September 2010 in algorithmic-trading.