PureBytes Links
Trading Reference Links
|
I want to get the median close. Couldn't find AFL function
so I wrote this script. It doesn't give any errors but
the result is not the median of the last 21 days. I use 21
because the 11th sorted value becomes the median. Can someone
please spot my error.
tia
nand
/*Median CLose in last 21 days*/
medianclose=0;
EnableScript("vbscript");
<%
Close = AFL( "close" )
Function fnSort(aSort)
Dim intTempStore
Dim i, j
For i= Ubound(aSort)-21 To UBound(aSort)
For j = i To UBound(aSort)
'Sort Ascending
if aSort(i) > aSort(j) Then
intTempStore = aSort(i)
aSort(i) = aSort(j)
aSort(j) = intTempStore
End if 'i > j
Next 'j
Next 'i
fnSort = aSort
End function 'fnSort
'-------------------------
Dim aSorted
'call the function
aSorted = fnSort(Close)
median=aSorted(11) ' 11th element of the sorted 21
AFL.Var("medianclose") = median
%>
|