小編 不好意思
想要請問,我以此篇文章當範例 移動停利語法
取得成本價後 設定50點停利 停損(台指)
等待下次進場機會
但是回測後發現出場點跟我設定不一樣
例如下圖 並沒有幫我做停利停損

無論使用連結內的寫法 或是使用filledavgprice 都是一樣的結果
請問
1.是哪邊寫錯了呢??
2.有沒辦法以20MA進場,跌破5MA做移動停利呢??
3. 另外有沒有辦法進場以後是K棒收盤才進場,但是出場是打到停利停損價就出場呢? (分鐘K)
語法如下 ######### 主要從 37行開始 #########
感謝小編
input: Length(9, "計算期數"), RSVt(3, "RSVt權數"), Kt(3, "Kt權數");
variable: _rsv(0), _k(0), _d(0), DI(0), nDI(0), ADX_value(0), DealPrice(0), _MarketPosition(0),period(10);
///// MA /////
value1 = EMA(close,144);
value2 = EMA(close,5);
///// KD /////
SetTotalBar(maxlist(Length,6) * 3 + 8);
Stochastic(Length, RSVt, Kt, _rsv, _k, _d);
///// MACD /////
input: FastLength(12), SlowLength(26), MACDLength(9);
SetInputName(1, "DIF短期期數");
SetInputName(2, "DIF長期期數");
SetInputName(3, "MACD天數");
variable: difValue(0), macdValue(0), oscValue(0), Forecast_DealPrice(0), profit(0), loss(0);
MACD(weightedclose(), FastLength, SlowLength, MACDLength, difValue, macdValue, oscValue);
///// SAR /////
input:AFIncrement(0.02,"加速因子");
input:AFMax(0.2,"加速因子最大值");
variable: sarValue(0);
sarValue = SAR(AFIncrement, AFIncrement, AFMax);
/////////////////////////////////////////////////////////////////////
var: long_condition(false); { Long Condition }
var: stop_long_profit(false);
var: stop_long_loss(false);
var: short_condition(false); { Short Condition }
var: stop_short_profit(false);
var: stop_short_loss(false);
long_condition = close > value1 and oscValue > 0 and close > sarValue;
short_condition = close < value1 and oscValue < 0 and close < sarValue;
///// 取得成本價 /////
once long_condition or short_condition begin
Forecast_DealPrice = close;
// profit = Forecast_DealPrice + 50;
// loss = Forecast_DealPrice - 50;
end;
///// 停損停利條件 /////
stop_long_profit = close > Forecast_DealPrice + 50;
stop_short_profit = close < Forecast_DealPrice - 50 ;
stop_long_loss = close < Forecast_DealPrice - 50;
stop_short_loss = close > Forecast_DealPrice + 50;
///// Long /////
if long_condition then begin
setposition(1, market);
print(Forecast_DealPrice, date, time, position, close, value1, DI, nDI);
end;
if position = 1 and filled = 1 then begin
if stop_long_profit or stop_long_loss then setposition(0, market);
print(Forecast_DealPrice, date, time, position, close, value1, DI, nDI);
end;
///// Short /////
if short_condition then begin
setposition(-1, market);
print(Forecast_DealPrice, date, time, position, close, value1, DI, nDI);
end;
if position = -1 and filled = -1 then begin
if stop_short_profit or stop_short_loss then setposition(0, market);
print(Forecast_DealPrice, date, time, position, close, value1, DI, nDI);
end;


3 評論