有您的持续关注
我们会做得更好

MT4挂单脚本 挂卖单 SELLLIMIT SELLSTOP



MT4挂单脚本 挂卖单 SELLLIMIT  SELLSTOP,该脚本可以实现按照设定手数 距离,上下挂卖单。

MQL4源码如下:

 //+------------------------------------------------------------------+
 //|                                                        挂买单.mq4 |
 //|                                         http://www.125808047.com |
 //+------------------------------------------------------------------+
 #property copyright "www.125808047.com."
 #property link      "http://www.125808047.com/"
 #property show_inputs
 extern double     最小手数 = 0.01;
extern string a1="自动模式设为0累加设为1固定";
 extern int        自动模式 = 0;
 extern double 第一单手数=0.01;
 extern double 上第1档手数=0.01;
 extern double 上第2档手数=0.01;
 extern double 上第3档手数=0.01;
 extern double 上第4档手数=0.01;
 extern double 上第5档手数=0.02;
 extern double 上第6档手数=0.02;
 extern double 上第7档手数=0.03;
 extern double 下第1档手数=0.01;
 extern double 下第2档手数=0.01;
 extern double 下第3档手数=0.01;
 extern double 下第4档手数=0.01;
 extern double 下第5档手数=0.01;
 extern double 下第6档手数=0.01;
 extern double 下第7档手数=0.01;
extern double 上挂单距离=55;
 extern double 下挂单距离=0;
 extern int    编码magic            = 88888885;
 extern double 上挂单次数=7;
 extern double 下挂单次数=0;
extern double MaxLots=0.2;
int gd_180;
 int gd_181;
 int gd_182;
 int li_0;
int init() {
    li_0 = 1;
   if (Digits == 5.0 || Digits == 3.0) li_0 = 10;
 
   return (0);
 }
 int start()
  {
 Counts();
OrderSend(Symbol(), OP_SELL, 第一单手数, Bid, 2*li_0, 0, 0,WindowExpertName( ) , 编码magic, 0, Blue);
 Sguada();
 Xguada();
 
 
   return(0);
  }
 //+------------------------------------------------------------------+
 void Sguada()
 {
     for (int li_132 = 上挂单次数; li_132 > 0; li_132--) {
               RefreshRates();
               Counts();
               OrderSend(Symbol(), OP_SELLLIMIT, GetLots1(自动模式), Bid+(gd_181+1)*上挂单距离*li_0*Point, 2*li_0, 0, 0,"卖挂单"+"-"+Symbol() , 编码magic, 0, Blue);
               if (GetLastError() != 0) {
                  Print("Buy OrderSend 3 failed with error #", GetLastError());
                  Sleep(1000);
               }
               if(上挂单次数<=gd_181) break;
            }
           
            }
 void Xguada()
 {
     for (int li_132 = 下挂单次数; li_132 > 0; li_132--) {
               RefreshRates();
               Counts();
               OrderSend(Symbol(), OP_SELLSTOP, GetLots(自动模式), Bid-(gd_182+1)*下挂单距离*li_0*Point, 2*li_0, 0, 0,"卖突破单"+"-"+Symbol() , 编码magic,0, Blue);
               if (GetLastError() != 0) {
                  Print("Buy OrderSend 3 failed with error #", GetLastError());
                  Sleep(1000);
               }
               if(下挂单次数<=gd_182) break;
            }
           
            }
void Counts() {  
   gd_180 = 0;
   gd_181 = 0;
   gd_182 = 0;
   for (int cn = OrdersTotal() - 1; cn >= 0; cn--) {
      OrderSelect(cn, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol()||编码magic!=OrderMagicNumber( ) ) continue;
      if (OrderSymbol() == Symbol()) {
        if (OrderType() == OP_SELL&&编码magic==OrderMagicNumber( )) gd_180 ++;
         if (OrderType() == OP_SELLLIMIT&&编码magic==OrderMagicNumber( )) gd_181 ++;
         if (OrderType() == OP_SELLSTOP&&编码magic==OrderMagicNumber( )) gd_182 ++;
      }
   }
 }
 double GetLots(int flag)
{
   double Lots ;
   Counts();
 
      if(flag==0)
      {
       
 
 switch(gd_182)
 {
 case 0:
 {
 Lots =下第1档手数 ;
 break;
 }
 case 1:
 {
 Lots =下第2档手数 ;break;
 }
 case 2:
 {
 Lots =下第3档手数 ;break;
 }
 case 3:
 {
 Lots =下第4档手数 ;break;
 }
 case 4:
 {
 Lots =下第5档手数 ;break;
 }
 case 5:
 {
 Lots =下第6档手数 ;break;
 }
 case 6:
 {
 Lots =下第7档手数 ;break;
 }
       
 }
 
 }
   if(flag==1) Lots = 第一单手数 ;
    
      if(Lots < 第一单手数) Lots = 第一单手数;
      if(Lots > MaxLots) Lots = MaxLots;
  
   return(Lots);
 }
 double GetLots1(int flag)
{
   double Lots = 第一单手数;
   Counts();
 
      switch(flag)
      {
         case 0:
         {
             switch(gd_181+1)
 {
 case 1:
 {
 Lots =上第1档手数 ;
 break;
 }
 case 2:
 {
 Lots =上第2档手数 ;break;
 }
 case 3:
 {
 Lots =上第3档手数 ;break;
 }
 case 4:
 {
 Lots =上第4档手数 ;break;
 }
 case 5:
 {
 Lots =上第5档手数 ;break;
 }
 case 6:
 {
 Lots =上第6档手数 ;break;
 }
 case 7:
 {
 Lots =上第7档手数 ;break;
 }
       
 }
           
            break;
            }
         case 1:
            Lots = 第一单手数 ;
            break;
      }
      if(Lots < 第一单手数) Lots = 第一单手数;
      if(Lots > MaxLots) Lots = MaxLots;
  
   return(Lots);
 }

如您喜欢此文章请点下面分享按钮↴峰汇在线 » MT4挂单脚本 挂卖单 SELLLIMIT SELLSTOP
上一篇:
下一篇:
分享到:更多 ()