您好,
我想問一個問題,我有一個現股當沖的策略,自動警示後下單這沒問題,但是若是觸發停損(賣出)時會觸發兩次,見附圖。
然後多觸發的一次竟會變成「進場單(買進)」,可否麻煩幫我看一下到底哪裡出問題了呢?
PS:如果看不到我的附圖,可以點此下圖片網址 :
我的程式碼如下:
if barfreq<>"Min" or barinterval<> 1 then raiseruntimeerror("腳本只適用於1分鐘線");
variable:H30(0),L30(0),barcount(0),_cost(0),_stock(0),_gainprice(0),_lossprice(0);
input:gain(1,"停利%");
input:loss(1.1,"停損%");
if date <> date[1] then barcount=1 else barcount+=1;
if barcount = 30 then
begin
H30 = highest(high,30);//前30分鐘的最高價
L30 = lowest(low,30);//前30分鐘的最低價
end;
if close > H30 and close < H30*1.005
and Time > 093000 and Time < 131000
and _stock=0
then begin
//做多進場
_cost = close ;//30.1
_gainprice = _cost*(1+gain/100);
_lossprice = _cost*(1-loss/100);
_stock =1;
ret=1;
Print(Time,"做多進場:","成本價:",_cost,"庫存",_stock,"close",close,"_gainprice",_gainprice,"_lossprice",_lossprice);
end;
//多單停利
if _stock = 1
and close > _gainprice
then begin
_stock =0;
ret = 1;
Print(Time,"多單停利:","成本價:",_cost,"庫存:",_stock,"close",close,"_gainprice",_gainprice);
end;
//多單停損
if _stock =1
and close < _lossprice
then begin
_stock = 0;
ret = 1;
Print(Time,"多單停損","成本價:",_cost,"庫存:",_stock,"close",close,"_lossprice",_lossprice);
end;




17 評論