
當我們想要在一串數列中做排序後的取最大值,或是取第二大值的,有內建的函數 Highest 或是 Maxlist 又或是 Maxlist2 可以使用,但是如果要取第4小、第6大呢?
函數(自建名稱 _minlistN)程式碼如下:
input:Price(Numeric),Length(Numeric),Nth(Numeric);
var:step(0);
array:AA[500](0);
for step=0 to Length-1 begin
AA[step]=Price[step];
end;
Array_sort(AA, 0, Length, true);
_minlistN=AA[Nth];
這個函數可以用來取相同類的連續數值的第N小。舉例來說,用來取最近 10根內的K棒最低價,取第3小的。 _minlistN( Low, 10, 3)。
其實 MultiCharts 有一串 Nth 開頭的內建函數可用。比如 NthLowest 就是做上述事情的。只不過,偶而我會做一點對自己腦袋訓練的事情^^