有兩個問題
問題一:進場K棒都慢了一根
問題二:如何撰寫盤中賺10點就市價出場,不用等到5分K收盤價才來決定
我想設計的是前一根5分K收盤價大於布林上通道
且下一根5分K收盤價低於布林上通道
就市價進場放空
例如8月24號應該是在9點05分這一根5分K收盤進場放空
但回測出來卻是在9點10分這一根開盤價放空
這樣本來在9點05分收盤進場放空
就能在9點10分這一根5分K停利出場
卻變成要等到9點45才能夠停利出場
另外語法都是用5分K收盤價來判斷停利停損出場
如何撰寫盤中任何一秒鐘有賺到10點就市價出場
停損的方式也是一樣盤中任何一秒鐘超過停損點數
馬上市價出場
{
空單停損(點)
}
Input: Length(20), UpperBand(2);
input: profit_point(10, "停利(點)");
input: loss_point(40, "停損(點)");
var: short_condition(false); { 進場做空 }
{
範例:
均線跌破時以市價賣出1張做空
以成交價為基礎, 設定固定的停損/停利價格, 觸及時出場
}
short_condition = Close[1] > bollingerband(Close[1], Length, UpperBand) and
Close<bollingerband(Close, Length, UpperBand);
if Position = 0 and short_condition then begin
SetPosition(-1, MARKET);{ 以市價賣出 }
end;
if Position = -1 and Filled = -1 then begin
{ 依照成本價格設定停損/停利: 請注意當作空時, 判斷是否獲利的方向要改變 }
if profit_point > 0 and Close <= FilledAvgPrice - profit_point then begin
{ 停利 }
SetPosition(0);
end else if loss_point > 0 and Close >= FilledAvgPrice + loss_point then begin
{ 停損 }
SetPosition(0);
end;
end;
3 評論