global initialization failed!!!!!!! - page 4

 
deysmacro:

You don't put any object find function to check if the object already exist or not. From there, then you create the object accordingly.


I am helping you, right now.


Now, that's a good hint, to do cleanup OnInit(), thanks.

Not that it really solves any of the above problems, you know.

The labels still don't lock into position.

After all the things I've done, it's better, but still not perfect.

I think the issue is much deeper and has smth to do with data not being cleanedup.

As if somehow MT4 retrieved some old data from some uncleaned registers.

 

I am sorry if I just giving you hints because the ultimate in coding is the one who actually do the coding.

Unfortunately, many don't understands/pick up the hint given.

 
qjol:



1. Labels are getting out of line, as if the XDISTANCE and YDISTANCE weren't obeyed.

They get back in-line only after switching Tf's back and forth.

After switching chart windows or changing parameters input, they get out of line.

that means you can fix it in your code

I have done a lot, nothing helps.

It gets better, but still, ie. after changing smth in parametrs, not the X,Y, the label gets way out of line!

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double StopLoss    = 30;
extern double RiskPercent = 3;
extern int Corner = 3;
extern int Font_Size = 13;
extern string Font_Type = "Berlin Sans FB";
extern color Font_Color = clrSnow;
extern color Warning_Color = clrRed;
extern int XDistance = 9;
extern int YDistance = 27;
string  comment;
int X,Y;


int OnInit()   {   
 X = XDistance;
 Y = YDistance;
if(ObjectFind("Lot_Size_Label")==0)
 {
 ObjectDelete("Lot_Size_Label");
 }
ObjectCreate("Lot_Size_Label", OBJ_LABEL, 0, 0,0); return(0); 
  }

//-------------------------------------------------------------+
  
int OnDeinit(int reason) 
  {
  ObjectDelete("Lot_Size_Label"); 
  return(0); 
  }

