Download MetaTrader 5
To add comments, please log in or register
Launch your trading signal and add account monitoring!
murger
82
murger 2014.02.19 20:48 

Hi companions in misfortune,

Why do you think about an indic that wouldn't run anymore when you re-start the plaform until you recompile it ?

This indic built under MT4 use simple init(), deinit(), start) & some includes .

All of these files are correctly placed in the new rooming V610 Folder.

Thanks

D



Ubzen
Moderator
5394
Ubzen 2014.02.19 21:10  
DanielTahiti:

Hi companions in misfortune,

Why do you think about an indic that wouldn't run anymore when you re-start the plaform until you recompile it ?

This indic built under MT4 use simple init(), deinit(), start) & some includes .

All of these files are correctly placed in the new rooming V610 Folder.

Try using some print statements to debug.

Please show the parts of the code you're having problems with.

You might be having global variable || initialization issues.

murger
82
murger 2014.02.20 08:55  

ok, thanks, so the functions concerned are in an include A which receive itself another include B.


This include B serves on the same time to an EA, and to an indicator wich is on the same graph. The indicator is like a "vigile" of the good running of the EA .


- At the Head scope of the indicator :

#include <@X_VigileFonctions.mqh>


- the Function called in the Init, and then each new minutes is

if(avb_ShowFinance) {SHOWFINANCE();}


- The include A :

//>>>>>>>>>>>>>>>>>>>>>>
// @W_AnnexVigil.mqh>
//>>>>>>>>>>>>>>>>>>>>>>

static string    IncWExpertName      = "Xoid Include Indicateur  " ;

#include <@V_GvManaging.mqh>


//II-@Xoidi-FXMarketGmtHour---Preprocessor.
#import "kernel32.dll"
int GetTimeZoneInformation(int& a0[]);
#import

// VARIABLES DES INDICATEURS ANNEXES INSERES .
//.
//I-@Xoidi-PROFITTRACKER--Variables-                                     
//+--------------------------------------------------------------------------------------
//|                         Options positions                                
//+--------------------------------------------------------------------------------------
 int   eiOffsetY = 27;                 // (Y) Offset text vertically
 int   eiStepY   = 14;                 // (Y) Step displacements of the text vertically
 int   eiX1Row   = 190;                // (X) Coordinate of the first column
 int   eiX2Row   = 145;                // (X) Coordinate of the second column
 int   eiX3Row   =  78;                // (X) Coordinate third column
 int   eiX4Row   =  10;                // (X) Coordinate of the fourth column
//+--------------------------------------------------------------------------------------
//|                          Color Settings                                  
//+--------------------------------------------------------------------------------------
 color ecText    = White;              // Text Color
 color ecProfit  = Lime;               // Color profit
 color ecLoss    = Red;                // Color loss
//+--------------------------------------------------------------------------------------
//<\_END I-@Xoidi-PROFITTRACKER--Variables___________________________________________________________________________________________________________
//.
//>I-@Xoidi-Profittracker--FUNCTIONS
//+--------------------------------------------------------------------------------------
  color    ColorOnSign(double nu) {
  color    lcColor=ecText;
  if       (nu==0 ||nu>0 ) lcColor=ecProfit;
  if       (nu<0) lcColor=ecLoss;
  return   (lcColor);
  }
//+--------------------------------------------------------------------------------------
  datetime DateBeginQuarter(int nk=0) 
      {
      int      ye=Year()-MathFloor(nk/4); 
               nk=MathMod(nk, 4); 
      int      mo=Month()-MathMod(Month()+2, 3)+3*nk;
      if       (mo<1)  { mo+=12;  ye--; }
      if       (mo>12) {mo-=12 ;  ye++; }
      //Alert("W_annexVig",sp,ye,sp,ye+"."+mo+".01");
  return  (StrToTime(ye+"."+mo+".01"));
      }
