"

FRASMA: Fractally Modified Simple Moving Average

by Dr.Hamdi Boukamcha
Name:
FRASMA: Fractally Modified Simple Moving Average
Author: jppoton (2009.02.18 08:11)
Rating: 10
Downloaded: 9248
Download:
FRASMA: Fractally Modified Simple Moving Average   FRASMA.mq4 (9.7 Kb) View
FRASMA: Fractally Modified Simple Moving Average   fractal_dimension.mq4 (15.9 Kb) View
The SMA is accelerated during a trend and slowed down during a sideways market, so as to avoid false signals. It’s using the fractal dimension as computed by iliko [[email protected]] in his indicator called fractal_dimension.mq4, and makes use of it to smooth the SMA. I feel it is best used in combination with it, so I attached the file (though both indicators are independent and can be used alone).

FRASMA: Fractally Modified Simple Moving Average

 

The theoretical details behind the logic of this indicator can be found on my blog: http://fractalfinance.blogspot.com/

This indicator can then be used for bands trading, and I intend to develop a fractalised bollinger bands based on it in the next few weeks.

18 comments: 1 2   To post a new comment, please log in or register

jppoton, thanks for good idea. +10.

09.09.2009 23:03 Blaid73

For anyone who would like to add support for median, typical, or weighted pricing to their FRASMA or FRASMAv2 please replace the _computeLastNbBars function with the below:

Just recompile and all should work as normal.

Tai

void _computeLastNbBars( int lastBars )
  {
   int pos;
   switch( e_type_data )
     {
      case PRICE_CLOSE    : _FRASMA( lastBars, Close ); break;
      case PRICE_OPEN     : _FRASMA( lastBars, Open ); break;
      case PRICE_HIGH     : _FRASMA( lastBars, High ); break;
      case PRICE_LOW      : _FRASMA( lastBars, Low ); break;
      case PRICE_MEDIAN   :
         for( pos=lastBars; pos>=0; pos--)ExtOutputBuffer[pos]=(High[pos]+Low[pos])/2.0; _FRASMA( lastBars, ExtOutputBuffer );
         break;
      case PRICE_TYPICAL  :
         for( pos=lastBars; pos>=0; pos--)ExtOutputBuffer[pos]=(High[pos]+Low[pos]+Close[pos])/3.0; _FRASMA( lastBars, ExtOutputBuffer );
         break;
      case PRICE_WEIGHTED :
         for( pos=lastBars; pos>=0; pos--)ExtOutputBuffer[pos]=(High[pos]+Low[pos]+Close[pos]+Close[pos])/4.0; _FRASMA( lastBars, ExtOutputBuffer );
         break;
      default :
         Alert( "[ 20-ERROR  " + FILENAME + " ] the imput parameter e_type_data <" + e_type_data + "> is unknown" );
     }
  }
21.07.2009 15:02 tsheppard

tsheppard wrote:

jppoton wrote:

tsheppard wrote:
Hi Jean-Philippe,

I hope you’re doing well.

I’ve downloaded FRASMA and find it fascinating, but I’m not a very mathematical person. I spent quite a long time reading your blog and I must say I’m more confused now than before I went 🙂

I understood clearly your explanation of using SMA over EMA which would seem to make perfect sense, if indeed you are an intra-day trader as I am.

What I wasn’t clear on, and could not find a clear understanding of on your blog are the settings to use when replacing a current SMA/EMA with FRASMA.

I assume that e_period and e_type_data would be the Period: and Apply to: settings of the current moving average that you’re replacing, but I have no idea what the normal_speed setting should be, or how I should calculate it.

For instance, I am currently using a 50 period, weighted EMA which I would like to replace with a 50 Period FRASMA.

Since it’s not possible to utilize a weighted close, (FRASMA does not allow e_type_data > 3), how would I set this up, and most importantly for future reference, how does one calculate the normal_speed of a FRASMA?

Thank you so much for your hard work and your great contribution to the community 🙂

Tai

Hi Tai,

Thanks for your interesting comments.

As for your questions, the e_period is not directly used in relation with the FRASMA, but rather is the number of bars used to calculate the Fractal Graph Dimension, fdi in the program, via the line:

fdi=1.0 +(MathLog( length)+ LOG_2 )/MathLog( 2 * e_period );

