請教小幫手
我的策略是用在小台全日15分K 在盤中的買進賣出訊號都有執行
但今天剛好在最後13:30出訊號 應該在下一根K棒開盤價15:00時會下指令買進
不過程式認定是13:45當時剛好收盤 於是出現下列訊息
想請問 有什麼辦法可以讓13:45的買進訊號在15:00執行

// MACD 黃金交叉 (dif向上穿越macd)
//
input: FastLength(12), SlowLength(65), MACDLength(15);
variable: difValue(0), macdValue(0), oscValue(0);
SetTotalBar(200);
SetInputName(1, "DIF短期期數");
SetInputName(2, "DIF長期期數");
SetInputName(3, "MACD期數");
MACD(weightedclose(), FastLength, SlowLength, MACDLength, difValue, macdValue, oscValue);
input: profit_point(0, "停利(點)");
input: loss_point(30, "停損(點)");
var:
long_condition(false), { 做多 }
short_condition(false); { 做空 }
long_condition = difValue cross above macdValue and close > ema(close,20);
short_condition = difValue cross below macdValue and close < ema(close,20);
if Position = 0 and long_condition then begin
SetPosition(1); { 買進1張 }
end;
if Position = 1 and Filled = 1 then begin
{ 依照成本價格設定停損/停利 }
var: intrabarpersist stoploss_point(0);
{ 計算停損價格 }
if stoploss_point = 0 then begin
stoploss_point = FilledAvgPrice - loss_point;
end;
{ 如果價格上漲的話, 則往上挪動停損價格. 停損價格只會越來越高 }
if Close > FilledAvgPrice then begin
if Close - loss_point > stoploss_point then begin
stoploss_point = Close - loss_point;
end;
end;
if profit_point > 0 and Close >= FilledAvgPrice + profit_point then begin
{ 停利 }
SetPosition(0);
stoploss_point = 0;
end else if Close <= stoploss_point then begin
{ 停損 }
SetPosition(0);
stoploss_point = 0;
end;
end;
if Position = 0 and short_condition then begin
SetPosition(-1); { 做空賣出1張 }
end;
if Position = -1 and Filled = -1 then begin
{ 依照成本價格設定停損/停利 }
var: intrabarpersist stoploss_point1(0);
{ 計算停損價格 }
if stoploss_point1 = 0 then begin
stoploss_point1 = FilledAvgPrice + loss_point;
end;
{ 如果價格下跌的話, 則往下挪動停損價格. 停損價格只會越來越低 }
if Close < FilledAvgPrice then begin
if Close + loss_point < stoploss_point1 then begin
stoploss_point1 = Close + loss_point;
end;
end;
if profit_point > 0 and Close <= FilledAvgPrice - profit_point then begin
{ 停利 }
SetPosition(0);
stoploss_point1 = 0;
end else if Close >= stoploss_point1 then begin
{ 停損 }
SetPosition(0);
stoploss_point1 = 0;
end;
end;
3 評論