//+--------------------------------------------------------------------------------------
  datetime DateOfMonday(int no=0) {
  datetime dt=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));
  if       (TimeDayOfWeek(dt)!=1) dt-=24*60*60;
           dt+=no*7*24*60*60;
           //Alert("W_annexVig",sp,"Date du lundi",sp,TimeToStr(dt));
  return   (dt);
  }
//+--------------------------------------------------------------------------------------
  void     DELPROFITRACKER() 
  {
  string   st="iProfit";
  int      i, j;
  for      (i=0; i<=10; i++) 
     {
    for    (j=1; j<=15; j++) 
        {   
        
        if(ObjectFind(st+i+j)>-1)      {ObjectDelete(st+i+j); }
        }
     }
   }     
//+--------------------------------------------------------------------------------------
  double GetProfitFromDateInCurrency(string sy="", int op=-1, int mn=-1, datetime dt=0)
  {
  double p=0;
  int    i, k=OrdersHistoryTotal();
  if     (sy=="0" ) sy=Symbol();
  for    (i=0; i<k; i++) {
  if     (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
  if     ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
  if     (OrderType()==OP_BUY || OrderType()==OP_SELL) {
  if     (mn<0 || OrderMagicNumber()==mn) {
  if     (dt<OrderCloseTime()) {
         p+=OrderProfit()+OrderCommission()+OrderSwap();
         
  } } } } } }
  return (p);
  }
//+--------------------------------------------------------------------------------------
  double GetProfitFromDateInPoint(string sy="", int op=-1, int mn=-1, datetime dt=0)
  {
  double p=0, po;
  int    i, k=OrdersHistoryTotal();
  if     (sy=="0") sy=Symbol();
  for    (i=0; i<k; i++) {
  if     (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
  if     ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
  if     (OrderType()==OP_BUY || OrderType()==OP_SELL) {
  if     (mn<0 || OrderMagicNumber()==mn) {
  if     (dt<OrderCloseTime()) {
         po=MarketInfo(OrderSymbol(), MODE_POINT);
         
  //if     (po==0) if (StringFind(sy, "jpy")<0) po=0.00001; else po=0.001;//zzz
  if     (OrderType()==OP_BUY) {
         p+=(OrderClosePrice()-OrderOpenPrice())/po;
  }
  if     (OrderType()==OP_SELL) {
         p+=(OrderOpenPrice()-OrderClosePrice())/po;
                
  } } } } } } }
  return (p);
  }
//+--------------------------------------------------------------------------------------
  int    GetProfitOpenPosInPoint(string sy="", int op=-1, int mn=-1) {
  double p;
  int    i, k=OrdersTotal(), pr=0;

  if     (sy=="0") sy=Symbol();
  for    (i=0; i<k; i++) {
  if     (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
  if     ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
  if     (mn<0 || OrderMagicNumber()==mn) {
         p=MarketInfo(OrderSymbol(), MODE_POINT);
  //if     (p==0) if (StringFind(OrderSymbol(), "jpy")<0) p=0.00001; else p=0.001;//zzz
  if     (OrderType()==OP_BUY) {
         pr+=(MarketInfo(OrderSymbol(), MODE_BID)-OrderOpenPrice())/p;
  }
  if (OrderType()==OP_SELL) {
         pr+=(OrderOpenPrice()-MarketInfo(OrderSymbol(), MODE_ASK))/p;
  } } } } }
  return (pr);
  }
//+--------------------------------------------------------------------------------------
//| cr - room corner bindings - (0 - upper left)                             
//| fs - font size - (9 - default)                                           
//+----------------------------------------------------------------------------------------------------------
  void SetLabel(string nm, string tx, color cl, int xd, int yd, int cr=3,string fnt="Arial Bold", int fs=10)
  //void SetLabel(string nm, string tx, color cl, int xd, int yd, int cr=3, int fs=10)
  {
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_LABEL, 0, 0,0);
  ObjectSetText(nm, tx, fs);
  ObjectSet    (nm, OBJPROP_COLOR    , cl);
  ObjectSet    (nm, OBJPROP_XDISTANCE, xd);
  ObjectSet    (nm, OBJPROP_YDISTANCE, yd);
  ObjectSet    (nm, OBJPROP_CORNER   , cr);
  ObjectSet    (nm, OBJPROP_STYLE , fs);

  }
