学习逻辑 - 页 10 1...3456789101112131415 新评论 Sceptic Philozoff 2010.06.28 19:05 #91 可能是这样的,如果没有参数的话。 bool IsActiveType() { int type = OrderType(); return (type == OP_BUY || type == OP_SELL); } bool IsAnySellType() { int type = OrderType(); return (type == OP_SELL || type == OP_SELLLIMIT || type == OP_SELLSTOP); } { if (IsActiveType()) { //... } if (IsAnySellType()) { //... } } Prival 2010.06.28 19:11 #92 //+----------------------------------------------------------------------------+ //| Возвращает количество позиций. | //| Параметры: | //| sy - наименование инструмента ("" - любой символ, | //| NULL - текущий символ) | //| op - операция (-1 - любая позиция) | //| mn - MagicNumber (-1 - любой магик) | //+----------------------------------------------------------------------------+ int NumberOfPositions(string sy="", int op=-1, int mn=-1) { int i, k=OrdersTotal(), kp=0; if (StringLen(sy)==1 && StringGetChar(sy, 0)==48) sy=Symbol(); for (i=0; i<k; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol()==sy || sy=="") { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { if (op<0 || OrderType()==op) { if (mn<0 || OrderMagicNumber()==mn) kp++; } } } } } return(kp); } [删除] 2010.06.28 19:24 #93 Mathemat: 可能是这样的,如果没有参数的话。 bool IsActiveType(int type = -1) { if (type < 0) type = OrderType(); return (type == OP_BUY || type == OP_SELL); } Sceptic Philozoff 2010.06.28 19:29 #94 这是有参数的,但你不必指定一个参数。 [删除] 2010.06.28 19:34 #95 我的意思是要把参数从调用中删除。而且我无法从功能描述中删除它们。 [删除] 2010.06.28 19:44 #96 怎么说呢,这是对现有的订单属性 功能的命名系统的整合。 bool OrderIsActiveType(int type = -1) { if (type < 0) type = OrderType(); return (type == OP_BUY || type == OP_SELL); } if (OrderIsActiveType()) { //... } if (OrderIsAnySellType()) { //... } TheXpert 2010.06.28 19:57 #97 这并不明显,所以对我来说不起作用。 而不知何故,它本质上是一样的,但有了参数就更清楚了,所以默认它没有意义,我认为。 _______ 我们已经做了太多这样的事情。让我们给真正的代码进行重新设计,讨论等。 [删除] 2010.06.28 20:08 #98 但我从一堆代码中得到了它。 bool SafelyCloseOrder(int orderticket, string operation = "") { bool closed = false; LastError = 0; string ordercomment = ""; for(int attempt = 0; attempt <= 10 && !closed; attempt++) if (OrderSelect(orderticket, SELECT_BY_TICKET, MODE_TRADES)) if (WaitForConnection(6, operation)) { ordercomment = OrderComment(); if (OrderType() == OP_BUY) closed = OrderClose(orderticket, OrderLots(), NormalizeDouble(MarketInfo(OrderSymbol(), MODE_BID), MarketInfo(OrderSymbol(), MODE_DIGITS)), Set_slippage, Blue); else closed = OrderClose(orderticket, OrderLots(), NormalizeDouble(MarketInfo(OrderSymbol(), MODE_ASK), MarketInfo(OrderSymbol(), MODE_DIGITS)), Set_slippage, Red); LastError = LastError(); if (LastError != 0) Print(WindowExpertName() + " " + operation + " " + ErrorDescription(LastError)); if (!closed) { Sleep(3000 + attempt * 1000); RefreshRates(); } } if (closed) { Alert(WindowExpertName() + " " + operation + " Ордер " + orderticket + " " + ordercomment + " закрыт!"); PlaySound("Case.wav"); Sleep(555); } else { Alert(WindowExpertName() + " " + operation + " Не закрывается ордер " + orderticket + " " + ordercomment + "!"); PlaySound("NT_Ball_BAMMM!.WAV"); Sleep(555); } return(closed); } Evgeniy Logunov 2010.06.28 20:11 #99 这个怎么样? // основные битовые маски #define ORD_SELL 1 #define ORD_BUY 2 #define ORD_MARKET 4 #define ORD_LIMIT 8 #define ORD_STOP 16 #define ORD_INVALID 32 // комбинированные битовые маски #define ORD_MARKET_SELL 5 // ORD_SELL | ORD_MARKET #define ORD_MARKET_BUY 6 // ORD_BUY | ORD_MARKET #define ORD_LIMIT_SELL 9 // ORD_SELL | ORD_LIMIT #define ORD_LIMIT_BUY 10 // ORD_BUY | ORD_LIMIT #define ORD_STOP_SELL 17 // ORD_SELL | ORD_STOP #define ORD_STOP_BUY 18 // ORD_BUY | ORD_STOP #define ORD_PENDING 24 // ORD_STOP | ORD_LIMIT // получение битовой маски для текущего ордера int OrderTypeBitmask() { int orderType = OrderType(); int bitmask = ORD_INVALID; switch (orderType) { case OP_SELL: bitmask = ORD_MARKET_SELL; break; case OP_BUY: bitmask = ORD_MARKET_BUY; break; case OP_SELLLIMIT: bitmask = ORD_LIMIT_SELL; break; case OP_BUYLIMIT: bitmask = ORD_LIMIT_BUY; break; case OP_SELLSTOP: bitmask = ORD_STOP_SELL; break; case OP_BUYSTOP: bitmask = ORD_STOP_BUY; break; } return (bitmask); } // проверка по маске bool CheckMask(int value, int mask) { return ((value & mask) != 0); } // пример: for (int i = OrdersTotal() - 1; i >= 0; i--) { // выбор ордера, отбрасывание по символу, magic'у и т.п. if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if (OrderSymbol() != Symbol) continue; ... // обработка ордера int ordType = OrderTypeBitmask(); bool removeOrder = false; if ((signal == SIG_BUY) && CheckMask(ordType, ORD_SELL)) removeOrder = true; else if ((signal == SIG_SELL) && CheckMask(ordType, ORD_BUY)) removeOrder = true; if (!removeOrder) continue; if (CheckMask(ordType, ORD_MARKET)) RemoveMarketOrder(); else if (CheckMask(ordType, ORD_PENDING)) RemovePendingOrder(); } keekkenen 2010.06.28 20:28 #100 Mathemat: 可能是这样的,如果没有参数的话。 bool IsActiveType() { int type = OrderType(); return (type == OP_BUY || type == OP_SELL); } 由于orderselect可能返回false,IsActiveType()将返回0,即OP_BUY,这是不正确的使用...... 1...3456789101112131415 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
可能是这样的,如果没有参数的话。
可能是这样的,如果没有参数的话。
怎么说呢,这是对现有的订单属性 功能的命名系统的整合。
bool OrderIsActiveType(int type = -1) { if (type < 0) type = OrderType(); return (type == OP_BUY || type == OP_SELL); } if (OrderIsActiveType()) { //... } if (OrderIsAnySellType()) { //... }这并不明显,所以对我来说不起作用。
而不知何故,它本质上是一样的,但有了参数就更清楚了,所以默认它没有意义,我认为。
_______
我们已经做了太多这样的事情。让我们给真正的代码进行重新设计,讨论等。但我从一堆代码中得到了它。
这个怎么样?
可能是这样的,如果没有参数的话。