论坛全局菜单下方 - TICKMILL 285X70论坛全局菜单下方 - ThinkMarkets285X70论坛全局菜单下方 - 荔枝返现285X70论坛全局菜单下方 -  icmarkets285X70
查看:10111回复:8
wfy05
注册时间2005-07-23
MT4批量开启和删除订单的脚本程序
楼主发表于:2006-02-16 06:15只看该作者倒序浏览
1楼 电梯直达
电梯直达
两个脚本,第一个BatchOpen.mq4用来在一定区间内自动按照一定间隔挂单, 第二个BatchClose.mq4用来自动删除符合要求或者所有的单子. 安装方法同其他标准脚本,以脚本方式安装即可. 两个脚本运行前都可以设置相应参数, BatchOpen的参数如下: ActionBuy -> true或者false, 表示挂单为买入或者卖出 RangeStart -> 挂单范围的起点 RangeEnd -> 挂单范围的终点 TotalLots -> 挂单的总手数 OrderCount -> 挂单分割成的总数量, 必须大于等于2 Slippage -> 允许的滑点数,可以为0 StopLoss -> 所挂的单的止损位, 可以为0表示无止损 TakeProfit -> 所挂的单的获利位, 可以为0表示无获利 Comments -> 注释,默认为"BatchOpen Auto Generated", 可以用后面的BatchClose来通过 特定的注释匹配删除特定的单. Expiration -> 挂单过期时间,未测试,默认不过期 Delay -> 每两个单之间的等待时间,默认不等待 比如以如下的参数设置 ActionBuy = true RangeStart = 1.1850 RangeEnd = 1.1870 TotalLots = 1.0 OrderCount = 5 Slippage = 0 StopLoss = 1.1830 TakeProfit = 1.1920 为例, 运行后将自动挂上如下5单: 1.1850, 0.2 lots, S/L 1.1830, T/P 1.1920 1.1855, 0.2 lots, S/L 1.1830, T/P 1.1920 1.1860, 0.2 lots, S/L 1.1830, T/P 1.1920 1.1865, 0.2 lots, S/L 1.1830, T/P 1.1920 1.1870, 0.2 lots, S/L 1.1830, T/P 1.1920 如果当手数之类的不能整除的话多余的会放到最后一单,同时 每单大小最小必须为0.1 Lots 另外注意挂单时候的价位以及止损, 获利价位都必须和 当前价位之类的有最小7点的差别, 否则该单会失败. BatchClose对应为批处理关闭符合要求的单子, 设置参数为: Comments -> 用来设置匹配的单子注释, 注释不匹配的不予删除, 不设置则表示匹配任意注释 CommentsMatchStart -> 用来设置注释匹配时候是全匹配还是只匹配开头部分即可,默认为只匹配开头 PendingOnly -> 表示是否只匹配挂单,默认为否,匹配所有单据 Slippage -> 允许的滑点数,可以为0 Magic -> 表示用来匹配的单据MagicNumber, 默认0表示匹配所有单据. 默认参数运行表示删除所有的单子(包括挂单和已成交单),一般如果想只删除BatchOpen自动生成的单子 可以把Comments项改成"BatchOpen"即可(前提是 BatchOpen运行的时候注释为默认的), 如果只想删除挂单 则修改PendingOnly 为true. 不过这两个脚本实际意义不大,MT4上应该没有几个人有真实帐户的. 有兴趣的自己试试吧. //+------------------------------------------------------------------+ //| BatchOpen.mq4 | //| [email protected] | //| www.talkforex.com | //+------------------------------------------------------------------+ #property copyright "[email protected]" #property link "www.talkforex.com" #property show_inputs #include extern bool ActionBuy = true; extern double RangeStart = 1.1850; extern double RangeEnd = 1.1870; extern double TotalLots = 1.0; extern int OrderCount = 5; extern int Slippage = 0; extern double StopLoss = 0.0; extern double TakeProfit = 0.0; extern string Comments = "BatchOpen Auto Generated"; extern datetime Expiration = 0; extern int Delay = 0; #define BATCH_OPEN_MAGIC 06021610 //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int ActionType = 0; int start() { //---- //inputs checking if (OrderCount < 2) { MessageBox("Not enough OrderCount, must be greater than 1 at least"); return (-1); } double LotsPerOrder, LotsLeft; int i, n; n = TotalLots * 10/OrderCount; LotsPerOrder = n; LotsPerOrder /= 10; LotsLeft = TotalLots - LotsPerOrder * OrderCount; if (LotsPerOrder < 0.1) { MessageBox("Not enough TotalLots or too many OrderCount, each order must be 0.1 lots at least"); return (-1); } if (LotsPerOrder + LotsLeft >= 10000) { MessageBox("Too many TotalLots, each order must be less than 10000 lots"); return (-1); } n = NormalizeDouble((MathAbs(RangeStart - RangeEnd) * MathPow(10, Digits)), 0)/(OrderCount-1); if (n < 1) { MessageBox("Too many OrderCount, each order must have 1 pips diff at least"); } double volume, price; string symbol; int cmd, magic, ticket, cnt, failed; symbol = Symbol(); magic = BATCH_OPEN_MAGIC; volume = LotsPerOrder; cnt = 0; failed = 0; for (i = 0; i < OrderCount; i++) { price = RangeStart + i * n * Point; if (i == OrderCount-1) { volume += LotsLeft; //price = RangeEnd; } RefreshRates(); if (ActionBuy) { if (price < Ask) { cmd = OP_BUYLIMIT; } else { cmd = OP_BUYSTOP; } } else { if (price < Bid) { cmd = OP_SELLSTOP; } else { cmd = OP_SELLLIMIT; } } ticket = OrderSend(symbol, cmd, volume, price, Slippage, StopLoss, TakeProfit, Comments, magic, Expiration, CLR_NONE); if (ticket < 0) { Print("Failed to place order at price " + price + ", Error: " + ErrorDescription(GetLastError())); failed++; } else { cnt++; } Sleep(Delay); } //---- Print(cnt + " orders placed, " + OrderCount + " requested, " + failed + " failed"); return(0); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| BatchClose.mq4 | //| [email protected] | //| www.talkforex.com | //+------------------------------------------------------------------+ #property copyright "[email protected]" #property link "www.talkforex.com" #property show_inputs #include extern string Comments = ""; extern bool CommentsMatchStart = true; extern bool PendingOnly = false; extern int Slippage = 0; extern int Magic = 0; bool OrderDeleteOrClose() { int cmd; double price; int ticket; ticket = OrderTicket(); cmd=OrderType(); if(cmd == OP_BUY || cmd == OP_SELL) { if (cmd == OP_BUY) { price = Bid; } else { price = Ask; } if (!OrderClose(ticket, OrderLots(), price, Slippage, CLR_NONE)) { Print("Failed to close order " + ticket + " Error: " + ErrorDescription(GetLastError()) ); return (false); } else { return (true); } } else { //pending orders if (!OrderDelete(ticket)) { Print("Failed to delete order " + ticket + " Error: " + ErrorDescription(GetLastError()) ); return (false); } else { return (true); } } } int start() { bool result; int cmd,total,ticket, cnt, failed; string c; //---- total=OrdersTotal(); //---- cnt = 0; failed = 0; for(int i=total-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if (PendingOnly) { cmd=OrderType(); if(cmd == OP_BUY || cmd == OP_SELL) { continue; } } if (Magic != 0) { if (OrderMagicNumber() != Magic) { continue; } } if (StringGetChar(Comments, 0) != 0) { if (CommentsMatchStart) { c = StringSubstr(OrderComment(), 0, StringLen(Comments)); } else { c = OrderComment(); } if (Comments != c) { continue; } } OrderPrint(); if (!OrderDeleteOrClose()) { failed++; } else { cnt++; } } else { Print("Failed to select order " + i + " Error: " + ErrorDescription(GetLastError()) ); failed++; } } Print(cnt + " orders deleted from " + total + " total orders, " + failed + " failed"); //---- return(0); } //+------------------------------------------------------------------+
TK29帖子1楼右侧xm竖版广告90-240
个性签名

