FRASMA: Fractally Modified Simple Moving Average
Name: 


Author:  
Rating:  10  
Downloaded:  9248  
Download: 


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).
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. 

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( "[ 20ERRORÂ Â " + 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 JeanPhilippe, 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 intraday 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/(2fdi); 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 eperiod, 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 timescale gets a bit slower. Hope this helps, if you are any more doubts or questions, you are welcome to ask me again. Cheers JeanPhilippe
Excellent, thanks JeanPhilippe. 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 JeanPhilippe 21.07.2009 02:30 jppoton
jppoton wrote:
tsheppard wrote:
Hi JeanPhilippe, 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 intraday 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/(2fdi); 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 eperiod, 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 timescale gets a bit slower. Hope this helps, if you are any more doubts or questions, you are welcome to ask me again. Cheers JeanPhilippe
Excellent, thanks JeanPhilippe. 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 JeanPhilippe, 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 intraday 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/(2fdi); 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 eperiod, 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 timescale gets a bit slower. Hope this helps, if you are any more doubts or questions, you are welcome to ask me again. Cheers JeanPhilippe
20.07.2009 20:51 jppoton
Hi JeanPhilippe, 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 intraday 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, 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 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
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
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 