Asked by FRANCISCO
on 30 Sep 2013

I would like to ask a question. I want to create an algorithm to compute technical indicator values from matlab because I can not export the data directly. This indicator is called Bill Williams fractal indicator. A little explanation is in this link, although it is in Spanish can be understood well, in case anyone wants to pursue the subject.

http://www.tecnicasdetrading.com/2012/03/patron-fractal-de-bill-williams.html

I explain how this indicator. I have a list of times that I show prices, High, Low and Close. The definition of this indicator fractal is a fractal bullish indication arises when the two previous candles are maximums under the third candle and candle 4 has maximum sailing less than 3 and 5 has maximum sail sailing less than 3 and 4 . A candle is the figure that shows high, low and close. A fractal downward when the candle is formed 3 has a higher minimum than candles 1 and 2, and candles 4 and 5 are less than the minimum candle 3 A figure with a better explanation is in the link above. I think the logical sequence would be:

n = current candle

1-high (n-2) <high (n)

2-high (n-1) <high (n)

3-high (n +1) <high (n)

4-high (n +2) <high (n)

5-low (n-2)> low (n)

6-low (n-1)> low (n)

7-low (n +1)> low (n)

8-low (n +2)> low (n)

As could implement the algorithm?

thank you very much

"A fractal is one of five indicators of Bill Williams' trading system, que Allows detecting the bottom or the top.Fractal Technical Indicator it is a series of At least five successive bars, With The highest HIGH in themiddle, and two lower highs on Both Sides. The reversing September is a series of At least five successive bars, With The Lowest LOW in the middle, and two higher lows on Both Sides, que correlates to the sellfractal. The fractals are have high and Low values and are Indicated With The up and down arrows. "

There is no legitimate formula for Fractals because they are formed when there is a series of 5 consecutive bars where the middle bar is the highest or lowest.

Answer by dpb
on 30 Sep 2013

Edited by dpb
on 1 Oct 2013

Accepted answer

Sraightforward, "brain-dead" solution would seem to be

indp=false(1,length(x)-5+1); for ix=3:length(x)-2 indp(ix-2)=max(x(ix-2:ix+2)==x(ix)); end

Make the obvious fixup for the indm (minimum). Returns a logical vector of locations that meet the positive criterion. An alternate return of location and/or value is an (also hopefully obvious) extension.

**accumarray** could be useful in vectorizing, undoubtedly.

ADDENDUM:

>> x=round(10*rand(1,10)) x = 6 4 8 5 4 9 8 6 6 6 >> accumarray([1:6]',[3:8]',[],@(ix) max(x(ix-2:ix+2))==x(ix))' ans = 1 0 0 1 0 0 >>

NB1: I adjusted spacing above to lineup the values w/ those of the input for visual comparison

On retrospect, you'll probably want to pre-/post-pend the two False values to have the return vector the same length as the original in this implementation or use the actual locations instead.

That is,

>> [x;false(1,2) accumarray([1:6]',[3:8]',[],@(ix) max(x(ix-2:ix+2))==x(ix))' false(1,2)] ans = 6 4 8 5 4 9 8 6 6 6 0 0 1 0 0 1 0 0 0 0 >>

NB2: Substitute appropriate length values in place of the constant subscripting vectors above.

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments