global initialization failed!!!!!!! - page 5

To add comments, please log in or register
Dadas
260
Dadas  
deysmacro:
Comment() doesn't effect chart, most of the time.

  if(ObjectFind(Symbol()+"Lot_Size_Label")==0)
   {         
  int x_check=ObjectGet(Symbol()+"Lot_Size_Label",OBJPROP_XDISTANCE);
  int y_check=ObjectGet(Symbol()+"Lot_Size_Label",OBJPROP_YDISTANCE);
  Comment(x_check+ " , "+y_check); 
   }

Comment() to check what the coords data are.

They should change when label goes right, but they don't.

IOW, coords are what they should be.

Label disappears to the right.

Dadas
260
Dadas  

Coord are XDISTANCE = 225; YDISTANCE = 27; CORNER = 3;

First, loading the indi on the chart, label in place:

Second, closing MT4 and restarting it, label goes right:

Third, after shifting Tf's, label jumps back:

It's something to do with the Anchors related to Corner calculations and must be a bug in B646.

Ian Venner
2397
Ian Venner  
What does any of that have to do with global initialization failed ?
Dadas
260
Dadas  
SDC:
What does any of that have to do with global initialization failed ?

That B646 is seriously bugged!
Jeffrey Irick
339
Jeffrey Irick  
Dadas:


Thanks, I had the same issue with the objects not being deleted on deinit.

I was developing some indi, and got these strange results, then I saw on the objects list, they were still there.

I got around that, probably in the simplest way, by ObjectDelete() in the start().

Yup, changing init() to OnInit() and deinit() to OnDeinit() got the labels back right! Thanks!

Then after a while, it didn't!!! They are still doing the same dance.


You're welcome, Dadas. I wouldn't use ObjectDelete() in the start method, though. That's best done in OnDeInit(). The reason for that is this: if you put the code in OnStart() or OnCalculate() it's going to be executed every time a tick comes. That's bad for two reasons: 1) it adds a lot of operations using up time that you can't afford to waste in a real-time application and 2) it doesn't make sense to do that in most situations - usually it's only going to matter when a chart is de-initialized. You should only do it in the "startup" methods if a price change will affect your objects in some way. As an example, consider this(which is part of an app that I intend to sell, but sharing this is cool :-) ).

// If no trade is progress, there is no Position Value to display
      if (ObjectFind("PositionValue") > 0)
                ObjectDelete("PositionValue");
                
      if (ObjectFind("PipsProfitLoss") > 0)
                ObjectDelete("PipsProfitLoss");
                
      if (ObjectFind("CurrentStop") > 0)
                ObjectDelete("CurrentStop");
                
      if (ObjectFind("PipsLockedIn") > 0)
                ObjectDelete("PipsLockedIn");
                
      if (ObjectFind("ProfitLockedIn") > 0)
                ObjectDelete("ProfitLockedIn");
                
      if (GlobalVariableCheck(CurrentPairPercentageRisk))
         GlobalVariableDel(CurrentPairPercentageRisk);

This code catches objects that have been left over from a closed trade if they exist.

By the way - do NOT do this:

string AcctCurrency = AccountCurrency();
       
      if (AcctCurrency == "")
          return(rates_total);

You've misunderstood the intent of the code. It's designed to NOT run the indie until the server has "settled down". That's why I return 0. That way the indie code won't execute until all the info it needs is available. I honestly haven't worked with OnCalculate() yet because I haven't needed to but I can say that what you're doing is an invitation to disaster. You aren't telling your program, "Don't run this code until you have valid data." You're just casting stuff to the wind and hoping for the best. To tell you the truth, I don't know what your code would do if it wasn't getting dependable info from the server. After a considerable amount of reading, their new OnCalculate() method makes no sense to me. it looks to me like it's unnecessarily calculating and handing a load information that you would do for yourself if you needed to and saving yourself the computing time by not bothering with what you don't need. I'm not sure what they're trying to accomplish with this.

Happy Coding!

Dadas
260
Dadas  
ProfessorMetal:


You're welcome, Dadas. I wouldn't use ObjectDelete() in the start method, though. That's best done in OnDeInit(). The reason for that is this: if you put the code in OnStart() or OnCalculate() it's going to be executed every time a tick comes. That's bad for two reasons: 1) it adds a lot of operations using up time that you can't afford to waste in a real-time application and 2) it doesn't make sense to do that in most situations - usually it's only going to matter when a chart is de-initialized. You should only do it in the "startup" methods if a price change will affect your objects in some way. As an example, consider this(which is part of an app that I intend to sell, but sharing this is cool :-) ).

