找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
首页论坛EAHub 外汇论坛
查看: 20|回复: 0

【MQL4函数】挂单模块函数

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-27 16:49:00 | 显示全部楼层 |阅读模式
挂单模块一般来说不会存在延迟的问题,所以它只需要解决拆单的问题,但是需要解决价格错误的问题,比如说挂突破买单,当挂单的价格小于当前买价时,挂单是挂不了的,所以要排除这种价格错误的情况。代码如下:

int pendingorder(string sym,string direction,double price,double lot,double sl,
double tp,int mag,string comment)
{
   int check;
   double lot_min=MarketInfo(sym,MODE_MINLOT);
   double lot_max=MarketInfo(sym,MODE_MAXLOT);
   double lot_last=0;
   int huadian=10;
   double amount;
   int i;
   if(lot<lot_min)
   {
      Print("lot is too small");
      return(1);
   }
   if(direction=="BUYSTOP" && price<MarketInfo(sym,MODE_ASK)+
MarketInfo(sym,MODE_SPREAD)*MarketInfo(sym,MODE_POINT))
   {
      Print("rice is too low for BUYSTOP order");
      return(1);
   }
   else if(direction=="BUYLIMIT" && price>MarketInfo(sym,MODE_ASK)-
MarketInfo(sym,MODE_SPREAD)*MarketInfo(sym,MODE_POINT))
   {
      Print("rice is too high for BUYLIMIT order");
      return(1);
   }
   else if(direction=="SELLSTOP" && price>MarketInfo(sym,MODE_BID)-
MarketInfo(sym,MODE_SPREAD)*MarketInfo(sym,MODE_POINT))
   {
      Print("rice is too high for SELLSTOP order");
      return(1);
   }
   else if(direction=="SELLLIMIT" && price<MarketInfo(sym,MODE_BID)+
MarketInfo(sym,MODE_SPREAD)*MarketInfo(sym,MODE_POINT))
   {
      Print("rice is too low for SELLLIMIT order");
      return(1);
   }
   
   if(lot>lot_max)
   {
      amount=MathCeil(lot/lot_max);
      lot_last=lot-(amount-1)*lot_max;
      for(i=(int)amount;i>0;i--)
                {
              if (i!=1)
              {
                  if(direction=="BUYSTOP")
                   {
              check=OrderSend(sym,OP_BUYSTOP,lot_max,price,huadian,sl,tp,
comment,mag,0,clrBlue);
            }
            else if(direction=="BUYLIMIT")
            {
              check=OrderSend(sym,OP_BUYLIMIT,lot_max,price,huadian,sl,tp,
comment,mag,0,clrBlue);
            }
            else if(direction=="SELLSTOP")
            {
              check=OrderSend(sym,OP_SELLSTOP,lot_max,price,huadian,sl,tp,
comment,mag,0,clrRed);
            }
            else if(direction=="SELLLIMIT")
            {
              check=OrderSend(sym,OP_SELLLIMIT,lot_max,price,huadian,sl,tp,
comment,mag,0,clrRed);
            }
              }
              else
              {
            if(direction=="BUYSTOP")
                         {
              check=OrderSend(sym,OP_BUYSTOP,lot_last,price,huadian,sl,tp,
comment,mag,0,clrBlue);
            }
            else if(direction=="BUYLIMIT")
            {
              check=OrderSend(sym,OP_BUYLIMIT,lot_last,price,huadian,sl,tp,
comment,mag,0,clrBlue);
            }
            else if(direction=="SELLSTOP")
            {
              check=OrderSend(sym,OP_SELLSTOP,lot_last,price,huadian,sl,tp,
comment,mag,0,clrRed);
            }
            else if(direction=="SELLLIMIT")
            {
              check=OrderSend(sym,OP_SELLLIMIT,lot_last,price,huadian,sl,tp,
comment,mag,0,clrRed);
            }
                }
      }
   }
   else
   {
      if(direction=="BUYSTOP")
      {
           check=OrderSend(sym,OP_BUYSTOP,lot,price,huadian,sl,tp,
comment,mag,0,clrBlue);
      }
      else if(direction=="BUYLIMIT")
      {
           check=OrderSend(sym,OP_BUYLIMIT,lot,price,huadian,sl,tp,
comment,mag,0,clrBlue);
      }
      else if(direction=="SELLSTOP")
      {
           check=OrderSend(sym,OP_SELLSTOP,lot,price,huadian,sl,tp,
comment,mag,0,clrRed);
      }
      else if(direction=="SELLLIMIT")
      {
           check=OrderSend(sym,OP_SELLLIMIT,lot,price,huadian,sl,tp,
comment,mag,0,clrRed);
      }
   }
   return(0);
}

复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|EAHub外汇论坛

GMT+8, 2026-10-10 01:44 , Processed in 0.103281 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表