# Composite Fractal Behavior and its aplications

139662

In describing the cfb I am going to cheat : since it was invented by Jurik, here is what he is saying about it :

What is the Theory Behind CFB ?
CFB tells you how long the market has been in a quality trend. This value can be used to adjust the period length of other indicators, especially stochastic bands.

In order to quantify the overall duration of a market's trend, we replaced classical cycle analysis methods (FFT, MEM, MESA) with a form of analysis that works even when no cycles exist. We accomplished this by examining a time series for specific fractal patterns of any size. We then gather all the patterns found and combine them into one overall index, CFB (Composite Fractal Behavior) Index.

For good reason, CFB does not analyze time series data for dominant cycles. Classical cycle analysis examines data points (e.g. prices) and estimates the average presence of a cycle in the window. Now suppose a cycle with a period length of 9 days was strong for 50 days and then disappeared for the next 14 days. Because the cycle was present for 50 out of the last (50+14=64) days, the average presence of that cycle would be measured as "strong" even though it does not exist anymore!
Does CFB find the Dominant Cycle ?
No! Consider the following discussion about the MYTH of exploiting dominant cycles.

It is true that the market does have predictable cycles due to its "structural" or physical nature. For example, quarterly earning cycles, triple witching cycles, Federal Reserve meetings, weekly cycles, political election year cycles, the annual end-of-year stock dumping cycle, sunspot cycles, and the slow Kitchin (3-5 years), Juglar (7-11 years), Kuznet (15-25 years) and Kondratieff (45-60 years) cycles. They are very predictable and the markets readily discount their presence as far ahead in time as is reasonable. So there's not much left with regard to those cycles for you to exploit.

What traders see as cycles on an hourly chart, for example, is a different matter. The big, obvious cycles you see on price charts are actually the result of a combination of many weak cyclic forces that sometimes line up in phase to produce APPARENT dominant cycles that suggest the presence of a strong structural cycle that, in fact, does not exist. The slightest shifting in phase of any one component (due to crowd psychology, unscheduled events, etc.) will significantly alter the structure of the apparent dominant wave. This may drive the cycle into a "null" or random period, then reappear, completely out of phase. Now you see it ... and now you don't.

The transitory nature of these apparent dominant cycles makes their automated detection difficult and forecast unreliable. Sometimes cycle forecasting tools appear accurate and other times they are totally off mark. The reason is that tools designed to spot dominant cycles will announce whatever they find, even if they are only apparent (not structural) and transitory. For example, such tools would have no problem detecting cycles in the six charts below. But there is just one problem --- the slow cyclic price action in the six charts below is *impossible* to project into the future with any reasonable accuracy!

Why? Because we produced these six charts by simply adding consecutive random price changes. That's right!! These charts are nothing more than RANDOM WALKS. And by definition, they cannot be forecasted, no matter how impressive their apparent cyclic behavior may be!

The chart above does not "prove" market cycles are non-existent. Indeed, discretionary traders can learn to spot and use periodic price events, and take time to "understand" their causes, in order to verify whether the relevant triggers have actually occurred.

This demonstration does show, however, that cycle-finding tools like FFT, MESA and periodigrams, which have no understanding of market cause-effect relationships, can be easily fooled into seeing ghosts. In contrast, our CFB tool was designed to measure market trending action without assuming the existance of cycles. This makes CFB more reliable.

How would I use CFB's results ?
CFB produces a value proportional to a time series' trend duration. This value is in units of TIME, as measured in bars on a chart. Because CFB's output is in units of time and not price, CFB offers a unique window into a new dimension for representing signal behavior.

Investors have discovered many profitable ways to apply CFB:

* To auto-adjust the lookback of classical indicators, such as RSI

* To auto-adjust the lookback depth of breakout channels in trending markets

* To auto-adjust the minimum amount of retracement needed to reverse position

Making a profit in the market requires your finding a unique niche that very few other people are exploiting. CFB offers this unique perspective.

Do I specify a "period length" for CFB?
In CFB, period length determines how many bars (time slices) are examined for specific fractal patterns. Due to the complexity of the algorithm, CFB permits only four period lengths: 24, 48, 96, 192. The 24-bar version can see trend fractals up to 24 bars wide, and so on. You get all four versions when ordering CFB.

