請問一個策略的寫法:
#1. 當日9:30的收盤價下跌且低於前日收盤價的2%以上.
#2. 在10:15-11:15的1小時內,若價格突破當日均線,則進場做多. 設定2%停利,2.5%停損.
#3. 以2603, 7/28為測試, 前一日收盤價126.5, 當日9:30的收盤價120.5, 應該符合條件#1.
#4. 當日10:45, 收盤價為123.5, 當時均價122.53, 應該符合條件#2.
#5. 實際以1分鐘頻率回測7/28當天2603是否可以如策略進場,但是結果顯示無任何成交.
可否協助指正. 謝謝.
//價格 vs EMA23
input: StaTime(101500,"交易開始時間");
input: EndTime(111500,"交易結束時間");
input: rate(2.0,"9:30的跌幅");
input: profit_percent(2.0, "停利(%)");
input: loss_percent(2.5, "停損(%)");
input: OrderQty(1,"委託量");
var: profit_point(0),loss_point(0),stop_profit(0),stop_loss(0),priceRate(0);
var: _entry(false), _exit(false); //進出場
var: _stocktype(false); //須符合可當沖做多的商品
var: _cross(false); //是否符合穿越條件
var: _tradeRange(false); //是否符合交易時間
var: _updnRange(false); //是否符合漲跌幅範圍
//符合當沖進場時間
_tradeRange = GetField("Time") >= StaTime and GetField("Time") <= EndTime;
//確認符合可當沖
_stocktype = GetSymbolInfo("買賣現沖") or GetSymbolInfo("先買現沖");
//符合開低
If currentBar=30 then value1 = Close[0];
Condition1 = value1 < CloseD(1) * (1-rate/100);
//符合穿越當日均價
_cross = Close cross Above GetField("均價");
//過濾符合所有進場條件
_entry = _tradeRange and _stocktype and _cross and Condition1;
//交易
If Position= 0 and _entry then
begin
SetPosition(OrderQty, market); { 以市價買進 } {價格檔位=AddSpread(Close,-4))}
end;
//已有成交部位
if Position = OrderQty and Filled = OrderQty then begin
profit_point = FilledAvgPrice * 0.01*profit_percent;
loss_point = FilledAvgPrice * 0.01*loss_percent;
stop_profit = FilledAvgPrice + profit_point;
stop_loss = FilledAvgPrice - loss_point;
{ 依照成本價格設定停損/停利 }
if profit_percent > 0 and Close >= stop_profit then begin { 停利 }
SetPosition(0,Market);
end else if loss_percent > 0 and Close <= stop_loss then begin {停損 }
SetPosition(0,market);
end;
end;
2 評論