Logic Nodes


The Logic template system is where the real power and flexibility of BloodHound exists.  With logic you can manipulate the raw output from solvers and create constructs that produce outputs to match your specific goals – be it: specifying entry signals for trading, filtering existing signals from another system, or even identifying exit conditions.

Logic Primer

BloodHound’s logic template system is based on fuzzy logic.  If you are familiar with Boolean logic, fuzzy logic is a very natural extension of Boolean logic, and in many cases you can design logic constructs in much the same way you would regular Boolean logic and get the results you would otherwise expect.

Boolean logic uses a few fundamental operations from which it is possible to create any possible combination of logic statements.  They are: AND, OR and NOT.  Even if you are not familiar with these logical operators they are easy to understand, as they function exactly like their names.

For the purposes of constructing an example we will consider the two statements

  1. Statement 1: “slope of the Stochastic D Indicator is good”
  2. Statement 2: “closing price is on the good side of the EMA(100)”

For information on how we can configure Solvers to emulate these statements, see the Confidence Solver overview.

AND and OR

AND will only result to true when both statements (called operands) are also true. Thus in the example above, if we labeled “slope of the Stochastic D Indicator is good” statement 1, and “closing price is on the good side of the EMA(100)” as statement 2:

Statement 1 AND Statement 2 is true, if and only if Statement 1 is true, and Statement 2 is true.

Similarly for OR:

Statement 1 OR Statement 2 is true if and only if at least one of the statements are true.

Both AND and OR can also chain together multiple operands, and the result is basically what you would expect if you were to describe it in natural language. For example: Statement 1 AND Statement 2 AND Statement 3 is true if and only if all statements (1 through 3) are true. Similarly Statement 1 OR Statement 2 OR Statement 3 is true if and only if any one of the statements are true.

NOT

A logic NOT operation reverses the statement from true to false, and false to true. Thus in our example, if the Statement 1 is true, than NOT Statement 1 is false.

NOT works as intuitively as you might expect. If you consider that Statement 1 was defined as “slope of the Stochastic D Indicator is good”, then NOT Statement 1 can be thought of as: “slope of the Stochastic D Indicator is not good”.

Fuzzy Logic

As you may have seen previously, BloodHound works with an extension of Boolean logic known as fuzzy logic. It was designed by mathematicians with the goal of adapting the hard digital edges of the logical systems to fit the more organic and chaotic patterns of the real world. Aside from that, fuzzy logic behaves much the same way and indeed it is possible to create a fuzzy logic system that works identically to a regular logic system. Thus by extension, you may choose to take full advantage of BloodHound’s fuzzy logic capability or not. The choice is up to you.

With fuzzy logic, there are some subtle differences in the interpretation of “true”. The easiest way to conceptualize fuzzy logic (in the context of BloodHound) is to substitute the word “true” with “favorable”, since there are actually degrees of truth in a fuzzy logic system. If you recall, solvers and logic nodes in BloodHound output a value between 0 and 1.0, 1.0 being the most favorable value (or the highest degree of truth). Decimal numbers such as 0.3 or 0.7 are just as valid in a fuzzy logic system and can be interpreted to represent “not so true” and “substantially true” respectively. In contrast, to use a purely digital approach like a regular logic system, you would abandon decimal values and configure your solvers to output only 1’s (true) and 0’s (false).

In our previous example with the two statements in the previous section, the solver that evaluates Statement 1 may produce a high number during the long evaluation, say 0.90 if the slope is steeply positive. But it is more than possible to configure the solver to give you a lower value, say 0.70 if the slope is relatively flat (but still positive). In that case, Statement 1 is still “true” but to a lesser degree.

Fuzzy AND

For a fuzzy logic AND, the result is only favorable if all the statements (called operands) are also favorable. In fact a fuzzy logic AND is the minimum value from all operands. So if the solvers from Statement 1 and Statement 2 were producing 0.5 and 0.7 respectively, an AND node connected to both statements would produce a 0.5. This generally means that the at best Statement 1 AND Statement 2 is only “half true” or “partially favorable”, because Statement 1 was only “partially favorable”.

