MetaTrader 5 / 脚本

Pending orders DOWN - MetaTrader 5脚本

2123
(38)

"Pending orders DOWN" 脚本程序设置一个低于当前价格的挂单网格。


输入参数

  • Gap for pending orders DOWN from the current price (in pips) - 当前价格与第一个挂单之间的距离.
  • Step between orders DOWN (in pips) - 挂单之间的距离.
  • Type of pending orders DOWN - 挂单的类型 (可以是限价买入或者是止损卖出).
  • DOWN quantity - 设置的挂单数量.
  • Lots - 每个挂单的交易量.
  • Stop Loss (in pips) - 止损值.
  • Take Profit (in pips) - 获利值.

该脚本通过使用异步交易操作来确保最快地发送交易请求来设置挂单:

   m_trade.SetAsyncMode(true);

这里是一个发送5个挂单请求的例子:

2017.08.28 09:00:30.227 Scripts script Pending orders DOWN (AUDCAD,Daily) loaded successfully 2017.08.28 09:00:35.272 Trades  '6121033': sell stop 0.01 AUDCAD at 0.98893 sl: 0.99143 tp: 0.98693 2017.08.28 09:00:35.272 Trades  '6121033': sell stop 0.01 AUDCAD at 0.98743 sl: 0.98993 tp: 0.98543 2017.08.28 09:00:35.273 Trades  '6121033': sell stop 0.01 AUDCAD at 0.98593 sl: 0.98843 tp: 0.98393 2017.08.28 09:00:35.273 Trades  '6121033': sell stop 0.01 AUDCAD at 0.98443 sl: 0.98693 tp: 0.98243 2017.08.28 09:00:35.273 Trades  '6121033': sell stop 0.01 AUDCAD at 0.98293 sl: 0.98543 tp: 0.98093 2017.08.28 09:00:35.274 Scripts script Pending orders DOWN (AUDCAD,Daily) removed 

五个挂单是在1毫秒之内发送的!

这里是完整报告,从脚本开始到删除 (第一个订单发送的时间是 2017.08.28 09:00:35.272):

2017.08.28 09:00:30.227 Scripts script Pending orders DOWN (AUDCAD,Daily) loaded successfully 2017.08.28 09:00:35.272 Trades  '6121033': sell stop 0.01 AUDCAD at 0.98893 sl: 0.99143 tp: 0.98693 2017.08.28 09:00:35.272 Trades  '6121033': sell stop 0.01 AUDCAD at 0.98743 sl: 0.98993 tp: 0.98543 2017.08.28 09:00:35.273 Trades  '6121033': sell stop 0.01 AUDCAD at 0.98593 sl: 0.98843 tp: 0.98393 2017.08.28 09:00:35.273 Trades  '6121033': sell stop 0.01 AUDCAD at 0.98443 sl: 0.98693 tp: 0.98243 2017.08.28 09:00:35.273 Trades  '6121033': sell stop 0.01 AUDCAD at 0.98293 sl: 0.98543 tp: 0.98093 2017.08.28 09:00:35.274 Scripts script Pending orders DOWN (AUDCAD,Daily) removed 2017.08.28 09:00:35.340 Trades  '6121033': accepted sell stop 0.01 AUDCAD at 0.98893 sl: 0.99143 tp: 0.98693 2017.08.28 09:00:35.341 Trades  '6121033': order #164992356 sell stop 0.01 / 0.01 AUDCAD at market done in 68.657 ms 2017.08.28 09:00:35.341 Trades  '6121033': accepted sell stop 0.01 AUDCAD at 0.98743 sl: 0.98993 tp: 0.98543 2017.08.28 09:00:35.342 Trades  '6121033': order #164992357 sell stop 0.01 / 0.01 AUDCAD at market done in 69.645 ms 2017.08.28 09:00:35.342 Trades  '6121033': accepted sell stop 0.01 AUDCAD at 0.98593 sl: 0.98843 tp: 0.98393 2017.08.28 09:00:35.343 Trades  '6121033': order #164992358 sell stop 0.01 / 0.01 AUDCAD at market done in 70.006 ms 2017.08.28 09:00:35.343 Trades  '6121033': accepted sell stop 0.01 AUDCAD at 0.98443 sl: 0.98693 tp: 0.98243 2017.08.28 09:00:35.343 Trades  '6121033': order #164992359 sell stop 0.01 / 0.01 AUDCAD at market done in 70.346 ms 2017.08.28 09:00:35.343 Trades  '6121033': accepted sell stop 0.01 AUDCAD at 0.98293 sl: 0.98543 tp: 0.98093 2017.08.28 09:00:35.343 Trades  '6121033': order #164992360 sell stop 0.01 / 0.01 AUDCAD at market done in 70.312 ms 

当最后一个挂单被确认的时间是 2017.08.28 09:00:35.343. 所有的操作总共才花费了 71 毫秒!

在脚本运行的开始,要检查指定交易量正确性:

//+------------------------------------------------------------------+ //| 脚本程序起始函数                         | //+------------------------------------------------------------------+ void OnStart()   { //---    if(InpLots<=0.0)      {       Print("\"Lots\" 不能小于或者等于0");       return;      } //---    if(!m_symbol.Name(Symbol())) // 设置交易品种名称       return;    if(!RefreshRates())       return;    string err_text="";    if(!CheckVolumeValue(InpLots,err_text))      {       Print(err_text);       return;      } //--- 

由MetaQuotes Ltd译自俄语
原代码: https://www.mql5.com/ru/code/19025