The new MQL4 syntax - page 6

 
SDC:

The compiler errors when I put the path to the icon in the terminal_data_directory, the error says cannot open file in a virtual store folder even though I did not specify a folder in the virtual store. I specify a folder in the terminal_data_directory.

The only way I could get it to work was to put the file in the same folder as the source code and not specify a path at all, just #property icon "MyIcon.ico"


Hi just in case anyone has problem with #property icon "\\Images\\MyIcon.ico", you should consider the size of the icon 96x96 px or higher. I have experienced the error also, but now works.
 

I noticed that compiler performs casting that I would not expect to occur.

I have following code:

where the class of the key object is MT4String, while the function getKey() returns more generic class. The same case is with the button object. Explicit casting is omitted.

Original code looked like this:

In JAVA, there would be explicit casting necessary, but the MQL4 compiler works with this syntax properly as well.

Is this implicit casting a feature, that is also valid in C++? Or is it a bug?

 

I'm not a C++ expert but going from a base class to a child class is called downcasting and according to this page it looks like downcasting must be explicit in C++ too. (like Java) ?

As MQL4 allows implicit downcasting it's either a "feature" or a bug :)

If its a "feature" it probably means that the compiler will fail to warn the coder of a potential error, so its not a great feature. Both C++ and Java require explicit downcasting for a reason?

Furthermore, in MQL4, there is no built in way to check the class of an object (eg instanceOf etc) so it means a run time error can't be avoided unless you implement your own 'type' check...


Animal a;

Dog d;

...

if (a instanceOf Dog) { // no built in check like this - we all have to roll our own??

 d = a;

}
 
ydrol:

I'm not a C++ expert but going from a base class to a child class is called downcasting and according to this page it looks like downcasting must be explicit in C++ too. (like Java) ?

As MQL4 allows implicit downcasting it's either a "feature" or a bug :)

If its a "feature" it probably means that the compiler will fail to warn the coder of a potential error, so its not a great feature. Both C++ and Java require explicit downcasting for a reason?

Furthermore, in MQL4, there is no built in way to check the class of an object (eg instanceOf etc) so it means a run time error can't be avoided unless you implement your own 'type' check...




Yes, I would appreciate instanceof or ".class" too, but as far as I noticed it is not available even in the C++. Even the MQL4 debugger does not know the type of the watched object. I do not care much, because the OOP feature in MQL4 is implemented surprisingly very well, and if this was the only bug, then I would say hurray. I just was curious, if it was following some existing pattern, but it seems it was rather a bug.

 

one click trading

in old MT4 i use a dll file for creating EA one click trading

i can type the parameter.. LOT, TP SL directly on those white text box

when i click buy or sell.. my EA read the input text in the box.

in new MT4 i see button function.. but i can't find the function to create an read a text box like that

 
WDholic:

in old MT4 i use a dll file for creating EA one click trading

i can type the parameter.. LOT, TP SL directly on those white text box

when i click buy or sell.. my EA read the input text in the box.

in new MT4 i see button function.. but i can't find the function to create an read a text box like that

For the keyboard input there is the object type OBJ_EDIT. It fires CHARTEVENT_OBJECT_ENDEDIT event if you press the Enter key. But it seems that the Enter key is the only way how to finish editing, e.g. clicking a mouse outside the object boundaries does not finish editing. It prevents me from deploying the object as user unfriendly.

Moreover, if empty string is supplied as initial value, then automatic text "Edit" shows up instead (and this word even can be edited), which is really confusing.

 
void OnChartEvent(const int id,
                  const long   &lparam,
                  const double &dparam,
                  const string &sparam){

   if(id==CHARTEVENT_OBJECT_ENDEDIT ){
   
      if(sparam=="pulsanteEdit") Print("The text in the Edit field of the object with name ",sparam," has been changed");
     } 
}
void creaPulsanteEdit(const string objNameIns,const string objText,int xDistance,int yDistance,int xSize,int ySize,color clrIns,color clrTextIns){
   
   if(!ObjectCreate(0,objNameIns,OBJ_EDIT,0,0,0)){ 
      stampaErrore("Errore creazione pulsante edit");
      return;
   }
   
   ObjectSetInteger(0,objNameIns,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   
   ObjectSetInteger(0,objNameIns,OBJPROP_XDISTANCE,xDistance); 
   ObjectSetInteger(0,objNameIns,OBJPROP_YDISTANCE,yDistance); 

   ObjectSetInteger(0,objNameIns,OBJPROP_XSIZE,xSize); 
   ObjectSetInteger(0,objNameIns,OBJPROP_YSIZE,ySize);
   
//--- set the text 
   ObjectSetString(0,objNameIns,OBJPROP_TEXT,objText);
   ObjectSetString(0,objNameIns,OBJPROP_FONT,"Arial");
   ObjectSetInteger(0,objNameIns,OBJPROP_FONTSIZE,10);
   
   ObjectSetInteger(0,objNameIns,OBJPROP_READONLY,false);
   
   ObjectSetInteger(0,objNameIns,OBJPROP_BGCOLOR,clrIns);
   ObjectSetInteger(0,objNameIns,OBJPROP_COLOR,clrTextIns);
   
   ObjectSetInteger(0,objNameIns,OBJPROP_BORDER_COLOR,LightSeaGreen);
   
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(0,objNameIns,OBJPROP_BACK,false);
   
   ObjectSetInteger(0,objNameIns,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0,objNameIns,OBJPROP_SELECTED,false);
   ObjectSetInteger(0,objNameIns,OBJPROP_HIDDEN,false);
}

void OnTick(){

  creaPulsanteEdit("pulsanteEdit", string1, 10, 275,60,30,Black,LightSeaGreen);

  Print("string1: "+string1);
}

I created this button to edit the text inside it and I would like to read and convert the text string into a double or int variable but it does not work and not print the "The text in the Edit field of the object with name" has been changed "

can you help me?

Reason: