Stock Portfolio Organizer
The ultimate porfolio management solution.
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Spearman Indicator for Amibroker (AFL)
From S& C Mag February 2011
It may be possible to use the Spearman coefficient to determine trend intensity AND turning points. I wrote a program using AmiBroker to calculate this indicator (see below).
Screenshots
Similar Indicators / Formulas
Indicator / Formula
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | // Spearman indicator: // // r1 - time series order // r11 - price (close) // r21 - internal sort table // r22 - order of prices (close) // This code has been written only to support findings // described in this article. It can be modified for // improved efficency. // /* Number of periods */ n = Param ( "Periods: " , 10, 5, 200, 1 ); /* Start loop and computations based on Close */ for ( k = n; k <= BarCount -1; k++ ) /* Populate internal tables for n elements */ { r1=0; r11 = 0; r2=0; r21=0; r22=0; /////////////////////////////////////////////////////////////// for (i=n; i>=1; i--) { r1[i] = i; r22[i] = i; r11[i] = Close [k-n+i]; r21[i] = Close [k-n+i]; } // for ... /////////////////////////////////////////////////////////////// /* Sort internal table r21 descending */ changed = 1; while (changed > 0) { changed = 0; for (i=1; i<=(n-1); i++) { if (r21[i+1]<r21[i]) { temp = r21[i]; r21[i] = r21[i+1]; r21[i+1] = temp; changed = 1; } } // for .... } // while .... /////////////////////////////////////////////////////////////// for (i =1; i<=n; i++) { found = 0; while (found < 1) { for (j =1; j<=n; j++) { if (r21[j] == r11[i]) { r22[i] = j; found = 1; } } // for ... } // while ... } // for ... /////////////////////////////////////////////////////////////// /* Compute Spearman's rank correlation coeficient for n bars */ absum=0; for (i = 1; i<=n; i++) { ab = r1[i] - r22[i]; ab2 = ab*ab; absum = absum+ab2; } // for ... coefcorr[k] = (1-(6*absum)/(n*(n*n-1))); /* coefcorr[k]: Spearman's rank correlation coefficient for current bar k */ sc[k]=100*coefcorr[k]; // multiplied by 100 /////////////////////////////////////////////////////////////// } // for k..... // /* Plot Spearman's rank correlation coefficient multiplied by 100 */ Plot (sc, "Spearman indicator" , colorBlue , styleLine ); /* Plot 3-bar simple moving average */ Plot ( MA (sc,3), "SMA(3)" , colorRed , styleLine ); Title = Date ()+ " " + Interval (2) + " " + Name () + " Spearman(" +n+ ") = " + sc; /* end */ |
1 comments
Leave Comment
Please login here to leave a comment.
Back
NICE AFL ,CAN ANY ONE ADD BUY & SELL
WHEN BLUE LINE CROSSES RED .
THANKS IN ADVANCE.