________________________________

Now that was Jurik

The main problem in building this indicator for metatrader was the shear number of buffers it must use for its calculations and the calculations itself. There were some attempts to make it, but those were stopped at a first step : making a basic calculation function and that was all that was done. This is the "real" one. With some additions of course

In this indicator the "period" is replaced with "depth" :
depth 1 -> period 24

depth 2 -> period 32

depth 3 -> period 48

depth 4 -> period 64

depth 5 -> period 96

depth 6 -> period 128

depth 7 -> period 192

What deviates from Juriks cfb is the post smoothing : since the slope should determine the "trending" or "no trending" that I thought that some smoothing would not hurt. Smoothing used is the one from one more average and gives satisfactory results. Do not confuse the Smooth parameter with SmoothResult, SmoothSpeedand SmoothAdaptiveparameters. Smooth is a part of cfb calculations and the last 3 are used to smooth the already calculated cfb.

PS: attached a welth lab source that I used as a model for this indicator. Do not be alarmed when you compare the two sources : that is cfb (value wise the same thing, believe me, just everything can be done a BIT differently and faster ) Also attached what can be found and what people wrongly believe to be a cfb : the cfbAux function (this function is a correct, if you compare it to those posted on some sites )

____________________________

Updated version posted here : Composite Fractal Behavior and its aplications

Files:
139662

...

One (simple this time) implementation of cfb : cfb channel

This channel is a high/low channel with a twist. The channel and its "speed" are modified by a "stochastic-ised" cfb in order to be more responsive

_______________________________

Of parameters :
CfbResultSmooth-> when set to values > 1 smooths internal cfb results used by this indicator

Depth1-> the minimal "depth" of the high/low lookback

Depth2-> the maximal "depth" of the high/low lookback

CfbDepth, CfbPriceand CfbSmoothare the parameters passed to cfb, and for explanation of them, please look at the previous post.

_______________________________

PS: this indicator is made as a direct idea of Mark Jurik, and is interesting as a simplest implementation of cfb in another indicator. Later on will be posted some much more useful implementations (like cfb modified speed of RSX, for example) Also attached the stochastic of the cfb - it might be interesting to see exactly when and why is the channel modified, but also there is some interesting behavior of the stochastic version itself as a standalone indicator

PPS: updated version of cfb stochastic posted here https://www.mql5.com/en/forum/179686

2078

Cfb channel+oma

One (simple this time) implementation of cfb : cfb channel

This channel is a high/low channel with a twist. The channel and its "speed" are modified by a "stochastic-ised" cfb in order to be more responsive

_______________________________

Of parameters :
CfbResultSmooth-> when set to values > 1 smooths internal cfb results used by this indicator

Depth1-> the minimal "depth" of the high/low lookback

Depth2-> the maximal "depth" of the high/low lookback

CfbDepth, CfbPriceand CfbSmoothare the parameters passed to cfb, and for explanation of them, please look at the previous post.

_______________________________

PS: this indicator is made as a direct idea of Mark Jurik, and is interesting as a simplest implementation of cfb in another indicator. Later on will be posted some much more useful implementations (like cfb modified speed of RSX, for example) Also attached the stochastic of the cfb - it might be interesting to see exactly when and why is the channel modified, but also there is some interesting behavior of the stochastic version itself as a standalone indicator

Your CFB channel is very interesting when used in combination with your OMA,usual settings I use that I explained at your "one more average" thread.

Please see pic...The basic idea is as follows...for longs(inverse for shorts,same concept)

1-SETUP:Price Closes below external OMA,once the OMAS have crossed(Adaptive over non Adaptive)

2-Entry trigger:We wait for the cfb channel band to flatten,then enter at bar close...this will usually give us an entry with price action in our favour,and good "company" (orderflow)...so,we will not enter at the low,but we will enter a very good probability trade....see pic with the arrow

3-Stoploss:1/2 ATR Below lower low,which,probably,will be previous bar low...move to BE once first TP is touched or, in case you choose OPTION2 for TP,when 1 H4 ATR is reached....then Trail(optional,I personally do not believe in trailing stops)

