感謝教授指導
1.之前所述的實際與回測交易商品和時間點都有出入,問題仍在為何?
2.增加委託後若要排隊成交的則調低平倉價格
3..若時間內一直未達委託價則調低平倉價格
程式碼如下何處有不妥之處?
//%B指標
input: Lengthb(20, "布林通道天數");
input: BandRange(2, "上下寬度");
input: bM(80,"擴展"),bs(60,"緊縮");
variable: up(0), down(0), mid(0);
up = bollingerband(Close, Lengthb, BandRange);
down = bollingerband(Close, Lengthb, -1 * BandRange);
if up - down = 0 then value31 = 0 else value31 = (close - down) * 100 / (up - down);
//ATR
input: Length(6,"ATR天數"),ATRs(2.25,"ATR除數");
value1 = Average(TrueRange, Length);
value2=open-low;
value3=high-open;
value4=high-low;
value5=value2/(value4+0.0001);
value6=1-value5;
value7=round(open-open*0.00015-(value1*value5)/ATRs,2);
condition1=GetField("收盤價","Tick") <= value7;//close
value8=round(open+open*0.00015+(value1*value6)/ATRs,2);
condition2=GetField("收盤價","Tick")>= value8;//close
input:TM(090200,"進場時間"),P1(10,"操作價位L"),P2(500,"超作價位H"),
X1(1,">買進有漲%停利"),X2(25,"<買進有跌%停損"),X3(1,"<賣出有跌%停利"),X4(25,">賣出有漲%停損");
condition7=GetSymbolInfo("處置股")=false or q_NetValuePerShare >=6;
condition90 = close > p1 and close <P2 and close < close[1]*1.05 and condition7; //進場點
var: intrabarpersist SentTime(0);
var: intrabarpersist hasOrdered(false);
if position=0 and filled=0 and condition90 and currentTime > TM and currentTime <=110000
then begin
if condition1 and (value31 > value31[1] or value7 > value7[1] )
and value7*1.0045 < getField("High","D")
then
setposition(minList(position+1,1),GetField("收盤價","Tick"),label:="買1");//有庫存時,不進場加買,維持一張
end;
if position<>0 and filled<>0 then
begin
value95=100 * (Close - FilledAvgPrice) / FilledAvgPrice; //停利停損%
if filled=1 then setposition(0,filledAvgPrice*(1+(x1/100)),label:="買進續漲%停利");
SentTime=Getfield("時間","Tick");
end;
input:CT1(5,"排隊時間"),CT2(60,"改價時間");
if position=0 and filled=1
and GetField("收盤價","Tick") >=filledAvgPrice*(1+(x1/100))
and Getfield("時間","Tick")>=timeadd(SentTime,"S",CT1)
then setposition(0,filledAvgPrice*(1+(0.435/100)),label:="排隊則調利");
if position=0 and filled=1
and Getfield("時間","Tick")>=timeadd(SentTime,"M",CT2)
then setposition(0,filledAvgPrice*(1+(0.435/100)),label:="未達委託價調利");
14 評論