//+----------------------------------------------------------------------------------------------------------
//.
//<\END SHOWFINANCE()__FUNCTIONS_____________________________________________________________________________________________________________________

void SHOWFINANCE()
{
//I-@Xoidi-Profittracker--START()
//+----------------------------------------------------------------------------------------------------------
//| Custom indicator iteration function                                      
//+----------------------------------------------------------------------------------------------------------
  static double    tb,tp;
  datetime d9,d0, d1, d2, d3, d4, d5, d6, d7, d8;
//+----------------------------------------------------------------------------------------------------------//I-@Xoidi-Profittracker
           d0=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));
  while    (TimeDayOfWeek(d0)<1 || TimeDayOfWeek(d0)>5) d0-=24*60*60;
           d1=d0-24*60*60;
  while    (TimeDayOfWeek(d1)<1 || TimeDayOfWeek(d1)>5) d1-=24*60*60;
           d2=d1-24*60*60;
  while    (TimeDayOfWeek(d2)<1 || TimeDayOfWeek(d2)>5) d2-=24*60*60;
           d3=d2-24*60*60;
  while    (TimeDayOfWeek(d3)<1 || TimeDayOfWeek(d3)>5) d3-=24*60*60;
           d4=d3-24*60*60;
  while    (TimeDayOfWeek(d4)<1 || TimeDayOfWeek(d4)>5) d4-=24*60*60;
           d5=DateOfMonday();
           d6=StrToTime(Year()+"."+Month()+".01");
           d7=DateBeginQuarter();
           d8=StrToTime(Year()+".01.01");
           d9=StrToTime((Year()-1)+".01.01"); //1 janvier année précédente
//+----------------------------------------------------------------------------------------------------------
  double   tu=GetProfitOpenPosInPoint     ();
  double   u0=GetProfitFromDateInPoint    ("", -1, -1, d0);
  double   u1=GetProfitFromDateInPoint    ("", -1, -1, d1)-u0;
  double   u2=GetProfitFromDateInPoint    ("", -1, -1, d2)-u1-u0;
  double   u3=GetProfitFromDateInPoint    ("", -1, -1, d3)-u2-u1-u0;
  double   u4=GetProfitFromDateInPoint    ("", -1, -1, d4)-u3-u2-u1-u0;
  double   u5=GetProfitFromDateInPoint    ("", -1, -1, d5);
  double   u6=GetProfitFromDateInPoint    ("", -1, -1, d6);
  double   u7=GetProfitFromDateInPoint    ("", -1, -1, d7);
  double   u8=GetProfitFromDateInPoint    ("", -1, -1, d8);
  
//+----------------------------------------------------------------------------------------------------------
  tb=AccountBalance();           tp=AccountProfit();      
  double   p0=GetProfitFromDateInCurrency ("", -1, -1, d0);
  double   p1=GetProfitFromDateInCurrency ("", -1, -1, d1)-p0;
  double   p2=GetProfitFromDateInCurrency ("", -1, -1, d2)-p1-p0;
  double   p3=GetProfitFromDateInCurrency ("", -1, -1, d3)-p2-p1-p0;
  double   p4=GetProfitFromDateInCurrency ("", -1, -1, d4)-p3-p2-p1-p0;
  double   p5=GetProfitFromDateInCurrency ("", -1, -1, d5);
  double   p6=GetProfitFromDateInCurrency ("", -1, -1, d6);
  double   p7=GetProfitFromDateInCurrency ("", -1, -1, d7);
  double   p8=GetProfitFromDateInCurrency ("", -1, -1, d8);
  double   p9=GetProfitFromDateInCurrency ("", -1, -1, d9)-p8; 