This fdi is then, in turn used to calculate the Trail dimension:

trail_dim=1/(2-fdi);

Then the alpha is half of this Trail dimension, and this alpha is then used to calculate the resulting fractalised speed of the FRASMA which really is an SMA with a variable fractalised speed:

speed=MathRound(normal_speed*alpha);
ExtOutputBuffer[pos]=iMA(NULL,0,speed,0,0,0,pos);

 

As for the normal_speed, it really is the speed you want the SMA to be in when there is no need to fractalise it, it therefore is the speed of your SMA before it becomes the FRASMA, which in your case, seems to be 50. One thing you may want to take care of, is to increase the e_period to a value higher than the normal_speed, that would seem more sensible to me, given that having a normal_speed higher than the e-period, would be to modify an information based on more data with another one based on less data. If therefore you want to put normal_speed at 50, I would think e_period should be something like 60, keep in mind though that this will slow down a bit the time response on your computer, given that the program will do more calculations than before, on my PC, it still not too much of a problem, though, change of time-scale gets a bit slower.

Hope this helps, if you are any more doubts or questions, you are welcome to ask me again.

Cheers

Jean-Philippe

 

 

 

 

Excellent, thanks Jean-Philippe.

I did have one other question, it may be a silly one considering my math expertise is limited, but is there a specific reason that you did not include typical, median and weighted prices?

I added them into my version, slightly modifying the code in FGDI, and they seem to work fine.

No big deal just wondering.

Thanks again.

Tai

Hi Tai,

No, you are right, it’s a mistake on my part, you are perfectly justified to use the typical, median and weighted price as you see fit. I just forgot to add them.

Cheers

Jean-Philippe

21.07.2009 02:30 jppoton

jppoton wrote:

tsheppard wrote:
Hi Jean-Philippe,

I hope you’re doing well.

I’ve downloaded FRASMA and find it fascinating, but I’m not a very mathematical person. I spent quite a long time reading your blog and I must say I’m more confused now than before I went 🙂

I understood clearly your explanation of using SMA over EMA which would seem to make perfect sense, if indeed you are an intra-day trader as I am.

What I wasn’t clear on, and could not find a clear understanding of on your blog are the settings to use when replacing a current SMA/EMA with FRASMA.

I assume that e_period and e_type_data would be the Period: and Apply to: settings of the current moving average that you’re replacing, but I have no idea what the normal_speed setting should be, or how I should calculate it.

For instance, I am currently using a 50 period, weighted EMA which I would like to replace with a 50 Period FRASMA.

Since it’s not possible to utilize a weighted close, (FRASMA does not allow e_type_data > 3), how would I set this up, and most importantly for future reference, how does one calculate the normal_speed of a FRASMA?

Thank you so much for your hard work and your great contribution to the community 🙂

Tai

Hi Tai,

Thanks for your interesting comments.

As for your questions, the e_period is not directly used in relation with the FRASMA, but rather is the number of bars used to calculate the Fractal Graph Dimension, fdi in the program, via the line:

fdi=1.0 +(MathLog( length)+ LOG_2 )/MathLog( 2 * e_period );

This fdi is then, in turn used to calculate the Trail dimension:

trail_dim=1/(2-fdi);

Then the alpha is half of this Trail dimension, and this alpha is then used to calculate the resulting fractalised speed of the FRASMA which really is an SMA with a variable fractalised speed:

speed=MathRound(normal_speed*alpha);
ExtOutputBuffer[pos]=iMA(NULL,0,speed,0,0,0,pos);

 

As for the normal_speed, it really is the speed you want the SMA to be in when there is no need to fractalise it, it therefore is the speed of your SMA before it becomes the FRASMA, which in your case, seems to be 50. One thing you may want to take care of, is to increase the e_period to a value higher than the normal_speed, that would seem more sensible to me, given that having a normal_speed higher than the e-period, would be to modify an information based on more data with another one based on less data. If therefore you want to put normal_speed at 50, I would think e_period should be something like 60, keep in mind though that this will slow down a bit the time response on your computer, given that the program will do more calculations than before, on my PC, it still not too much of a problem, though, change of time-scale gets a bit slower.

Hope this helps, if you are any more doubts or questions, you are welcome to ask me again.

Cheers

Jean-Philippe

 

 

 

 

Excellent, thanks Jean-Philippe.

