can mql5 EA coded with no OOP features?

 

my EA is simple , and the  functions in my EA do not have relationship, can i coded a mql5 EA which is no Class,  inheritance and no Polymorphism , without any error?

thanks 

 
chiwing posted  :

my EA is simple , and the  functions in my EA do not have relationship, can i coded a mql5 EA which is no Class,  inheritance and no Polymorphism , without any error?

thanks 

Yes, MQL5 can be written with just global functions, ie without any OO constructs.  But the advantage of OO encapsulation is that you can very easily use proven classes written by someone else - take a look at the CTrade class in include\trade\trade.mqh to use in your EA.

Paul

 

 
phampton:

Yes, MQL5 can be written with just global functions, ie without any OO constructs.  But the advantage of OO encapsulation is that you can very easily use proven classes written by someone else - take a look at the CTrade class in include\trade\trade.mqh to use in your EA.

Paul

 

I have look the "trade.mqh"

but i don't know how to use  "trade.mqh"  to help me making my EA easier

 

may you give an example for open a new order , and modify the SL,TP which just open before?

thanks 

#include  "trade.mqh"...

 
chiwing:

I have look the "trade.mqh"

but i don't know how to use  "trade.mqh"  to help me making my EA easier

 

may you give an example for open a new order , and modify the SL,TP which just open before?

thanks 

#include  "trade.mqh"...

 

 

CTrade is what is often termed a "wrapper", in order words it is a simple packaging of like functions into the one class, with a few checks.  The documentation at the top of each method is sufficient to work out how the class is used.

To do the actions that you suggest using CTrade, I would write it like this.

CTrade trade;
MqlTick CurrentTick;
SymbolInfoTick(_Symbol,CurrentTick);

// open new position
double sl,tp;  // set these to appropriate distance from CurrentTick.ask
if (!trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,0.1,CurrentTick.ask,sl,tp,"comment"))
{
  Print("Problem with CTrade::PositionOpen");
  return;
}

// change sl and tp to new values
// sl=??????;
// tp=??????;
if (!trade.PositionModify(_Symbol,sl,tp))
{
  Print("Problem with CTrade::PositionModify");
  return;
}



 

 

 

Paul 

 
phampton:

CTrade is what is often termed a "wrapper", in order words it is a simple packaging of like functions into the one class, with a few checks.  The documentation at the top of each method is sufficient to work out how the class is used.

To do the actions that you suggest using CTrade, I would write it like this.

 Paul 

thanks for your reply

actually , mql5 is doing for those ea coder which ea have lots of function and those functions are similar~ ~

 i have a mql4 ea which have 23 functions inside, but i don't think they are good by coding in mql5, because the functions are different

In my opinion , mql5 make EA author easier to make error, because it forced to make one by using some different property functions

in result,  author need to think and type more~ ~

i advice EA coders don't be lazy (want to save typing and line) , don't  try to make things in a object

if you disagree with me , never mind, just use some example to explain to everyone

thankyou 

Reason: