我发现了这个错误,我不确定原因(语法类似于 C)
该功能应该用卖单关闭买单,但我得到.
error 3:
invalid trade parameters
是否有一些我设置错误的参数?
我之前已经成功打电话,OrderClose()
所以我猜OrderSend()
是正确的。
void closeBuySell(int buyTicket){
double buyPrice = OrderClosePrice();
//Print("total ",OrdersTotal()," ",buyTickets," ",sellTickets);
for(int Counter=0; Counter<OrdersTotal(); Counter++){ //search for a matching sell
if(OrderSelect(Counter,SELECT_BY_POS) && OrderType()==OP_SELL && OrderOpenPrice()>buyPrice){
Print("CLOSING BUYSELL ",buyTicket," ",OrderTicket()," ",OrderOpenPrice(),">",buyAsk);
if(OrderCloseBy(buyTicket,OrderTicket(),Red)){ buyTickets--; sellTickets--; }
else Print(ErrorDescription(GetLastError()));
break;
}
}
}
int buyTickets=0;
int sellTickets=0;
bool up = false;
void OnTick(){
double FastMA = iMA(NULL,0,FastMAPeriod,0,0,0,0);
double SlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,0);
if(FastMA>SlowMA && !up){ up=true;
if(buyTickets<15 && OrderSend(Symbol(),OP_BUY,.1,Ask,40,0,0))
buyTickets++;
}
if(FastMA<SlowMA && up){ up=false;
if(sellTickets<15 && OrderSend(Symbol(),OP_SELL,.1,Bid,40,0,0))
sellTickets++;
}
for(int Counter=0; Counter<OrdersTotal(); Counter++) //ordercloseby buy with sell
if(OrderSelect(Counter,SELECT_BY_POS) && OrderType()==OP_BUY)
closeBuySell(OrderTicket());
}
输出:
...after
13:42 practice1 EURUSD,M5: invalid trade parameters
13:42 practice1 EURUSD,M5: OrderCloseBy error 3
13:42 practice1 EURUSD,M5: CLOSING BUYSELL 17 8 1.086>1.086
13:40 practice1 EURUSD,M5: invalid trade parameters
13:40 practice1 EURUSD,M5: OrderCloseBy error 3
13:40 practice1 EURUSD,M5: CLOSING BUYSELL 23 1 1.0858>1.0855
13:40 practice1 EURUSD,M5: invalid trade parameters
13:40 practice1 EURUSD,M5: OrderCloseBy error 3
13:40 practice1 EURUSD,M5: CLOSING BUYSELL 22 1 1.0858>1.0855
00:05 practice1 EURUSD,M5: sell orders:12
00:05 practice1 EURUSD,M5: open #12 sell limit 0.10 EURUSD at 1.08598 ok
00:05 practice1 EURUSD,M5: sell orders:11
00:05 practice1 EURUSD,M5: open #11 sell limit 0.10 EURUSD at 1.08599 ok
00:05 practice1 EURUSD,M5: sell orders:10
00:05 practice1 EURUSD,M5: open #10 sell limit 0.10 EURUSD at 1.08600 ok
...before