韬客社区www.talkfx.co

广告
TK30+TK31帖子一樓廣告
TK30+TK31帖子一樓廣告
老正
注册时间2003-09-21
365热心助人奖
发表于:2006-02-16 16:13只看该作者
2楼
呵呵 老大 也许可以用做鱼网交易的实验
wfy05
注册时间2005-07-23
楼主发表于:2006-02-16 16:43只看该作者
3楼
原帖由 老正 于 2006-2-17 00:13 发表 呵呵 老大 也许可以用做鱼网交易的实验
鱼网的话T/P应该换成相对数了, 稍微改了一下加入TakeProfitRelative 参数用来设置网格的获利点数. (TakeProfitRelative不为0时候TakeProfit将被忽略) 不过网格的话想要自动还是做成EA的比较好,当然要考虑的东西也多不少, 完全自动网格还需结合震荡行情的判断才行. Metaquotes上以前有人已经 做过一个Grid Maker了,没具体用过,有兴趣的自己去看看. //+------------------------------------------------------------------+ //| BatchOpen.mq4 | //| [email protected] | //| www.talkforex.com | //+------------------------------------------------------------------+ #property copyright "[email protected]" #property link "www.talkforex.com" #property show_inputs #include extern bool ActionBuy = true; extern double RangeStart = 1.1850; extern double RangeEnd = 1.1870; extern double TotalLots = 1.0; extern int OrderCount = 5; extern int Slippage = 0; extern double StopLoss = 0.0; extern double TakeProfit = 0.0; extern int TakeProfitRelative = 0; extern string Comments = "BatchOpen Auto Generated"; extern datetime Expiration = 0; extern int Delay = 0; #define BATCH_OPEN_MAGIC 06021610 //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int ActionType = 0; int start() { //---- //inputs checking if (OrderCount < 2) { MessageBox("Not enough OrderCount, must be greater than 1 at least"); return (-1); } double LotsPerOrder, LotsLeft; int i, n; n = TotalLots * 10/OrderCount; LotsPerOrder = n; LotsPerOrder /= 10; LotsLeft = TotalLots - LotsPerOrder * OrderCount; if (LotsPerOrder < 0.1) { MessageBox("Not enough TotalLots or too many OrderCount, each order must be 0.1 lots at least"); return (-1); } if (LotsPerOrder + LotsLeft >= 10000) { MessageBox("Too many TotalLots, each order must be less than 10000 lots"); return (-1); } n = NormalizeDouble((MathAbs(RangeStart - RangeEnd) * MathPow(10, Digits)), 0)/(OrderCount-1); if (n < 1) { MessageBox("Too many OrderCount, each order must have 1 pips diff at least"); } double volume, price; string symbol; int cmd, magic, ticket, cnt, failed; double tp; symbol = Symbol(); magic = BATCH_OPEN_MAGIC; volume = LotsPerOrder; cnt = 0; failed = 0; for (i = 0; i < OrderCount; i++) { price = RangeStart + i * n * Point; if (i == OrderCount-1) { volume += LotsLeft; //price = RangeEnd; } RefreshRates(); if (ActionBuy) { if (price < Ask) { cmd = OP_BUYLIMIT; } else { cmd = OP_BUYSTOP; } } else { if (price < Bid) { cmd = OP_SELLSTOP; } else { cmd = OP_SELLLIMIT; } } if (TakeProfitRelative != 0) { if (ActionBuy) { tp = price + TakeProfitRelative * Point; } else { tp = price - TakeProfitRelative * Point; } } else { tp = TakeProfit; } ticket = OrderSend(symbol, cmd, volume, price, Slippage, StopLoss, tp, Comments, magic, Expiration, CLR_NONE); if (ticket < 0) { Print("Failed to place order at price " + price + ", Error: " + ErrorDescription(GetLastError())); failed++; } else { cnt++; } Sleep(Delay); } //---- Print(cnt + " orders placed, " + OrderCount + " requested, " + failed + " failed"); return(0); } //+------------------------------------------------------------------+
shwlm
注册时间2004-11-19
发表于:2006-02-17 05:16只看该作者
4楼
楼主强!隔三差五的总能给大家一些好东西。 不过俺是菜鸟,楼主能再给说说 MT4 的脚本该怎么安装使用就好了。
冰雪寒香
注册时间2005-03-04
发表于:2006-10-31 14:56只看该作者
5楼
这是去年我短消息请wfy05帮忙给写的脚本,今天因需要再查询又来看了一遍,顺便顶一下。
一千年太久
注册时间2008-05-06
发表于:2010-12-28 13:54只看该作者
7楼
多谢楼主:034: :034:
捌陆老虎
注册时间2011-06-17
积极参与奖
发表于:2012-10-22 07:01只看该作者
8楼
好脚本,一键N单
xyr
注册时间2012-11-18
发表于:2012-11-19 06:45只看该作者
9楼
批量开启和删除订单的脚本程序

