I am sorry if I may sound rude or cocky but I most point some details.
I believe that role idea of this group is to built knowledge and good AFL coding practices. So...
1) About this:
I think a simple MA will make more sense for correlation than a AMA. There is no reason why one want sto weight most recent bars over older bars for correlation purposes.
AMA() is not WMA() or EMA().
Complete different functions.
I wouldn't call AMA() an average, it is a smoothing function.
Anyway, AMA() would not be the solution for the case because there was not a problem in the first place.
Better explained below in number (2).
2) The original function should handle "period" as a number or an array. I see no difference from the solution code and the original code posted.
In fact, it is not up to the correlation() function (that most have been renamed as pointed) but only where you use the "period" input.
They are all used in the MA() function and MA(array, period) can handle period as a number or an array.
You should be facing a different problem than the one described.
|
3) A heads up, if you want to speed up your code stop calling the same functions over and over.
nom_S= MA( BarIndex() * C, HL_BarSince_S ) - MA( BarIndex(), HL_BarSince_S ) * MA( C, HL_BarSince_S );denom_S = sqrt( MA( BarIndex() ^ 2, HL_BarSince_S ) - MA( BarIndex(), HL_BarSince_S ) ^ 2 ) * sqrt( MA( C ^ 2, HL_BarSince_S ) - MA( C, HL_BarSince_S ) ^ 2 );
Every time you call barindex() you are running this function again.
That is ok because barindex() is a fast one but MA() may not be. ATR() and Percentile() are not, for example.
So:
bi = barindex(); // the return of barindex() is stored on "bi". You can use it over and over.
Calling MA() multiple times is the same, you would be recalculating the same thing over and over.
bi = barindex();
ma_bi_hl = MA( bi , HL_BarSince_S );
ma_close_HL = MA( C, HL_BarSince_S );
nom_S= MA( bi * C, HL_BarSince_S ) - ma_bi_hl * ma_close_HL;
denom_S = sqrt( MA( bi ^ 2, HL_BarSince_S ) - ma_bi_hl ^ 2 ) * sqrt( MA( C ^ 2, HL_BarSince_S ) - ma_close_HL ^ 2 );
If you compare the performance of both codes you most see some gain.
(On the AFL Editor / Tools / Code Check and Profile).
Any speed improvement can result and a big time difference when optimizing your parameters.
After all, the code will run over and over, a zillion times.
Same thing on analysis when scanning the market.
Thanks and I hope I could be helpful.
2016-05-23 3:24 GMT-03:00 meanomalist@yahoo.com [amibroker] <amibroker@yahoogroups.com>:
Note: HL_BarSince_S is Period array and not as a Static Number.
nom_S= MA( BarIndex() * C, HL_BarSince_S ) - MA( BarIndex(), HL_BarSince_S ) * MA( C, HL_BarSince_S );
denom_S = sqrt( MA( BarIndex() ^ 2, HL_BarSince_S ) - MA( BarIndex(), HL_BarSince_S ) ^ 2 ) * sqrt( MA( C ^ 2, HL_BarSince_S ) - MA( C, HL_BarSince_S ) ^ 2 );
Correl_S = (nom_S / denom_S );
__._,_.___
Posted by: =?UTF-8?Q?Jo=C3=A3o_Fl=C3=A1vio_Machado_Derzi?= <joaoderzi@gmail.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (7) |
Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
.
__,_._,___
EmoticonEmoticon