//+----------------------------------------------------------------------------------------------------------
  string               st;
  switch                                  (BasePerPercent) {
    case 0 :           st="current";                         break;
    case 1 : tb-=p0;   st="at the beginning of the day";     break;
    case 2 : tb-=p5;   st="at the beginning of the week";    break;
    case 3 : tb-=p6;   st="at the beginning of the month";   break;
    case 4 : tb-=p7;   st="at the beginning of the quarter"; break;
    default: tb-=p8;   st="at beginning of year";            break;
  }
  if(GlobalVariableGet(gv1stCapital)>0) {double ti=GlobalVariableGet(gv1stCapital);}else{ti=tb-p8;}   
  double     tr=tp*100/tb; 
  double     r0=p0*100/tb;
  double     r1=p1*100/tb;
  double     r2=p2*100/tb;
  double     r3=p3*100/tb;
  double     r4=p4*100/tb;
  double     r5=p5*100/tb;
  double     r6=p6*100/tb;
  double     r7=p7*100/tb;
  double     r8=p8*100/ti;
  double     r9=p9*100/ti;

//+----------------------------------------------------------------------------------------------------------//I-@Xoidi-Profittracker
//|                                   Title                                  
//+----------------------------------------------------------------------------------------------------------
  SetLabel ("iProfit105",  "Synthèse Financière",                  ecText, eiX4Row+50,eiOffsetY+14*eiStepY);
//+----------------------------------------------------------------------------------------------------------
//|                                  separator                               
//+----------------------------------------------------------------------------------------------------------
  SetLabel ("iProfit109", "____________________________________",  ecText, eiX4Row-1,eiOffsetY+15.5*eiStepY);
//+----------------------------------------------------------------------------------------------------------   
//+----------------------------------------------------------------------------------------------------------
//|                                   HEADERS                                
//+----------------------------------------------------------------------------------------------------------
  SetLabel ("iProfit05", "Date ",                                  ecText, eiX1Row+30,eiOffsetY);
  SetLabel ("iProfit06", "Pips",                                   ecText, eiX2Row-2, eiOffsetY);
  SetLabel ("iProfit07", "Valeur",                                 ecText, eiX3Row-2, eiOffsetY);
  SetLabel ("iProfit08", "  %  ",                                  ecText, eiX3Row-60,eiOffsetY);
//+----------------------------------------------------------------------------------------------------------
//|                                  separator                               
//+----------------------------------------------------------------------------------------------------------
  SetLabel ("iProfit09", "____________________________________",   ecText, eiX4Row-1,eiOffsetY+1.5*eiStepY);
//+----------------------------------------------------------------------------------------------------------
//|                                   position                              
//+----------------------------------------------------------------------------------------------------------
  SetLabel ("iProfit11", "Courant       ",                         ecText, eiX1Row,   eiOffsetY+2*eiStepY);
  SetLabel ("iProfit21", "Ce jour        ",                        ecText, eiX1Row,   eiOffsetY+3*eiStepY);
  SetLabel ("iProfit31", ""+TimeToStr(d1, TIME_DATE)+"  ",         ecText, eiX1Row,   eiOffsetY+4*eiStepY);
  SetLabel ("iProfit41", ""+TimeToStr(d2, TIME_DATE)+"  ",         ecText, eiX1Row,   eiOffsetY+5*eiStepY);
  SetLabel ("iProfit51", ""+TimeToStr(d3, TIME_DATE)+"  ",         ecText, eiX1Row,   eiOffsetY+6*eiStepY);
  SetLabel ("iProfit61", ""+TimeToStr(d4, TIME_DATE)+"  ",         ecText, eiX1Row,   eiOffsetY+7*eiStepY);
  SetLabel ("iProfit71", "Semaine   ",                             ecText, eiX1Row,   eiOffsetY+8*eiStepY);
  SetLabel ("iProfit81", "Mois           ",                        ecText, eiX1Row,   eiOffsetY+9*eiStepY);
  SetLabel ("iProfit91", "Trimestre   ",                           ecText, eiX1Row,   eiOffsetY+10*eiStepY);
  SetLabel ("iProfit01", "Année         ",                         ecText, eiX1Row,   eiOffsetY+11*eiStepY);
  SetLabel ("iProfit011","An (-1)         ",                       ecText, eiX1Row,   eiOffsetY+12*eiStepY);