This code catches objects that have been left over from a closed trade if they exist.

By the way - do NOT do this:

You've misunderstood the intent of the code. It's designed to NOT run the indie until the server has "settled down". That's why I return 0. That way the indie code won't execute until all the info it needs is available. I honestly haven't worked with OnCalculate() yet because I haven't needed to but I can say that what you're doing is an invitation to disaster. You aren't telling your program, "Don't run this code until you have valid data." You're just casting stuff to the wind and hoping for the best. To tell you the truth, I don't know what your code would do if it wasn't getting dependable info from the server. After a considerable amount of reading, their new OnCalculate() method makes no sense to me. it looks to me like it's unnecessarily calculating and handing a load information that you would do for yourself if you needed to and saving yourself the computing time by not bothering with what you don't need. I'm not sure what they're trying to accomplish with this.

Happy Coding!


Thanks again!

I have found the answer to the floating labels.

Looks like now we must Bind the Object Anchor in the code itself:

https://docs.mql4.com/en/constants/objectconstants/enum_anchorpoint

So, I must add smth like the following:

if(Corner==0) Anchor=ANCHOR_LEFT;
if(Corner==1) Anchor=ANCHOR_RIGHT;
if(Corner==2) Anchor=ANCHOR_LEFT;
if(Corner==3) Anchor=ANCHOR_RIGHT; 

and then use another line to set the object:

    ObjectSet(objname,OBJPROP_ANCHOR,Anchor);

Life is definetily not getting easier!

And then this doesn't help, after all!!!

BTW. I'll tell you what they are trying to accomplish:

They want to stop as many people as possible from messing around with codes.

It has to be as commercial as possible.

Until recently, almost anybody was able to mess around with simple mql4.

Now, the goal is to commercialize everything!

Ian Venner
2397
Ian Venner  
Dadas:

That B646 is seriously bugged!
That may be so, but global initialization failed is a specific error unrelated to this discussion about objects anchor points.
Ian Venner
2397
Ian Venner  
ProfessorMetal:


their new OnCalculate() method makes no sense to me. it looks to me like it's unnecessarily calculating and handing a load information that you would do for yourself if you needed to and saving yourself the computing time by not bothering with what you don't need. I'm not sure what they're trying to accomplish with this.

Happy Coding!

OnCalculate provides the result of calculating how many bars have already been processed by the indicator. It replaces old IndicatorCounted function. It also achieves compatability with mql5 because the series arrays are passed to it by reference, vs the old mql4 way of using the global series arrays. From a coding point of view there is very little difference.

Jeffrey Irick
339
Jeffrey Irick  

Once again, you're welcome, Dadas. I had forgotten about using the ANCHOR properties even though I make use of it in some of my stuff.

SDC, thanks for the info. The documentation doesn't really clarify its purpose. I suspect the meaning may have gotten lost in the translation from Russian to English. Now it makes more sense. I assume that it isn't meant to be used in place of OnStart() but instead used in place of IndicatorCounted(). It would be a good addition to the documentation to provide an example that shows a sort of "before" and "after" demonstrating the replacement of IndicatorCounted() with OnCalculate(). I'll have to go back and review the documentation in light of your explanation and see how the pieces come together. Thanks again.

Prof

Ian Venner
2397
Ian Venner  

You use int OnCalculate() in place of int start(). It runs on every tick like start(). A before and after would look something like this,

int start()
  {
   int i=0, limit=0;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars < 0) return(-1);
//----
   limit = Bars-counted_bars-1;
   for (i = limit; i >= 0; i--)
   {
//---- indicator calculations
   }
   return(0);
  }

//--------------------------------------------------
//--------------------------------------------------

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[])
  {
   int i=0, limit=0;
//--- check for possible errors
   if(prev_calculated < 0) return(-1);
//---
   limit = rates_total-prev_calculated;
   for(i = limit; i >= 0; i--)
   {
//--- indicator calculations
   }
   return(rates_total);
  }

OnCalculate's formal parameters make it more self contained, the coder doesn't have to rely on calling all kinds of globals which apparently in oop circles is bad bad coder, slap on wrist. In practice there really is not much difference between using either of them. Also OnCalculate is the same as mql5 so you have the option to write compatabie code.

To add comments, please log in or register