I did have one other question, it may be a silly one considering my math expertise is limited, but is there a specific reason that you did not include typical, median and weighted prices?

I added them into my version, slightly modifying the code in FGDI, and they seem to work fine.

No big deal just wondering.

Thanks again.

Tai

21.07.2009 01:48 tsheppard

tsheppard wrote:
Hi Jean-Philippe,

I hope you’re doing well.

I’ve downloaded FRASMA and find it fascinating, but I’m not a very mathematical person. I spent quite a long time reading your blog and I must say I’m more confused now than before I went 🙂

I understood clearly your explanation of using SMA over EMA which would seem to make perfect sense, if indeed you are an intra-day trader as I am.

What I wasn’t clear on, and could not find a clear understanding of on your blog are the settings to use when replacing a current SMA/EMA with FRASMA.

I assume that e_period and e_type_data would be the Period: and Apply to: settings of the current moving average that you’re replacing, but I have no idea what the normal_speed setting should be, or how I should calculate it.

For instance, I am currently using a 50 period, weighted EMA which I would like to replace with a 50 Period FRASMA.

Since it’s not possible to utilize a weighted close, (FRASMA does not allow e_type_data > 3), how would I set this up, and most importantly for future reference, how does one calculate the normal_speed of a FRASMA?

Thank you so much for your hard work and your great contribution to the community 🙂

Tai

Hi Tai,

Thanks for your interesting comments.

As for your questions, the e_period is not directly used in relation with the FRASMA, but rather is the number of bars used to calculate the Fractal Graph Dimension, fdi in the program, via the line:

fdi=1.0 +(MathLog( length)+ LOG_2 )/MathLog( 2 * e_period );

This fdi is then, in turn used to calculate the Trail dimension:

trail_dim=1/(2-fdi);

Then the alpha is half of this Trail dimension, and this alpha is then used to calculate the resulting fractalised speed of the FRASMA which really is an SMA with a variable fractalised speed:

speed=MathRound(normal_speed*alpha);
ExtOutputBuffer[pos]=iMA(NULL,0,speed,0,0,0,pos);

 

As for the normal_speed, it really is the speed you want the SMA to be in when there is no need to fractalise it, it therefore is the speed of your SMA before it becomes the FRASMA, which in your case, seems to be 50. One thing you may want to take care of, is to increase the e_period to a value higher than the normal_speed, that would seem more sensible to me, given that having a normal_speed higher than the e-period, would be to modify an information based on more data with another one based on less data. If therefore you want to put normal_speed at 50, I would think e_period should be something like 60, keep in mind though that this will slow down a bit the time response on your computer, given that the program will do more calculations than before, on my PC, it still not too much of a problem, though, change of time-scale gets a bit slower.

Hope this helps, if you are any more doubts or questions, you are welcome to ask me again.

Cheers

Jean-Philippe

 

 

 

 

20.07.2009 20:51 jppoton

Hi Jean-Philippe,

I hope you’re doing well.

I’ve downloaded FRASMA and find it fascinating, but I’m not a very mathematical person. I spent quite a long time reading your blog and I must say I’m more confused now than before I went 🙂

I understood clearly your explanation of using SMA over EMA which would seem to make perfect sense, if indeed you are an intra-day trader as I am.

What I wasn’t clear on, and could not find a clear understanding of on your blog are the settings to use when replacing a current SMA/EMA with FRASMA.

I assume that e_period and e_type_data would be the Period: and Apply to: settings of the current moving average that you’re replacing, but I have no idea what the normal_speed setting should be, or how I should calculate it.

For instance, I am currently using a 50 period, weighted EMA which I would like to replace with a 50 Period FRASMA.

Since it’s not possible to utilize a weighted close, (FRASMA does not allow e_type_data > 3), how would I set this up, and most importantly for future reference, how does one calculate the normal_speed of a FRASMA?

Thank you so much for your hard work and your great contribution to the community 🙂

Tai

19.07.2009 10:19 tsheppard

jppoton wrote:

MadCow wrote:

funyoo wrote:
Thanks for these indicators. I have tried to code an expert advisor based on the fractal dimension.

jppoton

I read your blog, and it convinced me that your use of Fractal dimension is better than Ehlers. Good work, and thanks for the excellent explanation.

