也就是說可以直接在程式中直接呼叫日盛API all
然後直接做策略運算並送單
不用靠字檔輸出。
可以想成直接把下單機寫在策略裡。
下單路徑少了很多。
實際丟單狀況如下圖。(接CBOT小道瓊報價)
快!!! 真的快。
Chart中訊號出現到日盛APITradeMgr送單紀錄幾乎同時出現。
當然丟單到成交就不曉得了><
以下是範例程式。
vars:order(0);
DefineDLLFunc:"C:\JihSun\HTS2\Dll\HTSAPITradeClient.dll",void,"HTSOrder",LPSTR;
if C > O and marketposition = 0 and order = 0 then begin
buy next bar at market;
order = order + 1;
end;
if O > C and marketposition = 0 and order = 0 then begin
sell next bar at market;
order = order - 1;
end;
if marketposition > 0 and O > C and order = 1 then begin
exitlong next bar at market;
order = order - 1;
end;
if 0 > marketposition and C > O and order = -1 then begin
exitshort next bar at market;
order = order + 1;
end;
if order=1 and order[1]=0 then begin
HTSOrder("Market=F,Account=帳號,ContractName=交易商品,"+
"ContractDate=月份,OpenCloseAuto=A,BuySell=B,Lots=1,"+
"OrderType=M,Price=0,FokIocRod=F,DayTrade=N");
end;
if order=-1 and order[1]=0 then begin
HTSOrder("Market=F,Account=帳號,ContractName=交易商品,"+
"ContractDate=月份,OpenCloseAuto=A,BuySell=S,Lots=1,"+
"OrderType=M,Price=0,FokIocRod=F,DayTrade=N");
end;
if order=0 and order[1]=1 then begin
HTSOrder("Market=F,Account=帳號,ContractName=交易商品,"+
"ContractDate=月份,OpenCloseAuto=A,BuySell=S,Lots=1,"+
"OrderType=M,Price=0,FokIocRod=F,DayTrade=N");
end;
if order=0 and order[1]=-1 then begin
HTSOrder("Market=F,Account=帳號,ContractName=交易商品,"+
"ContractDate=月份,OpenCloseAuto=A,BuySell=B,Lots=1,"+
"OrderType=M,Price=0,FokIocRod=F,DayTrade=N");
end;
if order=1 and order[1]=-1 then begin
HTSOrder("Market=F,Account=帳號,ContractName=交易商品,"+
"ContractDate=月份,OpenCloseAuto=A,BuySell=B,Lots=2,"+
"OrderType=M,Price=0,FokIocRod=F,DayTrade=N");
end;
if order=-1 and order[1]=1 then begin
HTSOrder("Market=F,Account=帳號,ContractName=交易商品,"+
"ContractDate=月份,OpenCloseAuto=A,BuySell=S,Lots=2,"+
"OrderType=M,Price=0,FokIocRod=F,DayTrade=N");
end;
宣告一個Order變數模擬倉位變化,紀錄下單條件達成時倉位變化。
以上寫法也許太過於粗糙,似乎也有很多無謂的動作。
所以實際上還是要仔細思考程式條件達成時
會讓帳戶倉未有什麼樣的變化。
畢竟在程式內就可以直接丟單了,所以要想成程式就是下單機。
一個不小心丟錯單就糟了。萬事嚴謹點好