【宽客EA源码】震荡剥头皮 - MetaTrader 4EA

0
回复
6681
查看
[复制链接]

121

主题

5

回帖

503

积分

实习版主

积分
503
来源: 2019-8-10 21:15:32 显示全部楼层 |阅读模式
分享一个震荡剥头皮EA源码。本源码是一个基于MQL4的源码策略。


  1. #property copyright "YANG"
  2. #property version   "1.00"
  3. #property copyright "EA"
  4. #property strict

  5. extern bool   k_g_1 =false;     
  6. extern int    fx_yc =100;       //Abnormal fluctuation
  7. extern double lots  =0.02;      //lots
  8. extern float  zhi_s =1;         //stop($)
  9. extern int    zhi_y =15;        //Take profit
  10. extern int   xiao_b =6;         //1 hour profit multiple
  11. extern int   jie_j  =10;        //Long position profit multiple
  12. extern int    dian_c=2;         //Spread
  13. extern int    magic =88888888;  

  14. int    wei_z =2,
  15.        wei_s =100;     
  16.       
  17. double dian_z=0.01,   
  18.        lots_s;         

  19. int    f_z=0;         
  20.         
  21. int    take;     
  22. datetime time;   
  23. bool   fx_jj =false;      
  24. //+------------------------------------------------------------------+
  25. //                                 |
  26. //+------------------------------------------------------------------+
  27. int OnInit()
  28.   {
  29.       datetime tom=0;
  30.       int AA_1=OrdersTotal();
  31.       if(Point < 0.001)
  32.      {
  33.            dian_z=0.00001;
  34.            wei_z=5;
  35.            wei_s=100000;
  36.      }
  37.      else if(Point == 0.001)
  38.      {
  39.            dian_z=0.001;
  40.            wei_z=3;
  41.            wei_s=1000;
  42.      }
  43.      
  44.      EventSetTimer(1);
  45.      for(int AA=0; AA<AA_1; AA++)
  46.      {
  47.          if(!OrderSelect(AA, SELECT_BY_POS, MODE_TRADES))  break;
  48.          if(OrderSymbol() != Symbol())  continue;
  49.          if(OrderMagicNumber() != magic) continue;
  50.          
  51.          if(OrderOpenTime() > tom)  
  52.          {
  53.              take=OrderTicket();
  54.              tom=OrderOpenTime();
  55.              continue;
  56.          }
  57.          
  58.      }
  59. //---
  60.    return(INIT_SUCCEEDED);
  61. }

  62. void OnDeinit(const int reason)
  63. {
  64.    
  65.     EventKillTimer();
  66. }

  67. //+------------------------------------------------------------------+
  68. //|                                       |
  69. //+------------------------------------------------------------------+
  70. void OnTick()
  71. {
  72.     static double prof_lr;   
  73.     static double prof_lr_1=0;
  74.     static datetime time_1 =0;
  75.     int    or_d=0;            
  76.     double jj_ok=0;            
  77.     bool   bo=false;         
  78.     int    AA_1=OrdersTotal();
  79.    
  80.     double stop_lr=0;         
  81.     datetime tme=0;
  82.     int   xy=0;

  83.     double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
  84.    if(lots<min_volume)
  85.      {
  86.       Print("交易量小于允许的最小交易量,SYMBOL_VOLUME_MIN=%.2f");
  87.       return;
  88.      }   
  89.     for(int A=0; A < AA_1; A++)
  90.     {
  91.         if(!OrderSelect(A, SELECT_BY_POS, MODE_TRADES))  break;
  92.         if(OrderSymbol() != Symbol())  continue;
  93.         if(OrderMagicNumber() != magic) continue;
  94.         
  95.         or_d++;  
  96.         
  97.         if(OrderProfit() < 0)  
  98.                stop_lr +=OrderSwap()+OrderProfit()+OrderCommission();
  99.                
  100.          
  101.         if(TimeCurrent()-14400 <= OrderOpenTime())  fx_jj=true;
  102.      
  103.         if(OrderType() == OP_BUY)
  104.         {
  105.             if(OrderClosePrice() - OrderOpenPrice() > zhi_y*dian_z)  
  106.             {
  107.                 jj_ok=OrderSwap()+OrderProfit()+OrderCommission();
  108.                 prof_lr += jj_ok;
  109.                 prof_lr_1 +=jj_ok;  
  110.                
  111.                 if(OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c))
  112.                 {
  113.                   
  114.                     
  115.                     if(OrderTicket() != take)  continue;
  116.                   
  117.                       if(f_z==2 && Close[0] - Open[0] < fx_yc*dian_z && Close[0] - Open[0] > 0)
  118.                       {
  119.                            take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "12", magic);
  120.                              time=Time[0];
  121.                              continue;
  122.                       }
  123.                       else if(f_z==1)
  124.                       {
  125.                          take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "11", magic);
  126.                           time=Time[0];
  127.                           continue;
  128.                       }
  129.                       take=0;
  130.                 }
  131.             }
  132.          
  133.             if(OrderTicket() != take)  continue;
  134.             if(OrderOpenPrice()-OrderClosePrice() > zhi_y*dian_z)
  135.             {
  136.                
  137.                 if(f_z==2)
  138.                 {
  139.                      take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "10", magic);
  140.                        time=Time[0];
  141.                        continue;
  142.                 }
  143.                 else if(f_z==1)
  144.                 {
  145.                    take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "9", magic);
  146.                     time=Time[0];
  147.                     continue;
  148.                 }
  149.             }
  150.         }
  151.         else if(OrderType() == OP_SELL)
  152.         {
  153.             if(OrderOpenPrice() - OrderClosePrice() > zhi_y*dian_z)
  154.             {
  155.                 jj_ok=OrderSwap()+OrderProfit()+OrderCommission();
  156.                 prof_lr += jj_ok;
  157.                 prof_lr_1 +=jj_ok;
  158.                 if(OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c))
  159.                 {
  160.                   
  161.                   
  162.                    if(TimeHour(TimeCurrent())==0)  continue;
  163.                     if(OrderTicket()!=take)  continue;
  164.                    if(f_z==2 && Open[0] - Close[0] < fx_yc*dian_z && Open[0] - Close[0] > 0)
  165.                    {
  166.                         take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "8", magic);
  167.                           time=Time[0];
  168.                           continue;
  169.                    }
  170.                    else if(f_z==1)
  171.                    {
  172.                       take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "7", magic);
  173.                          time=Time[0];
  174.                          continue;
  175.                    }
  176.                    take=0;
  177.                      
  178.                 }
  179.             }
  180.             if(OrderTicket()!= take)  continue;
  181.             if(OrderClosePrice() - OrderOpenPrice() > zhi_y*dian_z)
  182.             {
  183.                
  184.                 if(f_z==2)
  185.                 {
  186.                      take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "6", magic);
  187.                        time=Time[0];
  188.                        continue;
  189.                 }
  190.                 else if(f_z==1)
  191.                 {
  192.                    take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "5", magic);
  193.                       time=Time[0];
  194.                       continue;
  195.                 }
  196.             }
  197.         }
  198.     }
  199.    
  200.     if(or_d==0)
  201.     {
  202.         lots_s=lots;  
  203.         time=0;
  204.     }
  205.     if(time_1==0 && prof_lr_1 > 0)
  206.    {
  207.        time_1=TimeCurrent()+900;
  208.    }
  209.      
  210.       if(time != Time[0])
  211.       {
  212.            if(fx_jj)  jj_ok=or_ls();
  213.            xy=0;
  214.            for(int AA=0; AA<AA_1; AA++)
  215.            {
  216.                if(!OrderSelect(AA, SELECT_BY_POS, MODE_TRADES))  break;
  217.                if(OrderSymbol() != Symbol())  continue;
  218.                if(OrderMagicNumber() != magic) continue;
  219.                
  220.                
  221.                if(xy >= 3)
  222.                {
  223.                   bo=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c);
  224.                   continue;
  225.                }
  226.                if(prof_lr + stop_lr >= zhi_s || prof_lr + stop_lr >= NormalizeDouble(zhi_s/2, 2))  
  227.                {
  228.                    bo=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c);
  229.                    take=0;
  230.                    xy=3;
  231.                    prof_lr=0;
  232.                    continue;
  233.                }
  234.                if(prof_lr_1 + stop_lr >= zhi_s*xiao_b && time_1 < TimeCurrent())
  235.                {
  236.                    bo=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c);
  237.                    xy=4;
  238.                    take=0;
  239.                    time_1=TimeCurrent()+900;
  240.                    prof_lr_1=0;
  241.                    continue;
  242.                }
  243.                
  244.                if(fx_jj)
  245.                {
  246.                    if(jj_ok <= 0)  continue;
  247.                    if(jj_ok + stop_lr >= zhi_s*jie_j)  
  248.                    {
  249.                       bo=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c);
  250.                       xy=5;
  251.                       continue;
  252.                    }
  253.                      
  254.                }
  255.                
  256.            }
  257.            
  258.            xy=0;
  259.          
  260.           if(or_d > 0 && take > 0)  return;
  261.          
  262.            for(int xx=OrdersTotal()-1; xx>=0; xx--)
  263.           {
  264.               if(!OrderSelect(xx, SELECT_BY_POS, MODE_TRADES))  break;
  265.               if(OrderSymbol() != Symbol())  continue;
  266.               if(OrderMagicNumber() != magic) continue;
  267.               
  268.               if(OrderOpenTime() > tme && OrderType()==OP_BUY)
  269.               {
  270.                   time=OrderOpenTime();
  271.                   xy=1;
  272.               }
  273.               else if(OrderOpenTime() > tme && OrderType()==OP_SELL)
  274.               {
  275.                   time=OrderOpenTime();
  276.                   xy=2;
  277.               }
  278.           }
  279.          
  280.           if(xy==1)
  281.           {
  282.               take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "4", magic);
  283.               if(take > 0)
  284.                 time=Time[0];
  285.           }
  286.           else if(xy==2)
  287.           {
  288.               take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "3", magic);
  289.               if(take > 0)
  290.                 time=Time[0];
  291.           }
  292.           else
  293.           {
  294.               if(Open[1] > Close[1])
  295.               {
  296.                   take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "2", magic);
  297.                  if(take > 0)
  298.                    time=Time[0];
  299.               }
  300.               else
  301.               {
  302.                   take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "1", magic);
  303.                  if(take > 0)
  304.                    time=Time[0];
  305.               }  
  306.           }
  307.           if(take<0) f_z=0;
  308.       
  309.       }  
  310.    
  311. }
  312. void OnTimer()
  313. {
  314.       
  315.       int seconds=0;// the left seconds of the current bar
  316.       int h = 0; //Hour
  317.       int m = 0; //Minute
  318.       int s = 0; //Second  hh:mm:ss
  319.       int   xy=0;
  320.       datetime timee=iTime(Symbol(),PERIOD_CURRENT,0),
  321.                tme=0;
  322.       //double   close = iClose(Symbol(),PERIOD_CURRENT,0);
  323.       
  324.       seconds=PeriodSeconds(PERIOD_CURRENT) -(int)(TimeCurrent()-timee);

  325.       h = seconds/3600;
  326.       m = (seconds - h*3600)/60;
  327.       s = (seconds - h*3600 - m*60);
  328.       
  329.       if(m >= 3 && s>=0) f_z=1;
  330.       else if(m < 3)  f_z=2;
  331.       
  332. }
  333. double or_ls()
  334. {
  335.     static datetime tim=0;
  336.     double   prof_lr4=0;   
  337.     datetime tome;
  338.     if(!k_g_1)  return(0);
  339.     tome=TimeCurrent()-72000;
  340.     for(int x=OrdersHistoryTotal()-1; x>=0; x--)
  341.     {
  342.         if(!OrderSelect(x, SELECT_BY_POS, MODE_HISTORY))
  343.         {
  344.             tim=TimeCurrent()+600;
  345.             break;
  346.         }
  347.         if(OrderSymbol() != Symbol())  continue;
  348.         if(OrderMagicNumber() != magic)  continue;
  349.         if(OrderOpenTime() > tome)
  350.         {
  351.            prof_lr4 += OrderSwap()+OrderProfit()+OrderCommission();
  352.         }
  353.     }
  354.    
  355.     return(prof_lr4);
  356. }
复制代码
英镑-房子.jpg
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 免费注册
关注微信