このエラーが見つかりましたが、理由がわかりません (構文は 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