小頻率跨大頻率開盤遇到資料缺失

  •   88 
  • 最後發表   bisbenzene  2023 六月 09
bisbenzene 發文於   2023/06/08

 

小幫手, 你好:

下列警示內容是用來盤中當沖所使用 執行頻率為1分鐘, 當開盤啟動後開始讀取1分鐘第1根後卻發生每一檔有缺資料or資料有問題的錯誤訊息, 能請小幫手幫忙指正哪裡語法有錯誤的地方嗎? 謝謝

//
input: Length1(50), UpperBand1(2), LowerBand1(2), Length2(120), UpperBand2(2), LowerBand2(2);

SetInputName(1, "短天數");
SetInputName(2, "短上");
SetInputName(3, "短下");
SetInputName(4, "長天數");
SetInputName(5, "長上");
SetInputName(6, "長下");

value4=average(close,5);
value5=ema(close,40);
value6=average(close,10);
value7=xfmin_EMA("3",Close,3);

variables: pdi(0),ndi(0),adx_value(0),sma5(0),ema40(0),sma10(0),ema1(0),ema33(0);
variables: up_s(0), down_s(0), mid_s(0), up_l(0), down_l(0), mid_l(0);
variables: up_s3(0), down_s3(0), mid_s3(0), up_l3(0), down_l3(0), mid_l3(0);
variables: outsideratio(0),insideratio(0);

settotalbar(250);
ema1=GetField("均價");  
sma5=value4;
ema40=value5;  
sma10=value6;
ema33=value7;

value10=getField("內盤量","D");
value11=getField("外盤量","D");
value12=value10+value11;
if value12<>0 then outsideratio=value11/value12*100;
if value12<>0 then insideratio=value10/value12*100;

DirectionMovement(16, pdi, ndi, adx_value);

up_s= bollingerband(Close, Length1, UpperBand1);
down_s= bollingerband(Close, Length1, -1 * LowerBand1);
mid_s= (up_s + down_s)/2;
up_l= bollingerband(Close, Length2, UpperBand2);
down_l= bollingerband(Close, Length2, -1 * LowerBand2);
mid_l= (up_l + down_l)/2;

up_s3= bollingerband(getField("Close","3"), Length1, UpperBand1);
down_s3= bollingerband(getField("Close","3"), Length1, -1 * LowerBand1);
mid_s3= (up_s3 + down_s3)/2;
up_l3= bollingerband(getField("Close","3"), Length2, UpperBand2);
down_l3= bollingerband(getField("Close","3"), Length2, -1 * LowerBand2);
mid_l3= (up_l3 + down_l3)/2;

condition1=pdi>ndi and up_l>up_l[1] and sma5>up_s and sma5>up_l and ema33>up_s3 and ema33>up_l3 and outsideratio>56;
condition2=adx_value[2]>adx_value[1];
condition3=adx_value[3]>adx_value[2] and adx_value[2]<adx_value[1];
condition4=adx_value[4]>adx_value[3] and adx_value[3]<adx_value[2];
condition5=adx_value[5]>adx_value[4] and adx_value[4]<adx_value[3];
condition6=adx_value[6]>adx_value[5] and adx_value[5]<adx_value[4];
condition7=adx_value[7]>adx_value[6] and adx_value[6]<adx_value[5];
condition8=adx_value[8]>adx_value[7] and adx_value[7]<adx_value[6];
condition9=adx_value[9]>adx_value[8] and adx_value[8]<adx_value[7];

if condition1 and condition2 and adx_value[1]<adx_value then ret=1
else if condition1 and condition3 and adx_value[1]<adx_value then ret=1
else if condition1 and condition4 and adx_value[1]<adx_value then ret=1
else if condition1 and condition5 and adx_value[1]<adx_value then ret=1
else if condition1 and condition6 and adx_value[1]<adx_value then ret=1
else if condition1 and condition7 and adx_value[1]<adx_value then ret=1
else if condition1 and condition8 and adx_value[1]<adx_value then ret=1
else if condition1 and condition9 and adx_value[1]<adx_value then ret=1;

print(file("c:\XQPrint\[Date]\[Date]_[StrategyName]_[Symbol]_[Freq].log"),"時間=",formatTime("HH:mm:ss",getField("time","1")),"標的=",symbol,"EMA3=",ema33,"3MBB50=",up_s3,"3Mbb120=",up_l3,"外盤比=",outsideratio);

 

XQ小幫手 發文於   2023/06/09

Hello bisbenzene,

 

xfMin_EMA 沒有提供3分鐘頻率。

另外計算錯誤是因為資料筆數不足。

length2 設為 120 筆,但settotalbar只有250筆。

建議您可以加上 setbackbar 指定頻率及引用筆數,像是 setbackbar(120, "3")。

發表回覆
Close