4-TP:

Option1: 1/3 at 1 ATR H4,1/3 at near support,1/3 At next OMA cross.

Option2: 1/2 at 1 D1 ATR,1/2 at next OMA cross...

I think that this basic method can be used to catch the 123..or first retracement at the beginning of a new swing.

Additionally,I have been testing your CFB Stochastic with CRB bars,there are interesting patterns there,for sure,but totally unrelated to the "usual" stochastics behaviour ...When I am sure about them,I will post an example.

Regards

S

Files:
139662

These posts from mrtools (https://www.mql5.com/en/forum/general) and simba (https://www.mql5.com/en/forum/general) reminded me of the work I still want to do on this thread and indicators

__________________________

For a moment I am not going to post any new cfb based indicator but am going to talk about something else : some misconceptions coming from the original developer of cfb (Mark Jurik) himself and some problems needed to be solved before the practical ways of its usage turn to more or less "solid ways".

Of some misconceptions :
Mark Jurik, when using cfb as an modifier of some other indicator uses what he calls a "infinite length stochastic" to determine the length modifier (ratio) which then becomes an "cfb depending adaptive" indicator. A nice, catchy name (the "infinite length stochastic"), but what exactly does it mean?
The "infinite" means that the high an the low are determined using the whole history available. And there is the problem

For the sake of argument, just imagine that there are, let say, 10 values of cfb : 10,1,1,1,1,1,1,1,1 (the left most (10) being the oldest) Obviously that the one that has 10 bars of history will have 10 for maximum and 1 for minimum.

1st consequence: it is causing a "values deforming" since the extremes that occur are determining current range too, and it artificially "speeds up" indicator behavior in calm period (actually in any period calmer than the moments when those extremes happened - cfb is bounded from the lower side to 0, hence the "speeding up" - lower bound can not vary too much)

2nd consequence : if someone does not have same amount of historical data he/she may end up in having completely different indicator readings

3rd consequence: it will repaint. In any case when the number of historical bars is limited (and that case is with almost all trading platforms and systems). And if you want to avoid repainting you are going to be forced to keep the complete history in your charts in order to make it not repaint. And then you are ending up with ranges valid some 20 years ago (a sort of a "vicious circle" - which bad should we choose (which bad is less bad )?)

Cfb channel from the 1st post is coded the "infinite length stochastic" way. I will be added what I consider a normal way, as soon as I solve some problems (thoughts) with normalization.

__________________________

Now about normalization : the usual and considered by a lot of people as the acceptable and good is the stochastic. The cfb stochastic indicator is made for that purpose in mind originally. Even though Mark Jurik uses the "infinite way" even in his version of cfb stochastic, I decided to leave it out (for the reasons I stated) original stochastic is a good way, but frankly, I am looking for something better.

So far the best I have found (well, at least the one I like the best) is this one (posting the indicator itself too) It is using a basic (but really the "basic" basic way of normalization), but with rather good results (see the picture attached : upper is the normalized cfb and lower is the original one)

The problem consists in a fact that it largely depends on the normalization constant. As soon as that problem is solved, we shall have some new indicators in this section

__________________________

The moral (could not resist, sorry ) : do not believe even to Mark Jurik. Everybody can make mistakes

__________________________

Updated version posted here : https://www.mql5.com/en/forum/179686

Files:
9489

Thanks Mladen for your indicator and detailed explanation! Between you and Simba, a continuous learning experience.

139662

...

mrtools:
Thanks Mladen for your indicator and detailed explanation! Between you and Simba, a continuous learning experience.

As usual, both of you ask some questions that can not be taken lightly let alone answered easily

Anyway, will post here some other ways of normalizations since there is an everlasting need for "normalizers" and, due the some specific demands cfb puts before us, it seems a good spot to give some solutions (even if not ideal, yet) These posts are probably going to be much more useful to coders visiting this thread than to traders, but I ask for patience from "pure traders" for the goal is to get some better (faster) responding indicators

___________________________________

The specific demand is that cfb shows by its slope, if there is a trend or there is no trend. If the slope is positive, there is a trend. If the slope is negative, there is no trend. So the good thing from a normalized cfb value would be to preserve the slope itself too (hence the problem with the stochastic version - observe the flat periods around minimums and maximums).

___________________________________

So the next way : zero mean normalization. formula is simple : subtract a mean from a value and divide the result with deviation of the same value. It is not the normalization we are looking after because it, in theory, does not have a defined maximum and minimum, but it, statistically has more than 90% values in the range of -3 +3, so it can be considered her (and is used after in another way of normalization which I will post later).

If you observe the compared values of the original you will observe that the "deformity" in the mean of slope changing is significant (in some periods it completely changes the slope) so the conclusion is that, when used for cfb, it is not good

___________________________________

Updated version posted here : https://www.mql5.com/en/forum/179686

Files:
139662

Sigmoidal (Softmax) normalized cfb

Sigmoidal (Softmax) normalization is frequently used in NN in order to prepare normalized values as the input for the artificial neuro net.

__________________________

It is an offspring of zero mean normalization and, as you will see, it inherits it bad sides almost in full, so no wonder that some NNs are performing they way they are (if they use this way of normalization)

Basic formula is NV = 1/(1+(e raised to -zeroMean)). it produces results in the range of 0 to +1.

A hyperbolic version of sigmoidal normalization uses a slightly different formula : (1-(e raised to -zeroMean))/(1+(e raised to -zeroMean)). Hyperbolic calculation produces results in the range of 1- to +1

__________________________

The results : as you can see they inherit almost in full the bad side of "zero mean" normalization : slope change is almost the same as zero mean for both calculations

__________________________

Updated version posted here : https://www.mql5.com/en/forum/179686

Files:
139662

A variation

Simba mentioned lognormal, so I decided to make a little experiment

_________________________

This one is a variation to a sigmoidal version but the difference is that it does not use zero mean calculation of a value but a simple logarithm of a cfb value. Results are interesting. If a regular "logistic" sigmoidal normalization formula is used, than, since cfb values are > 0, it leaves a gap in the range of 0 to 0.5. But, with a simple little trick by applying hyperbolic formula, it is shifted down, and it becomes "usable" for the purpose.

Problem to solve : cfb values in the range of 0 to +1 (they are rare, but can happen) are causing negative logarithm values which can, in some cases, cause huge deformations, Cfb values > 1 are treated rather correctly and the slope is preserved in much more cases than the zero mean or original sigmoidal way

_________________________

PS: just realized that the cfb values of 0 to +1 will produce values that converge to 0 in the hyperbolic version of calculation, so, that problem does not exist. This one is definitely a good candidate to use in adaptive indicators

Updated version posted here : https://www.mql5.com/en/forum/179686

Files:
2078

mrtools:
Thanks Mladen for your indicator and detailed explanation! Between you and Simba, a continuous learning experience.

Thanks Tools,between you and Mladen kind help,it is a continuous learning experience

S

139662

Well, continuing here too __________________________

Velocity that uses cfb for changing / adapting it's length. The velocity itself is a smoothed momentum indicator and can be used as a signal indicator (a clear "zero cross" signal is rather good) Cfb adaptive has a goal of getting those zero crosses faster than the regular velocity

__________________________

Attaching here the velocity indicator itself (this is a bit different variation of it) and a comparison of velocity to momentum indicator :

The "cfb adaptive" differs in one essential parameter : it does not have a Length parameter but it rather has a LowLimit and HighLimit. It means that the length will vary between LowLimit and HighLimit depending on the current state of the cfb used for it.

Here is a comparison of a regular 30,5,Close velocity and a 20,40,5,Close (the rest is default) adaptive velocity (as a case when we can "compare" the 2). From even a quick look, we can conclude 2 things : 1- it is not a "middle of the range" case (just see the differences) and 2 - in some situations it gives dramatically faster crosses.

or with cfb depth set to 1 (so the fastest cfb)

PS: this indicator needs the cfb indicator from the first post in order to work

Updated version posted here : https://www.mql5.com/en/forum/179686

Files:
9489