本站免责声明:

1、本站所有广告及宣传信息均与韬客无关,如需投资请依法自行决定是否投资、斟酌资金安全及交易亏损风险;

2、韬客是独立的、仅为投资者提供交流的平台,网友发布信息不代表韬客的观点与意思表示,所有因网友发布的信息而造成的任何法律后果、风险与责任,均与韬客无关;

3、金融交易存在极高法律风险,未必适合所有投资者,请不要轻信任何高额投资收益的诱导而贸然投资;投资保证金交易导致的损失可能超过您投入的资金和预期。请您考虑自身的投资经验及风险承担能力,进行合法、理性投资;

4、所有投资者的交易帐户应仅限本人使用,不应交由第三方操作,对于任何接受第三方喊单、操盘、理财等操作的投资和交易,由此导致的任何风险、亏损及责任由投资者个人自行承担;

5、韬客不隶属于任何券商平台,亦不受任何第三方控制,韬客不邀约客户投资任何保证金交易,不接触亦不涉及投资者的任何资金及账户信息,不代理任何交易操盘行为,不向客户推荐任何券商平台,亦不存在其他任何推荐行为。投资者应自行选择券商平台,券商平台的任何行为均与韬客无关。投资者注册及使用韬客即表示其接受和认可上述声明,并自行承担法律风险。

版权所有:韬客外汇论坛 www.talkfx.com 联络我们:[email protected]