一个 mt4 外汇自动平仓EA代码

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

//+------------------------------------------------------------------+

//| CloseAllOrders.mq4 |

//| Copyright ?2008, PRMQuotes Software Corp. |

//| Jedimedic77@ |

//+------------------------------------------------------------------+

#property copyright "Copyright ?2008, PRMQuotes Software Corp."

#property link ""

//+------------------------------------------------------------------+

//| EX4 imports |

//+------------------------------------------------------------------+

#include

//+------------------------------------------------------------------+

//| global variables to program: |

//+------------------------------------------------------------------+

double Price[2];

int giSlippage;

bool CloseOpenOrders = true;

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

void start() {

int iOrders=OrdersTotal()-1, i;

if(CloseOpenOrders) {

for(i=iOrders; i>=0; i--) {

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()<=OP_SELL) && GetMarketInfo() && !OrderClose(OrderTicket(),OrderLots(),Price[1-OrderType()],giSlippage)) Print(OrderError());

}

}

}

//+------------------------------------------------------------------+

//| Function..: OrderError |

//+------------------------------------------------------------------+

string OrderError() {

int iError=GetLastError();

return(StringConcatenate("Order:",OrderTicket()," GetLastError()=",iError," ",ErrorDescription(iError)));

}

//+------------------------------------------------------------------+

//| Function..: GetMarketInfo |

//+------------------------------------------------------------------+

bool GetMarketInfo() {

RefreshRates();

Price[0]=MarketInfo(OrderSymbol(),MODE_ASK);

Price[1]=MarketInfo(OrderSymbol(),MODE_BID); double dPoint=MarketInfo(OrderSymbol(),MODE_POINT); if(dPoint==0) return(false);

giSlippage=(Price[0]-Price[1])/dPoint;

return(Price[0]>0.0 && Price[1]>0.0);

}

//+------------------------------------------------------------------+

相关文档
最新文档