親愛的小編,
想了解XS的環境是否有bug。因為如昨天所反應的~~做多腳本沒有任何問題。執行回測,結果也都如預期。但同樣的腳本直接copy,轉成做空腳本,卻發現在進場策略中的 if then begin當中的第三式 lowestprice = FilledAvgPrice 就沒有正常執行。所以後續的stopprice = lowestprice +riskpoint.....答案只有riskpoint。所以都會立即出場。(所以print也無法出現結果? 因為根本沒執行該式)。
//期指MACD做空當沖交易
// 宣告參數
input: FastLength(12,"DIF短天數"), SlowLength(26,"DIF長天數"), MACDLength(9,"MACD天數");
input: riskpoint(35,"停利停損點數");
var: intrabarpersist lowestprice(0);
var: intrabarpersist limit_control(0);
// if date<>date[1] then lowestprice =0; //自訂義變數歸零
if barfreq<>"Min"or barinterval<>5 then return;
var: price(0),dif_s(0),macd_s(0),osc_s(0);
settotalbar((maxlist(FastLength,SlowLength,MACDLength)+1)*3.5);
price = WeightedClose();
//macd25計算式
dif_s = XAverage(price, FastLength) - XAverage(price, SlowLength);
macd_s = XAverage(dif_s, MACDLength) ;
osc_s = dif_s - macd_s ;
value1 = ema(close,13); // ma13以下才能空
condition1 = close< value1 and osc_s cross below 0;
condition2 = limit_control <> currentbar;
// 空方進場策略:MACD由正轉負。
if position = 0 and condition1 and condition2 then begin
setposition(-1);
limit_control = currentbar;
lowestprice = FilledAvgPrice;
end;
if close < lowestprice then lowestprice = close; //採最低價位做為停利(損)起算點
stopprice = lowestprice + riskpoint;
//監控
print("lowestprice=",numtostr(lowestprice,0),"riskpoint=",numtostr(riskpoint,0),"FilledAvgPrice=",numtostr(FilledAvgPrice,0),"stopprice=",numtostr(stopprice,0));
//出場策略:同一K線時,以點數控制。不同K線時,三條件擇一出場
condition3 = osc_s cross above 0 or close > stopprice;
if limit_control<>currentbar then if
condition3 then setposition(0) //不同根bar時的停損模式
else if
close>stopprice then setposition(0) ; //同一根bar的停損模式
8 評論