$ w( k) x6 ?9 J6 O/ J6 a( v0 b2 T3 \. B" c 如果我们需要平掉所有的仓位,那么需要是什么? |( U) H0 D3 R0 p) B; }; h1 m) [+ i
第一,找到当前的所有持仓。 2 ~( C8 S# B' s* d2 s' B2 g8 y. q+ E% T第二,然后平掉。 5 N- J7 D: D0 w7 b4 J- z" Q* S1 j3 z% J那么第一步:就是找到当前的所有持仓,好在mql语言提供了,Orderselect(),具体的看mql的官方说明文档,简单的说就是这样的: ( l* s& K, }! @+ c% M4 B0 M
bool OrderSelect( " F9 a D" `3 D9 S6 Uint index, // index or order ticket , M2 j- ]3 `' c6 T1 W3 \. F9 nint select, // flag - o) l- P! K+ Q; i
int pool=MODE_TRADES // mode 6 C& x) `3 R+ q! X
); : _2 H- n" V$ V! V
这个就是记忆,没啥窍门,就这么定义的,记住。 # C$ B2 Y' K! c6 |. D2 M4 C
但是要理解里面的参数定义: $ K( F, {! s0 b+ i* y : l4 Q g5 \4 vselect " u4 |: \0 g7 x[in] Selecting flags. It can be any of the following values: //选择标识,可以为下面的2者之一。 X* e0 a3 W; z$ w$ i
SELECT_BY_POS - index in the order pool, O9 f8 P+ c9 }3 q! Z& A3 l* Z1 nSELECT_BY_TICKET - index is order ticket. % ?( M* _4 ^6 C9 Epool=MODE_TRADES //这个pool参数默认是MODE_TRADES,下面会解释 # j9 ?* X U* @1 I' ^[in] Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any of the following values: 8 e5 J1 l; c5 W6 V* W5 cMODE_TRADES (default)- order selected from trading pool(opened and pending orders),//当前持有的浮动仓位。 K6 O" Y1 Q( b, {5 r/ A
MODE_HISTORY - order selected from history pool (closed and canceled order).//已经平仓和取消的仓位。 8 a+ K6 T0 q. \
简单的说:MODE_TRADES 为 当前的持有的仓位,MODE_HISTORY,为历史的交易记录。 7 H6 F# N) r9 _" w# V W; X( ?" g% J* X# l