As before, you can chain to together AND statements. Consider:

Statement 1 AND Statement 2 AND Statement 3 AND Statement 4.

This will only be favorable if and only if all of the statements are favorable.

Fuzzy OR

The fuzzy OR  works very similar to the fuzzy AND except the result is only favorable if any of the operands have a favorable value. Mathematically a fuzzy logic OR is simply the maximum value of all inputs. This ensures the highest input value is represented in the output. Similar to the fuzzy AND, you can also chain multiple OR statements together, and the result will work as expected, that is if any one of the statements are favorable, your overall result will be favorable.

Fuzzy NOT

Fuzzy NOT takes the operand and performs an inversion of the value, which is to take the value and subtract it from 1.0.  Thus a relatively low value of 0.3 becomes a much higher value of 0.7 (derived from 1.0 -0.3).  Similarly, a value of say 0.85 becomes a relatively low value of 0.15 (1 -0.85).

If you pause to think about this: inverting a once high value into a low value makes sense. Fuzzy NOT inverts a favorable value into an unfavorable value, just as the word “not” inverts the meaning of a statement in natural language.

Fuzzy Hedges

Aside from standard logic operations, fuzzy logic allows you alter the meaning of a statement (represented by a fuzzy value) by simply modifying the value. This modification is known as a fuzzy hedge. We will now discuss the 2 fuzzy hedges supported by BloodHound: VERY and SOMEWHAT.

Fuzzy Very

Consider the statement from our previous value: “slope of the Stochastic D Indicator is good”. Suppose you wanted to make your criteria more stringent, that is you are looking for a “very good” slope before taking a trade. For the purposes of simplicity, let us suppose that the steeper the slope in a given direction, the more favorable it is for your trading system. Thus to arrive at a very good slope we would be looking for a very steep slope.

In order to ensure that only a very good slope is observed, we must deflate the values by squaring them. This will ensure that only a very high value results in favorable value. Thus the fuzzy hedge for VERY is achieved by squaring the original value. For example, if we had a value of 0.8 (a relatively high value) for statement 1, then VERY Statement 1 (in our example this would mean: “slope for the Stochastic D Indicator is very good”) would be:

0.8^2=0.64

As you can see a very high number would have to suffice for a favorable outcome of VERY Statement 1.

Fuzzy Somewhat

In contrast to VERY, fuzzy hedge SOMEWHAT performs the opposite modification. It is used when you need to relax the criteria of your statement so that mediocre values are can pass as favorable.

This is achieved by square-rooting the original value. In our example, suppose that Statement 1 produced a value of 0.65 (a relatively mediocre value). Then SOMEWHAT Statement 1 would be calculated by:

sqrt{0.65}=0.81

In our previous example, this can be interpreted as: “slope of Stochastic D is somewhat good”. The hedge SOMEWHAT has taken the mediocre value of 0.65 and turned it into the relatively high value of 0.81, allowing it to pass as a relatively favorable value.

BloodHound’s Logic Nodes

BloodHound comes with both the AND and OR logic nodes, as well as two special Ratio and Addition logic nodes for fuzzy logic manipulation.

You will notice that when you add this node to the node workspace, there will be one open input connection on the left hand side, and an output connection on the right hand side.

The inputs are considered operands, and you can connect a solver directly to this connection or the output from another logic node. As you connect other nodes to this node, you will notice that another open input connection appears, allowing you to connect as many inputs to this node as you desire.

You can find out more information about BloodHound’s implementation of the fuzzy logic nodes at the links below:

NOT and Fuzzy Hedges

BloodHound allows you to apply fuzzy logic hedges VERY and SOMEWHAT as well as NOT to any logic or solver node in the node workspace. To do this, select the desired node in the node workspace. You will notice that the weight slider control for the node is now visible on the right hand sidebar. Right-click the weight slider to bring up the context menu, and find the Hedge sub-menu. From there you can choose to apply the fuzzy logic hedges VERY and SOMEWHAT. Additionally you can invert the node’s value by applying NOT.