朋友,你找到mt5追踪止损的代码了吗?
yuliang0898:
MT5的代码,不是MT4。
想要追踪止损的整个框架代码和库,就是能够直接套用就行的,mql5网站有个相关的内容,老外写的,我语言基础差,看的有点稀里糊涂的,想要个现成带注解的。
十分感谢!!!
mt5 追踪止损代码,仅供参考!
void TrailingStop(int 移动点数,ENUM_POSITION_TYPE type,int magic) { MqlTradeRequest request= {0}; MqlTradeResult result= {0}; int t=PositionsTotal(); for(int i=t-1; i>=0; i--) { if(PositionGetTicket(i)>0) { if(PositionGetString(POSITION_SYMBOL)==_Symbol) { double bid=SymbolInfoDouble(_Symbol,SYMBOL_BID); double ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK); double pot=SymbolInfoDouble(_Symbol,SYMBOL_POINT); double op=PositionGetDouble(POSITION_PRICE_OPEN); double sl=PositionGetDouble(POSITION_SL); double tp=PositionGetDouble(POSITION_TP); if(type==POSITION_TYPE_BUY) { if((bid-op)>=pot*移动点数 && (sl<(bid-pot*移动点数) || (sl==0))) { if(PositionGetInteger(POSITION_MAGIC)==magic) { ZeroMemory(request); ZeroMemory(result); request.action=TRADE_ACTION_SLTP; request.position=PositionGetTicket(i); request.symbol=_Symbol; request.sl=bid-pot*移动点数; request.tp=tp; if(!OrderSend(request,result)) PrintFormat("OrderSend error %d",GetLastError()); } } } if(type==POSITION_TYPE_SELL) { if((op-ask)>=pot*移动点数 && ((sl>(ask+pot*移动点数)) || (sl==0))) { if(PositionGetInteger(POSITION_MAGIC)==magic) { ZeroMemory(request); ZeroMemory(result); request.action=TRADE_ACTION_SLTP; request.position=PositionGetTicket(i); request.symbol=_Symbol; request.sl=ask+pot*移动点数; request.tp=tp; if(!OrderSend(request,result)) PrintFormat("OrderSend error %d",GetLastError()); } } } } } } }
MT5的代码,不是MT4。
想要追踪止损的整个框架代码和库,就是能够直接套用就行的,mql5网站有个相关的内容,老外写的,我语言基础差,看的有点稀里糊涂的,想要个现成带注解的。
十分感谢!!!