這樣寫好像有問題 如何修正?
condition1= ema(closew(0),12) and ema(closew(0),26) ;//周金叉之後
condition2= average(close,5) >ema(close,12) ;//待若有多頭排列時
IF condition1 AND condition2 then setposition(1);//再買進
condition1 發生後 等待condition2 發生時 ,等待時間不可發生死叉,這段不確定時間的等待 語法?
這樣寫好像有問題 如何修正?
condition1= ema(closew(0),12) and ema(closew(0),26) ;//周金叉之後
condition2= average(close,5) >ema(close,12) ;//待若有多頭排列時
IF condition1 AND condition2 then setposition(1);//再買進
condition1 發生後 等待condition2 發生時 ,等待時間不可發生死叉,這段不確定時間的等待 語法?
Hello, xqyi.
您可以利用BarsLast(...)來計算最近一次黃金交叉是否筆死亡交叉小,
SetTotalBar(95 * 5);
value1 = BarsLast(xf_ema("W", close, 12) Cross over xf_ema("W", close, 26)); //最近一次週均線黃金交叉
value2 = BarsLast(xf_ema("W", close, 12) Cross under xf_ema("W", close, 26));//最近一次週均線死亡交叉
condition1 = value2 > value1;
condition2 = average(close,5) Cross over ema(close,12);
IF condition1 AND condition2 then ret = 1;
但是 因為 SetTotalBar太長,所以選股會跑不完,
小幫手建議您改成兩個腳本來實現,
//跑週頻率 SetTotalBar(95);// (26 + 1) * 3.5 value1 = BarsLast(ema(close, 12) Cross over ema(close, 26)); //最近一次週均線黃金交叉 value2 = BarsLast(ema(close, 12) Cross under ema(close, 26));//最近一次週均線死亡交叉 Ret = value2 > value1; outputField1(value1, "12EMA Cross over 26EMA"); outputField2(value2, "12EMA Cross under 26EMA");
//跑日頻率 SetTotalBar(46);// (12 + 1) * 3.5 ret = average(close,5) Cross over ema(close,12);
這樣即可得到您想要的結果,
網站上有教學區,裡面有XS語法的基礎和應用可以閱覽。
謝謝。
1 評論