input:LengthMA(10,"MA區間"),LengthEMA(10,"EMA區間"),rsiLengthInput(14,"RSI區間");
//Define
var:xMA(0),xEMA(0),dirMA(0),xRsi(0),dirRsi(0),up(0),down(0);
var:profitLong(0),profitShort(0),diffLong(0),diffShort(0),lossLong(0),lossShort(0);
Print(file("D:\Print\"),"date=",date,"time=",time,"Close:",close,"止盈:",profitLong,"止損:",lossLong);
xMA = average(close, LengthMA); //快線
xEMA = ema(close, LengthEMA); //慢線
if xEMA < xMA then dirMA = 1 else if xEMA > xMA then dirMA = -1 else dirMA = 0;
xRsi = rsI(close,rsiLengthInput);
if xRsi > 50 and xRsi < 70 then dirRsi = 1
else if xRsi > 30 and xRsi < 50 then dirRsi = -1
else dirRsi = 0;
condition1 = close > open; //收紅
condition2 = close < open; //收黑
condition5 = low>xMA and low>xEMA; //做多K棒都收在上方
condition6 = high<xMA and high<xEMA; //做空K棒都收在下方
condition8 = (dirMA = 1) and condition1 and condition5 and (dirRsi = 1); //多單條件
condition9 = (dirMA = -1) and condition2 and condition6 and (dirRsi = -1);
//Print(file("D:\Print\"),"date=",date,"time=",time,"Con1",condition1,"Con2",condition2,"Con5",condition5,"Con6",condition6,"dirMA",dirMA,"dirRsi",dirRsi);
//Trading
if position = 0 and filled = 0 then begin
if condition8 then
begin
lossLong = xMA;
diffLong = close - lossLong;
profitLong = close + (diffLong * 1.5);
Print(file("D:\Print\"),"date=",date,"time=",time,"多單進場價:",close,"止盈:",profitLong,"止損:",lossLong,"成交量",volume);
//setposition(1);
buy(1);
end;
if condition9 then
begin
lossShort = xMA;
diffShort = lossShort-close;
profitShort = close - (diffShort * 1.5);
Print(file("D:\Print\"),"date=",date,"time=",time,"空單進場價:",close,"止盈:",profitShort,"止損:",lossShort);
setposition(-1);
end;
end;
Print(file("D:\Print\"),"date=",date,"time=",time,"close:",close,"止盈:",profitLong,"止損:",lossLong);
Print(file("D:\Print\"),"date=",date,"time=",time,"position",position,"filled",filled);
if position = 1 and filled = 1 then begin
if close <= lossLong then begin
setposition(0, market);
Print(file("D:\Print\"),"date=",date,"time=",time,"多單出場價:",close,"止損:",lossLong);
end;
if close >= profitLong then begin
setposition(0, market);
Print(file("D:\Print\"),"date=",date,"time=",time,"多單出場價:",close,"止盈:",profitLong);
end;
end;
if position = -1 and filled = -1 then begin
if close >= lossShort then begin
setposition(0, market);
Print(file("D:\Print\"),"date=",date,"time=",time,"空單出場價:",close,"止損:",lossShort);
end;
if close <= profitShort then begin
setposition(0, market);
Print(file("D:\Print\"),"date=",date,"time=",time,"空單出場價:",close,"止盈:",profitShort);
end;
end;
Print(file("D:\Print\"),"date=",date,"time=",time,"close:",close,"止盈:",profitLong,"止損:",lossLong);
以上是我的code,在判斷停損停利時有時候會出現抓到前一次進場的止損止盈,請問可能是哪裡的問題呢?
 
 
             
        
         
         
         
     
     分類
    分類
 
            
2 評論