|
//+------------------------------------------------------------------+ //| 单边.mq4 | //| Copyright 2017, metaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2017, metaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int start() // 特别函数 start { int Dist_SL =7; // 设定止损位 7 个点 int Dist_TP =4; // 设定止盈位 4 个点 double Prots=0.1; // 交易使用 1% 的保证金 string Symb=Symbol(); // 交易对象名称 double Win_Price=WindowPriceonDropped(); // 脚本被拖拉进的窗口,价格点位 alert("The price is set by the mouse as Price = ",Win_Price);// 点击鼠标设定的价格 //------------------------------------------------------------------------------- 2 -- while(true) // 建仓过程循环 { int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);// 最小止损/止盈点位 double Min_Lot=MarketInfo(Symb,MODE_MINLOT);// 最小交易手数 double Free =AccountFreeMargin(); // 保证金 double One_Lot=MarketInfo(Symb,MODE_MARGINREQUIRED);//每手所需保证金 double Lot=MathFloor(Free*Prots-One_Lot*Min_Lot)*Min_Lot;// 总手数 //------------------------------------------------------------------------- 3 -- double Price=Win_Price; // 点击鼠标设定的价格 if (NormalizeDouble(Price,Digits)< // 若小于下限 NormalizeDouble(Ask+Min_Dist*Point,Digits)) { // 仅可 BuyStop 挂单! Price=Ask+Min_Dist*Point; // 没有平仓 alert("Changed the requested price: Price = ",Price); } //------------------------------------------------------------------------- 4 -- double TP=Price + Dist_TP*Point; // 止盈报价 if (Dist_TP < Min_Dist) // 若低于下限 { TP=Price + Min_Dist*Point; // 以下限为止盈点位 alert(" Increased the distance of TP = ",Min_Dist," pt"); } //------------------------------------------------------------------------- 6 -- alert("The request was sent to the server. Waiting for reply.."); int ticket=OrderSend(Symb, OP_BUYSTOP, Lot, Price, 0, 0, TP); //------------------------------------------------------------------------- 7 -- if (ticket>0) // 服务器接受挂单!:) { alert ("Placed order BuyStop ",ticket); break; // 退出挂单 } //------------------------------------------------------------------------- 8 -- int Error=GetLastError(); // 挂单被拒绝 :( switch(Error) // 可克服的错误 { case 129:alert("Invalid price. Retrying.."); RefreshRates(); // 更新数据 continue; // 继续 case 135:alert("The price has changed. Retrying.."); RefreshRates(); // 更新数据 continue; // 继续 case 146:alert("Trading subsystem is busy. Retrying.."); Sleep(500); // 简单处理方案 RefreshRates(); // 更新数据 continue; // 继续 } switch(Error) // 致命错误 { case 2 : alert("Common error."); break; // 退出本 'switch' case 5 : alert("Outdated version of the client terminal."); break; // 退出本 'switch' case 64: alert("The account is blocked."); break; // 退出本 'switch' case 133:alert("Trading fobidden"); break; // 退出本 'switch' default: alert("Occurred error ",Error);// 其他错误 } break; // 退出挂单 } //------------------------------------------------------------------------------- 9 -- alert ("The script has completed its operations -----------------------------"); return 0; // 退出 start() } //------------------------------------------------------------------------------- 10 -- |
我只想要一个就几行代码的单边EA,我试新手,编不好
回复:0 浏览:304
- 楼主admin 圈主
- 2019-05-05 13:13