想在1分K警示腳本把前1日近15分鐘外盤量比率大於89%的次數超過20次,當天策略雷達出現警示訊號.
但次數不對,請問要怎麼修改.
//警示腳本 1分K 前一日近15分鐘外盤量比率超過89%的次數超過20次
var: _or15B(0), _ir15B(0);
_or15B = outsizeBefore(15,15);//前一日近15分鐘外盤比率
variable: intrabarpersist Xtime15B(0);
variable: intrabarpersist Volumestamp15B(0);
Volumestamp15B =_or15B;
if Date > date[1] then Xtime15B =0;
if _or15B >= 89 then Xtime15B+=1;
if Xtime15B > 20 then ret = 1 ;
print(date, time, "Xtime15B=", NumToStr(Xtime15B, 0));
//函數 OutSizeBefore為前1日近N分鐘外盤量比率
Input:length1(numericsimple), length2(numericsimple);
array: _ArrayOutSize[](0), _ArrayInSize[](0);
Array_SetMaxIndex(_ArrayOutSize, length1);
Array_SetMaxIndex(_ArrayInSize, length2);
var:_Count(0);
//初始化
if getfieldDate("Date") <> getfieldDate("Date")[1] then begin
_Count = 0;
Array_SetValRange(_ArrayOutSize, 1, length1, 0);
Array_SetValRange(_ArrayInSize, 1, length2, 0);
value3 = 0;
value98 = 0;
value99 = 0;
end else begin
_Count += 1;
end;
value98 = mod(_count,length1) + 1;
value99 = mod(_count,length2) + 1;
_ArrayOutSize[value98] = GetField("外盤量","1")[270] ;
_ArrayInSize[value99] = GetField("內盤量", "1")[270] ;
value1 = Array_Sum(_ArrayOutSize, 1, length1);
value2 = Array_Sum(_ArrayInSize, 1, length2);
if (value1+value2) <> 0 then
OutSizeBefore = (value1/(value1+value2))*100
else OutSizeBefore = 0 ;
台積電做回測
20240918.000000 0.000000 Xtime15B= 1
20240919.000000 0.000000 Xtime15B= 1
20240920.000000 0.000000 Xtime15B= 1
20240923.000000 0.000000 Xtime15B= 1
20240924.000000 0.000000 Xtime15B= 1
20240925.000000 0.000000 Xtime15B= 1
20240926.000000 0.000000 Xtime15B= 1
20240927.000000 0.000000 Xtime15B= 1
以台積電今日 20240928為例, 前一日20240927近15分鐘外盤量比率超過89%的次數是15次(見以下指標腳本), 不是1次 請問要如何修改 ?
指標腳本
計算每天 1分k 近15分鐘外盤量比率>89%出現幾次的計數程式
var: _or15(0);
_or15 = outsize(15,15);//近15分鐘外盤量比率
variable: intrabarpersist Xtime15(0);
variable: intrabarpersist Volumestamp15(0);
Volumestamp15 =_or15;
if Date> date[1] then Xtime15 =0;
if _or15 >= 89 then Xtime15+=1;
plot1(Xtime15,"近15分鐘外盤量比率大於89%次數");
函數 outsize 當日近N分鐘外盤量比率函數
Input:length1(numericsimple), length2(numericsimple);
array: _ArrayOutSize[](0), _ArrayInSize[](0);
Array_SetMaxIndex(_ArrayOutSize, length1);
Array_SetMaxIndex(_ArrayInSize, length2);
var:_Count(0);
//初始化
if getfieldDate("Date") <> getfieldDate("Date")[1] then begin
_Count = 0;
Array_SetValRange(_ArrayOutSize, 1, length1, 0);
Array_SetValRange(_ArrayInSize, 1, length2, 0);
value3 = 0;
value98 = 0;
value99 = 0;
end else begin
_Count += 1;
end;
value98 = mod(_count,length1) + 1;
value99 = mod(_count,length2) + 1;
_ArrayOutSize[value98] = GetField("外盤量","1") ;
_ArrayInSize[value99] = GetField("內盤量", "1") ;
value1 = Array_Sum(_ArrayOutSize, 1, length1);
value2 = Array_Sum(_ArrayInSize, 1, length2);
if (value1+value2) <> 0 then
OutSize = (value1/(value1+value2))*100
else OutSize = 0 ;
8 評論