//+----------------------------------------------------------------------------------------------------------
//|                                     POINTS                              
//+----------------------------------------------------------------------------------------------------------
  SetLabel ("iProfit12", DoubleToStr (tu, 0),      ColorOnSign(tp), eiX2Row,   eiOffsetY+2*eiStepY);
  SetLabel ("iProfit22", DoubleToStr (u0, 0),      ColorOnSign(u0), eiX2Row,   eiOffsetY+3*eiStepY);
  SetLabel ("iProfit32", DoubleToStr (u1, 0),      ColorOnSign(u1), eiX2Row,   eiOffsetY+4*eiStepY);
  SetLabel ("iProfit42", DoubleToStr (u2, 0),      ColorOnSign(u2), eiX2Row,   eiOffsetY+5*eiStepY);
  SetLabel ("iProfit52", DoubleToStr (u3, 0),      ColorOnSign(u3), eiX2Row,   eiOffsetY+6*eiStepY);
  SetLabel ("iProfit62", DoubleToStr (u4, 0),      ColorOnSign(u4), eiX2Row,   eiOffsetY+7*eiStepY);
  SetLabel ("iProfit72", DoubleToStr (u5, 0),      ColorOnSign(u5), eiX2Row,   eiOffsetY+8*eiStepY);
  SetLabel ("iProfit82", DoubleToStr (u6, 0),      ColorOnSign(u6), eiX2Row,   eiOffsetY+9*eiStepY);
  SetLabel ("iProfit92", DoubleToStr (u7, 0),      ColorOnSign(u7), eiX2Row,   eiOffsetY+10*eiStepY);
  SetLabel ("iProfit02", DoubleToStr (u8, 0),      ColorOnSign(u8), eiX2Row,   eiOffsetY+11*eiStepY);
  
//+----------------------------------------------------------------------------------------------------------
//|                                      MONEY                               
//+----------------------------------------------------------------------------------------------------------
  SetLabel ("iProfit13", DoubleToStr (tp, 1),      ColorOnSign(tp), eiX3Row,   eiOffsetY+2*eiStepY);
  SetLabel ("iProfit23", DoubleToStr (p0, 0),      ColorOnSign(p0), eiX3Row,   eiOffsetY+3*eiStepY);
  SetLabel ("iProfit33", DoubleToStr (p1, 0),      ColorOnSign(p1), eiX3Row,   eiOffsetY+4*eiStepY);
  SetLabel ("iProfit43", DoubleToStr (p2, 0),      ColorOnSign(p2), eiX3Row,   eiOffsetY+5*eiStepY);
  SetLabel ("iProfit53", DoubleToStr (p3, 0),      ColorOnSign(p3), eiX3Row,   eiOffsetY+6*eiStepY);
  SetLabel ("iProfit63", DoubleToStr (p4, 0),      ColorOnSign(p4), eiX3Row,   eiOffsetY+7*eiStepY);
  SetLabel ("iProfit73", DoubleToStr (p5, 0),      ColorOnSign(p5), eiX3Row,   eiOffsetY+8*eiStepY);
  SetLabel ("iProfit83", DoubleToStr (p6, 0),      ColorOnSign(p6), eiX3Row,   eiOffsetY+9*eiStepY);
  SetLabel ("iProfit93", DoubleToStr (p7, 0),      ColorOnSign(p7), eiX3Row,   eiOffsetY+10*eiStepY);
  SetLabel ("iProfit03", DoubleToStr (p8, 0),      ColorOnSign(p8), eiX3Row,   eiOffsetY+11*eiStepY);
  SetLabel ("iProfit013", DoubleToStr(p9, 0),      ColorOnSign(p9), eiX3Row,   eiOffsetY+12*eiStepY);