On funyoo’s site he states that there is a problem with the indicator. The EA he has made works pretty well on the strategy tester, but that’s not much proof. Someone there suggested that ‘fractal dimension.mq4’ may be repainting. The indicator seems to change color one bar before it crosses the threshold, but not in all cases, as if it occasionally gets a peek into the future. Please comment on this.

Hi MadCow,

Thanks for your appreciation.

I just replied to Funyoo in his thread on Trading System FOREX. As I said there, I don’t think FDI repaints anything, simply the “curve” of FDI is just linking points of a discrete set, and the color is determined by the end point of the segment drawn, it may then be the case that the starting point of a segment is above 1.5, and the end point is below, in which case the segment will be red (or blue in teh opposite case of a starting point below 1.5 and end point above it).

Hope this clarifies, and that I understood correctly your concern.

JP

 

JP,
That’s clear, but I think I misstated the problem. The problem is with the fractal dimension indicator, not the FRASMA. If you consider the current bar as it paints, you don’t really know whether the point will be above or below the threshold until the bar has completed. Only then do you correctly know the color of the segment. This is not really a problem if you try to make an EA of the indicator, because you can simply wait for the bar to complete before making a decision, or using the result.

However most EA’s don’t wait for the bar, but make decisions with each tick, and the color of the segment may change after the decision was made, so if you try to look at the history of the trades the EA makes, the color segments will paint before they are known to the EA, and it will be hard to understand what happened. No real problem, just nitpicking really. I truly like the FRASMA, it is better than the FRAMA. It is interesting that if one adjusts the parameters, the FRASMA will overlay Ehlers Adaptive Laguerre Filter very closely.

MadCow

09.04.2009 07:35 MadCow

MadCow wrote:

funyoo wrote:
Thanks for these indicators. I have tried to code an expert advisor based on the fractal dimension.

jppoton

I read your blog, and it convinced me that your use of Fractal dimension is better than Ehlers. Good work, and thanks for the excellent explanation.

On funyoo’s site he states that there is a problem with the indicator. The EA he has made works pretty well on the strategy tester, but that’s not much proof. Someone there suggested that ‘fractal dimension.mq4’ may be repainting. The indicator seems to change color one bar before it crosses the threshold, but not in all cases, as if it occasionally gets a peek into the future. Please comment on this.

Hi MadCow,

Thanks for your appreciation.

I just replied to Funyoo in his thread on Trading System FOREX. As I said there, I don’t think FDI repaints anything, simply the “curve” of FDI is just linking points of a discrete set, and the color is determined by the end point of the segment drawn, it may then be the case that the starting point of a segment is above 1.5, and the end point is below, in which case the segment will be red (or blue in teh opposite case of a starting point below 1.5 and end point above it).

Hope this clarifies, and that I understood correctly your concern.

JP

 

08.04.2009 22:47 jppoton

funyoo wrote:
Thanks for these indicators. I have tried to code an expert advisor based on the fractal dimension.

jppoton

I read your blog, and it convinced me that your use of Fractal dimension is better than Ehlers. Good work, and thanks for the excellent explanation.

On funyoo’s site he states that there is a problem with the indicator. The EA he has made works pretty well on the strategy tester, but that’s not much proof. Someone there suggested that ‘fractal dimension.mq4’ may be repainting. The indicator seems to change color one bar before it crosses the threshold, but not in all cases, as if it occasionally gets a peek into the future. Please comment on this.

08.04.2009 03:52 MadCow

serdarali wrote:
Hi,

İs it possible to use your code as examplary and fractalise JMA or T3 moving average ?

Hi,

The logic behind the FRASMA can indeed be used to fractalise any MA, however, the problem to consider is to identify whether the logic behind a particular MA is “compatible” with what the fractal analysis is saying. As I explained on my blog, I chose to fractalise an SMA and not, as Ehlers did, an EMA, because the EMA is simply putting more weight on recent price variations, therefore accelerating the MA when a fractal analysis indicates that it should be slowed down (for high fractal dimensions).

I don’t know the logic behind the JMA, I therefore cannot say whether it’s interesting to fractalise it or not. The T3 is basically using the same logic as an EMA (being a combination of several EMAs), and here again, I believe this may be in conflict with what fractal analysis is telling us, so I would not recommend to fractalise a T3.

Cheers

Share this article

Leave a comment