打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
模板
//+------------------------------------------------------------------+
//|                                                     翻倍模板.mq4 |
//|                                           Copyright 2009, Weewas |
//|                                                     QQ:104206237 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009, Weewas"
#property link      "QQ:104206237"
extern double Lots = 0.1;
extern bool open_pow_flag = true;
extern int i_no=6;//最多倍数。
extern double open_pow_base=2.0;//上次开仓数的倍数。

datetime time=0;
bool add=true;
 

//+------------------------------------------------------------------+
//| 计算当前货币买卖单。                                             |
//+------------------------------------------------------------------+
int CalculateBuyOrders() {
   int l_count_8 = 0;
   for (int l_pos_12 = 0; l_pos_12 < OrdersTotal(); l_pos_12++) {
      if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES) == FALSE) break;
      if (OrderSymbol() == Symbol()  && OrderCloseTime()==0 )
         {if (OrderType() == OP_BUY) l_count_8++;}
   }
   return (l_count_8);
}
int CalculateSellOrders() {
   int l_count_8 = 0;
   for (int l_pos_12 = 0; l_pos_12 < OrdersTotal(); l_pos_12++) {
      if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES) == FALSE) break;
      if (OrderSymbol() == Symbol() && OrderCloseTime()==0)
         {if (OrderType() == OP_SELL) l_count_8++;}
   }
   return (l_count_8);
}
//+------------------------------------------------------------------+
//| 计算历史单                                                       |
//+------------------------------------------------------------------+
void CalculateOrders(double &lots,int &li_0 )
{
   datetime max=0, x;
   int l_count_8 = 0;
   int ticket=-1;
   double profit=0;
   for (int l_pos_12 = 0; l_pos_12 <OrdersHistoryTotal(); l_pos_12++)
   {
      if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_HISTORY) == FALSE) break;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == 12345 )  
       x = OrderOpenTime();
     if (x > max)
     {
   ticket = OrderTicket();
   max = x;
   }
  }
 if (OrderSelect(ticket, SELECT_BY_TICKET) == false ) return;
    lots= OrderLots();//开仓手数。
    profit=OrderProfit();if(profit>0)li_0=0;if(profit<0)li_0=1;//盈利否。1是亏损.
  
}
//+------------------------------------------------------------------+
//|  准备开仓                                                        |
//+------------------------------------------------------------------+
void CheckForOpen(double &volume,int &li_0)
{
   double lots;
 if(add)CalculateOrders(lots,li_0 );
 if(li_0==1){if (open_pow_flag == true && volume<Lots * MathPow(open_pow_base, i_no))volume = lots * open_pow_base;else volume = Lots; }//如果开启翻倍, 上一次输单翻倍;否则不翻倍。
 if(li_0==0)volume = Lots;// 上一次盈利不翻倍。
}
                                     
//+------------------------------------------------------------------+
//|       以下开仓                                                   |
//+------------------------------------------------------------------+
void ForOpen(int type)
{
     double lots=0;
     int li_0;
     if(add)CheckForOpen(lots,li_0);
    
     int l_ticket_104;    
     if (type > 0)if ( time!=Time[0])
        {l_ticket_104 =OrderSend(Symbol(), OP_BUY, lots, Ask, 3, 0, 0, "", 12345, 0, Green);
         time=Time[0];}
     if (type < 0)if ( time!=Time[0])
         {l_ticket_104 = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, 0, 0, "",12345, 0, Red);
          time=Time[0];}
}
 
//+------------------------------------------------------------------+
//| 开仓信号                                                         |
//+------------------------------------------------------------------+
int Signal_OpenOrder()
{
    int x=0;
 
    x=1;
   
    return(x);
}
//+------------------------------------------------------------------+
//| 平仓信号                                                         |
//+------------------------------------------------------------------+
int Signal_CloseOrder() //1为平多单信号,-1为平空单信号
{
 int x=0;
 return(x);
}
//+------------------------------------------------------------------+
//| 关闭全部单                                                       |
//+------------------------------------------------------------------+
void CloseAll()
{
   int l_error_8;
   int l_ord_total_0 = OrdersTotal();
   if (l_ord_total_0 > 0) {
      for (int l_pos_4 = l_ord_total_0 - 1; l_pos_4 >= 0; l_pos_4--) {
         OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() == Symbol()) {
            if (OrderType() == OP_BUY) {
               OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 3, Yellow);
               l_error_8 = GetLastError();
               if (l_error_8 > 1/* NO_RESULT */) Print("Error message line 47 , error: ", l_error_8);
            } else {
               if (OrderType() == OP_SELL) {
                  OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 3, Yellow);
                  l_error_8 = GetLastError();
                  if (l_error_8 > 1/* NO_RESULT */) Print("Error message line 56 , error: ", l_error_8);
               } else {
                  if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP || OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT ) {
                    OrderDelete(OrderTicket());
                     l_error_8 = GetLastError();
                     if (l_error_8 > 1/* NO_RESULT */) Print("Error message line 65 , error: ", l_error_8);
                  }
               }
            }
        }
      }
   }
   return (0);
}

//+------------------------------------------------------------------+
//| 主程序                                                           |
//+------------------------------------------------------------------+
void start()
 {  
  
   int li_0 = CalculateBuyOrders() + CalculateSellOrders();
   int li_4 = CalculateSellOrders();
   int li_8 = CalculateBuyOrders(); 
   
   if (li_0 == 0 )
      {
         if(Signal_OpenOrder()==1)ForOpen(1);
         if(Signal_OpenOrder()==-1)ForOpen(-1);      
      }
  
   if ( li_4 >0 && Signal_CloseOrder()==-1)CloseAll();
   if (li_8 >0 && Signal_CloseOrder()==1)CloseAll();  
   return(0);
}

//-------------------------------------------------------------------
//--------------------------------------------------------------------
 if (Opentrades==0)//如果没有开单
     {
      if (iMA(Symbol(),0,6,0,MODE_EMA,PRICE_CLOSE,1)>iMA(Symbol(),0,12,0,MODE_SMA,PRICE_CLOSE,1) && Bid<=iLow(Symbol(),0,Lowest(Symbol(),0,MODE_LOW,6,1)))
        {
         OrderSend(Symbol(),OP_BUY,Ilo,Ask,Slip,Ask-StopLoss*Point,0,"CP",0,0,Blue);
        }
      if (iMA(Symbol(),0,6,0,MODE_EMA,PRICE_CLOSE,1)<iMA(Symbol(),0,12,0,MODE_SMA,PRICE_CLOSE,1) && Bid>=iHigh(Symbol(),0,Highest(Symbol(),0,MODE_HIGH,6,1)))
        {
         OrderSend(Symbol(),OP_SELL,Ilo,Bid,Slip,Bid+StopLoss*Point,0,"CP",0,0,Blue);
        }
     }
//------------------------
if (Bid<=iLow(Symbol(),0,Lowest(Symbol(),0,MODE_LOW,6,1)))
 if (Bid>=iHigh(Symbol(),0,Highest(Symbol(),0,MODE_HIGH,6,1)))//如果买单大于6周期的最高点
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
MT4一次下三个单的小程序
交易系统
MT4实用函数
mt4一个综合智能交易系统的经典代码
TDJX模板
自动交易系统编程求助。
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服