//+----------------------------------------------------------------------------------------------------------
//|                                     Pourcentage                             
//+----------------------------------------------------------------------------------------------------------
  SetLabel ("iProfit14", DoubleToStr (tr, 1)+"  %", ColorOnSign(tr), eiX4Row,   eiOffsetY+2*eiStepY);
  SetLabel ("iProfit24", DoubleToStr (r0, 1)+"  %", ColorOnSign(r0), eiX4Row,   eiOffsetY+3*eiStepY);
  SetLabel ("iProfit34", DoubleToStr (r1, 1)+"  %", ColorOnSign(r1), eiX4Row,   eiOffsetY+4*eiStepY);
  SetLabel ("iProfit44", DoubleToStr (r2, 1)+"  %", ColorOnSign(r2), eiX4Row,   eiOffsetY+5*eiStepY);
  SetLabel ("iProfit54", DoubleToStr (r3, 1)+"  %", ColorOnSign(r3), eiX4Row,   eiOffsetY+6*eiStepY);
  SetLabel ("iProfit64", DoubleToStr (r4, 1)+"  %", ColorOnSign(r4), eiX4Row,   eiOffsetY+7*eiStepY);
  SetLabel ("iProfit74", DoubleToStr (r5, 1)+"  %", ColorOnSign(r5), eiX4Row,   eiOffsetY+8*eiStepY);
  SetLabel ("iProfit84", DoubleToStr (r6, 1)+"  %", ColorOnSign(r6), eiX4Row,   eiOffsetY+9*eiStepY);
  SetLabel ("iProfit94", DoubleToStr (r7, 1)+"  %", ColorOnSign(r7), eiX4Row,   eiOffsetY+10*eiStepY);
  SetLabel ("iProfit04", DoubleToStr (r8, 1)+"  %", ColorOnSign(r8), eiX4Row,   eiOffsetY+11*eiStepY);
  SetLabel ("iProfit014",DoubleToStr (r9, 1)+"  %", ColorOnSign(r9), eiX4Row,   eiOffsetY+12*eiStepY);
//+----------------------------------------------------------------------------------------------------------
//|                                  separator                                
//+----------------------------------------------------------------------------------------------------------
  SetLabel ("iProfit15", "____________________________________",ecText, eiX4Row-1,eiOffsetY+13.5*eiStepY);
}

//.
//<\END //<SHOWFINANCE()I-@Xoidi-Profittracker_______________________________________________________________________________________________________

//<\END I-@Xoidi-Profittracker--FUNCTION---__________________________________________________________________________________________________________


To finish, all the include are in the folder...//Rooming/.../include/*.* . I mean that the include for indicator are not in the under-folder name "/include/indicator" but directly in the folder /include.


at the open of the console

Then recompile Indic :

Indic recompile




murger
82
murger 2014.02.25 02:42  

Finaly I've find ...

Certainly the way of variables globales are updated is different, and so, there is a mistake in the code.

The mistake is about a divide .

When you divide with a variable, code for the case if the variable is =0 we have to think about an escape door to let the expert make and other round until the variable will not be egal to zero...

if not, code is stopped.. ( here nearly at the end / tb and /ti..)

I have copy-paste and insert this code as it was offered and...so it is my fault.. haha. so now :

 if(tb==0 || ti==0) {return;}
  else
  { 
  double     tr=tp*100/tb; 
  double     r0=p0*100/tb;
  double     r1=p1*100/tb;
  double     r2=p2*100/tb;
  double     r3=p3*100/tb;
  double     r4=p4*100/tb;
  double     r5=p5*100/tb;
  double     r6=p6*100/tb;
  double     r7=p7*100/tb;
  double     r8=p8*100/ti;
  double     r9=p9*100/ti;
  }


So the problem is over now.

D

/
To add comments, please log in or register