//-------------------------------------------------------------+
int start()  
{
      string AcctCurrency = AccountCurrency();
       
      if (AcctCurrency == "")
          return(0);
 X = XDistance;
 Y = YDistance;
           
   double pipValue = MarketInfo(Symbol(),MODE_TICKVALUE); 
   if (Digits==3 || Digits==5) pipValue *= 10;
   double step     = MarketInfo(Symbol(),MODE_LOTSTEP);
      int norm     = 0;
            if (step==1)    norm = 0;
            if (step==0.1)  norm = 1;
            if (step==0.01) norm = 2;
   double minLot = MarketInfo(Symbol(),MODE_MINLOT);
   double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);
   if(pipValue!=0)
    {
   double lots   = AccountBalance()*(RiskPercent/100.0)/(StopLoss*pipValue);
    }
         lots   = NormalizeDouble(lots,norm);
          
         comment = "SL("+DoubleToStr(RiskPercent,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(lots,norm)+" Lot";
          
          double actualRisk,maxRiskSL; 
          if (lots<minLot)
            {
               actualRisk = (100*minLot*StopLoss*pipValue)/AccountBalance();
               if(RiskPercent<=0) RiskPercent=1;
               maxRiskSL = StopLoss/(actualRisk/RiskPercent);
               comment = "SL("+DoubleToStr(actualRisk,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(minLot,norm)+" Lot"+"  SL("+IntegerToString(RiskPercent,0)+"%): "+IntegerToString(maxRiskSL,0)+" Pts";
               Font_Color=Warning_Color;
            }
  ObjectSet    ("Lot_Size_Label",OBJPROP_CORNER,Corner);

  ObjectSet    ("Lot_Size_Label",OBJPROP_XDISTANCE,X);
  ObjectSet    ("Lot_Size_Label",OBJPROP_YDISTANCE,Y);
  ObjectSetText("Lot_Size_Label",comment,Font_Size,Font_Type,Font_Color);
  ObjectSet    ("Lot_Size_Label",OBJPROP_SELECTABLE,false); 
 
   return(0);
}

Anything wrong with the code?



 
Dadas:


Anything wrong with the code?


you have been told already, forget about

int start()  

start using the new methods

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

daysmacro already written above

i dont see ObjectFind()

if (ObjectFind(....) == xxx, or != yyy ...)
   {
   ObjectSet    ("Lot_Size_Label",OBJPROP_CORNER,Corner);
   
   ObjectSet    ("Lot_Size_Label",OBJPROP_XDISTANCE,X);
   ObjectSet    ("Lot_Size_Label",OBJPROP_YDISTANCE,Y);
   ObjectSetText("Lot_Size_Label",comment,Font_Size,Font_Type,Font_Color);
   ObjectSet    ("Lot_Size_Label",OBJPROP_SELECTABLE,false); 
   }
else
   {
   do something maybe GetLastError() ??
   }
 
qjol:

you have been told already, forget about

start using the new methods

daysmacro already written above

i dont see ObjectFind()



So, I did:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double StopLoss    = 30;
extern double RiskPercent = 3;
extern int Corner = 3;
extern int Font_Size = 13;
extern string Font_Type = "Berlin Sans FB";
extern color Font_Color = clrSnow;
extern color Warning_Color = clrRed;
extern int XDistance = 9;
extern int YDistance = 27;
string  comment;
int X,Y;
//
//
//
//
//

int OnInit()   {   
 X = XDistance;
 Y = YDistance;
if(ObjectFind("Lot_Size_Label")==0)
 {
 ObjectDelete("Lot_Size_Label");
 }
ObjectCreate("Lot_Size_Label", OBJ_LABEL, 0, 0,0); 

  return(INIT_SUCCEEDED); 
  }
  
void OnDeinit(const int reason) 
  {
  ObjectDelete("Lot_Size_Label"); 
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
 {                
      string AcctCurrency = AccountCurrency();
       
      if (AcctCurrency == "")
          return(rates_total);
          
 X = XDistance;
 Y = YDistance;
           
   double pipValue = MarketInfo(Symbol(),MODE_TICKVALUE); 
   if (Digits==3 || Digits==5) pipValue *= 10;
   double step     = MarketInfo(Symbol(),MODE_LOTSTEP);
      int norm     = 0;
            if (step==1)    norm = 0;
            if (step==0.1)  norm = 1;
            if (step==0.01) norm = 2;
   double minLot = MarketInfo(Symbol(),MODE_MINLOT);
   double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);
   if(pipValue!=0)
    {
   double lots   = AccountBalance()*(RiskPercent/100.0)/(StopLoss*pipValue);
    }
         lots   = NormalizeDouble(lots,norm);
          
          //
          //
          //
          //
          //
          comment = "SL("+DoubleToStr(RiskPercent,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(lots,norm)+" Lot";
          
          double actualRisk,maxRiskSL; 
          if (lots<minLot)
            {
               actualRisk = (100*minLot*StopLoss*pipValue)/AccountBalance();
               if(RiskPercent<=0) RiskPercent=1;
               maxRiskSL = StopLoss/(actualRisk/RiskPercent);
               comment = "SL("+DoubleToStr(actualRisk,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(minLot,norm)+" Lot"+"  SL("+IntegerToString(RiskPercent,0)+"%): "+IntegerToString(maxRiskSL,0)+" Pts";
               Font_Color=Warning_Color;
            }
  ObjectSet    ("Lot_Size_Label",OBJPROP_CORNER,Corner);

  ObjectSet    ("Lot_Size_Label",OBJPROP_XDISTANCE,X);
  ObjectSet    ("Lot_Size_Label",OBJPROP_YDISTANCE,Y);
  ObjectSetText("Lot_Size_Label",comment,Font_Size,Font_Type,Font_Color);
  ObjectSet    ("Lot_Size_Label",OBJPROP_SELECTABLE,false);  
   return(rates_total);
}

Still, same effect. This changed nothing as far as label positioning.

ObjectFind() is in OnInit() checking if the object is there and deleting it if it is.

Label on indi intitialization is where it is supposed to be.

After changing some parameter, it disappears to the right.

Jumps back into place only after Tf shifting.

 
Actually you just need something like a first object set when first loading and then second object set after loading (the dust settles). I also got the same problem where as doing like I said solve the problem. It is more like a workaround but all good enough for me.
 
deysmacro:
Actually you just need something like a first object set when first loading and then second object set after loading (the dust settles). I also got the same problem where as doing like I said solve the problem. It is more like a workaround but all good enough for me.

So, I did like this, even rechecking the X,Y coords to resest the label in case the coords are different.

No juice, nothing changes at all, it behaves just as above.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double StopLoss    = 30;
extern double RiskPercent = 3;
extern int Corner = 3;
extern int Font_Size = 13;
extern string Font_Type = "Berlin Sans FB";
extern color Font_Color = clrSnow;
extern color Warning_Color = clrRed;
extern int XDistance = 9;
extern int YDistance = 27;
string  comment;
int X,Y;
//
//
//
//
//

int OnInit()   {   
 X = XDistance;
 Y = YDistance;
if(ObjectFind("Lot_Size_Label")==0)
 {
 ObjectDelete("Lot_Size_Label");
 }
  ObjectCreate("Lot_Size_Label", OBJ_LABEL, 0, 0,0); 
  ObjectSet    ("Lot_Size_Label",OBJPROP_CORNER,Corner);
  ObjectSet    ("Lot_Size_Label",OBJPROP_XDISTANCE,X);
  ObjectSet    ("Lot_Size_Label",OBJPROP_YDISTANCE,Y);
  ObjectSet    ("Lot_Size_Label",OBJPROP_SELECTABLE,false);    
  
  return(INIT_SUCCEEDED); 
  }
  
void OnDeinit(const int reason) 
  {
  ObjectDelete("Lot_Size_Label"); 
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
 {                
      string AcctCurrency = AccountCurrency();
       
      if (AcctCurrency == "")
          return(rates_total);
          
 X = XDistance;
 Y = YDistance;
           
   double pipValue = MarketInfo(Symbol(),MODE_TICKVALUE); 
   if (Digits==3 || Digits==5) pipValue *= 10;
   double step     = MarketInfo(Symbol(),MODE_LOTSTEP);
      int norm     = 0;
            if (step==1)    norm = 0;
            if (step==0.1)  norm = 1;
            if (step==0.01) norm = 2;
   double minLot = MarketInfo(Symbol(),MODE_MINLOT);
   double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);
   if(pipValue!=0)
    {
   double lots   = AccountBalance()*(RiskPercent/100.0)/(StopLoss*pipValue);
    }
         lots   = NormalizeDouble(lots,norm);
          
          //
          //
          //
          //
          //
          comment = "SL("+DoubleToStr(RiskPercent,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(lots,norm)+" Lot";
          
          double actualRisk,maxRiskSL; 
          if (lots<minLot)
            {
               actualRisk = (100*minLot*StopLoss*pipValue)/AccountBalance();
               if(RiskPercent<=0) RiskPercent=1;
               maxRiskSL = StopLoss/(actualRisk/RiskPercent);
               comment = "SL("+DoubleToStr(actualRisk,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(minLot,norm)+" Lot"+"  SL("+IntegerToString(RiskPercent,0)+"%): "+IntegerToString(maxRiskSL,0)+" Pts";
               Font_Color=Warning_Color;
            }
            
  if(ObjectFind("Lot_Size_Label")==0)
   {         
  int x_check=ObjectGet("Lot_Size_Label",OBJPROP_XDISTANCE);
  int y_check=ObjectGet("Lot_Size_Label",OBJPROP_YDISTANCE);  
   }  

  if(X!=x_check||Y!=y_check)
   {            
  ObjectSet    ("Lot_Size_Label",OBJPROP_CORNER,Corner);
  ObjectSet    ("Lot_Size_Label",OBJPROP_XDISTANCE,X);
  ObjectSet    ("Lot_Size_Label",OBJPROP_YDISTANCE,Y);
  ObjectSetText("Lot_Size_Label",comment,Font_Size,Font_Type,Font_Color);
  ObjectSet    ("Lot_Size_Label",OBJPROP_SELECTABLE,false);  
   }
   return(rates_total);
}
PS. this didn't happen in B625, only started with B646 update.

	          
 
So, is it done yet ?
 

And, the funny thing is, using Comment(), the coords never change, even when the label goes right.

Thus, the problem remains, it is not done.

 
Comment() doesn't effect chart, most of the time.
Reason: