© 本贴为 My05613828 原创/首发,严禁抄袭!
- //------------------------------------------------------
- void 平N时间前单(long magic,long 时间)
- {
- for(int i=PositionsTotal()-1; i>=0; i--)
- {
- if(PositionGetTicket(i)>0)
- {
- magic=魔术幻数(magic);
- if(PositionGetInteger(POSITION_MAGIC)==magic)
- {
- if(PositionGetInteger(POSITION_TIME)<TimeCurrent()-时间)
- {
- if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
- {
- MqlTradeRequest request= {};
- MqlTradeResult result= {};
- request.action=TRADE_ACTION_DEAL;
- request.magic=PositionGetInteger(POSITION_MAGIC);
- request.position=PositionGetInteger(POSITION_TICKET);
- request.volume=PositionGetDouble(POSITION_VOLUME);
- request.symbol=PositionGetString(POSITION_SYMBOL);
- request.type_filling=返回交易量指令(request.symbol);
- request.price=SymbolInfoDouble(request.symbol,SYMBOL_BID);
- request.deviation=deviation(slippage,request.symbol);;
- request.type=ORDER_TYPE_SELL;
- request.comment=PositionGetString(POSITION_COMMENT);
- bool X=OrderSendAsync(request,result);
- if(X==false)
- {
- Print("订单发送失败代码:"+IntegerToString(GetLastError()));
- Print("交易返回代码:"+IntegerToString(result.retcode));
- }
- }
- if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
- {
- MqlTradeRequest request= {};
- MqlTradeResult result= {};
- request.action=TRADE_ACTION_DEAL;
- request.magic=PositionGetInteger(POSITION_MAGIC);
- request.position=PositionGetInteger(POSITION_TICKET);
- request.volume=PositionGetDouble(POSITION_VOLUME);
- request.symbol=PositionGetString(POSITION_SYMBOL);
- request.type_filling=返回交易量指令(request.symbol);
- request.price=SymbolInfoDouble(request.symbol,SYMBOL_ASK);
- request.deviation=deviation(slippage,request.symbol);;
- request.type=ORDER_TYPE_BUY;
- request.comment=PositionGetString(POSITION_COMMENT);
- bool X=OrderSendAsync(request,result);
- if(X==false)
- {
- Print("订单发送失败代码:"+IntegerToString(GetLastError()));
- Print("交易返回代码:"+IntegerToString(result.retcode));
- }
- }
- }
- }
- }
- }
- };
- //+------------------------------------------------------------------+
-
-
- ENUM_ORDER_TYPE_FILLING 返回交易量指令(string symbol)
- {
- // 获取现价单开仓的交易命令类型 ( 如果一个交易币种同时允许SYMBOL_FILLING_FOK和SYMBOL_FILLING_IOC成交指令,则交易命令类型为ORDER_FILLING_FOK )
-
- ENUM_ORDER_TYPE_FILLING 指令类型=ORDER_FILLING_FOK;
- if(SymbolInfoInteger(symbol,SYMBOL_FILLING_MODE)==SYMBOL_FILLING_IOC)
- 指令类型=ORDER_FILLING_IOC;
- if(SymbolInfoInteger(symbol,SYMBOL_FILLING_MODE)==SYMBOL_FILLING_FOK)
- 指令类型=ORDER_FILLING_FOK;
- return(指令类型);
- }
- //+------------------------------------------------------------------+
复制代码
|