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

MT4统计账号日月周交易情况的脚本



该脚本可以统计账号日、月、周的盈利情况及盈利率,可以设定盈利目标。

脚本加载后显示如图:

MT4脚本MQL4源码如下:

//+------------------------------------------------------------------+
//|                                               日周月盈利统计.mq4 |
//|                                     Copyright 2016, QQ:125808047 |
//+------------------------------------------------------------------+
#property copyright "Copyright @2016, 125808047"
#property link      "http://www.125808047.com/"

#property indicator_chart_window
extern int 横坐标       = 100;
extern int 纵坐标       = 801;
extern int 右坐标       = 140;
extern int 盈利比字大小 = 14;
extern int 周目标盈利 = 5;
extern int 月目标盈利 =20;

  
double Curtime=0;
double CurrTime;

int init()
    
  { 
  double orderprofits = 0;
   for(int u = 0; u < OrdersHistoryTotal(); u++)
   {
      
       if(OrderSelect(u, SELECT_BY_POS, MODE_HISTORY))
      {         
            if ((TimeDayOfWeek(OrderCloseTime())==1 ||TimeDayOfWeek(OrderCloseTime())==2 ||
TimeDayOfWeek(OrderCloseTime())==3||TimeDayOfWeek(OrderCloseTime())==4||TimeDayOfWeek(OrderCloseTime())==5)
           && ( OrderType()== OP_BUY || OrderType()== OP_SELL) )
             {  orderprofits += OrderProfit();
              }
      }   
      }
  
  double ylz=NormalizeDouble(orderprofits/(AccountBalance()-orderprofits)*100,2);
  
  if(GlobalVariableCheck("pt121")&&GlobalVariableGet("pt121")<TimeLocal()-259200){
  GlobalVariableDel("pt121");

  }
   return(0);
  }

int deinit()
  {
  if(!GlobalVariableCheck("pt121"))GlobalVariableSet("pt121",TimeLocal());

   ObjectDelete("t27");ObjectDelete("t28");ObjectDelete("t29");ObjectDelete("t30");
    ObjectDelete("t31");ObjectDelete("t32");ObjectDelete("t33");ObjectDelete("t34");
     ObjectDelete("t35");ObjectDelete("t36");
   
   return(0);
  }

int start()
  {
  double orderprofitsd=0, orderprofits = 0,orderprofitsy = 0;
    int tdow = TimeDayOfWeek(TimeCurrent());
   if(tdow == 0)
      tdow = 7;
   datetime wfirst = TimeCurrent() - 86400 * tdow;
   
   for(int i = 0; i < OrdersHistoryTotal(); i++)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
      {   
           if(TimeYear(OrderCloseTime()) == TimeYear(TimeCurrent()) 
            &&TimeMonth(OrderCloseTime()) == TimeMonth(TimeCurrent())
            && TimeDay(OrderCloseTime()) == TimeDay(TimeCurrent())
           && ( OrderType()== OP_BUY || OrderType()== OP_SELL))
            orderprofitsd += OrderProfit();  //日
            
           if(OrderCloseTime() >= wfirst            
           && ( OrderType()== OP_BUY || OrderType()== OP_SELL))
            orderprofitsy += OrderProfit(); //周
      
         if(TimeYear(OrderCloseTime()) == TimeYear(TimeCurrent()) 
            &&TimeMonth(OrderCloseTime()) == TimeMonth(TimeCurrent())
             && ( OrderType()== OP_BUY || OrderType()== OP_SELL))
          {  orderprofits += OrderProfit(); //月
         }
      }
   }
  double yld=NormalizeDouble(orderprofitsd/(AccountBalance()-orderprofitsd)*100,2);
  double yla=NormalizeDouble(orderprofitsy/(AccountBalance()-orderprofitsy)*100,2);
  double ylz=NormalizeDouble(orderprofits/(AccountBalance()-orderprofits)*100,2);
 
   double  dlots = 0;
        for(int i1=0;i1<OrdersTotal();i1++)
   {
      if(OrderSelect(i1,SELECT_BY_POS,MODE_TRADES)==false)        
         break;
         dlots += OrderLots();
  double lost=NormalizeDouble(OrderLots(),2);

  }
 
  
   double kld,kla,kay;
   if(orderprofitsd>0)
      kld=Red;
      else {
        if (orderprofitsd<0)
        kld=SpringGreen;
         else kld=Yellow;}
   
    if(orderprofits>0) 
       kla=Red;
     else{ if(orderprofits<0) 
          kla=SpringGreen;
          else kla=Yellow;
          }
          
  if (orderprofitsy>0)
       kay=Red;
    else{ if (orderprofitsy<0)
         kay=SpringGreen;
         else kay=Yellow;}
        
  double mylots= (AccountEquity()/ MarketInfo(Symbol(),MODE_MARGINREQUIRED)*0.05);       

   ObjectDelete("t27");ObjectDelete("t28");ObjectDelete("t29");ObjectDelete("t30");
   ObjectDelete("t31");ObjectDelete("t32");ObjectDelete("t33");ObjectDelete("t34");
    ObjectDelete("t35");ObjectDelete("t36");
   
 
   ct("t34",10,右坐标+50,3);
   ct("t35",10,右坐标+25,3);
   ct("t27",10,右坐标,3);
   ct("t29",10,右坐标-25,3);
   ct("t30",10,右坐标-50,3);
   ct("t31",10,右坐标-75,3);
   ct("t32",10,右坐标-100,3);
   ct("t33",10,右坐标-125,3);

ObjectSetText( "t31","本月盈利"+DoubleToStr(orderprofits,2)+"美元", 盈利比字大小, "Arial", White);
ObjectSetText( "t32","比例"+DoubleToStr(ylz,2)+"%", 盈利比字大小, "Arial", kla);
ObjectSetText( "t33","月目标:"+月目标盈利+"%", 盈利比字大小, "Arial", Magenta);
ObjectSetText( "t30","周目标:"+周目标盈利+"%",盈利比字大小, "Arial", Magenta);

ObjectSetText( "t34","当日盈利"+DoubleToStr(orderprofitsd,2)+"美元",盈利比字大小, "Arial", White);
ObjectSetText( "t35","比例"+DoubleToStr(yld,2)+"%", 盈利比字大小, "Arial", kld);


ObjectSetText( "t27","本周盈利"+DoubleToStr(orderprofitsy,2)+"美元", 盈利比字大小, "Arial", White);
ObjectSetText( "t29","比例"+DoubleToStr(yla,2)+"%", 盈利比字大小, "Arial", kay);

   return(0);
  }
     int ct( string Text, int xOffset, int yOffset,int iCorner) //TITLE
{  ObjectCreate(Text,OBJ_LABEL         , 0, 0, 0 );
   ObjectSet   (Text,OBJPROP_CORNER    , iCorner);
   ObjectSet   (Text,OBJPROP_XDISTANCE , xOffset);
   ObjectSet   (Text,OBJPROP_YDISTANCE , yOffset );
   ObjectSet   (Text,OBJPROP_BACK      , True );
      return(0);
   }

如您喜欢此文章请点下面分享按钮↴峰汇在线 » MT4统计账号日月周交易情况的脚本
上一篇:
下一篇:
分享到:更多 ()