我只想要一个就几行代码的单边EA,我试新手,编不好
zs65221
|
2316 人阅读
|
9 人评论
|
2017-03-07
//+------------------------------------------------------------------+
//| 单边.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 --
|
|
|
|
|