Experts: Robust EA Template

 

Robust EA Template:

A robust EA template to help correctly set take profit and stop loss levels, enter and exit positions, and handle terminal issues, such as crashes or disconnects.

External Inputs

Author: Inovance

 
Automated-Trading:

Robust EA Template:

Author: Inovance

Sorry but your PIP-calculation or your way to deal with "with 4- and 5- digit brokers.":

   if(Digits==5 || Digits==3) // Adjust for 3- or 5-digit Brokers
     {
      takeProfit*=10;
      stopLoss *= 10;
      slippage *= 10;
     }

isn't working any more with many brokers.

For example one of my brokers e.g. has following prices:

        .DE30Cash       XAGUSD          XAUUSD
Open    10156.50        15.1120         11560.800
High    10178.30        15.1230         11569.200
Low     10144.50        15.0990         11560.700
Close   10168.10        15.1020         11562.800
                        
Digits     2               4               3

And these days more and more symbols become trade-able that wont match with your calculation!

 
calli:

Sorry but your PIP-calculation or your way to deal with "with 4- and 5- digit brokers.":

isn't working any more with many brokers.

For example one of my brokers e.g. has following prices:

And these days more and more symbols become trade-able that wont match with your calculation!

Great point, calli. I should have specified that this is meant for trading the majors and more commonly used crosses. Another great reason for always testing on a demo account!


Have you found a good way to make it more generic to handle those cases? The way I have always done it in the past is have it hard coded based on how my broker designates the different assets but obviously that isn't flexible enough to handle all possible names/decimal places. 

 

I have discussed about this with WHRoeder. He disagrees with my solution. (I couldn't found the link in the mql4-forum).

I want that a PIP has always the same money-value - by default close to 10 units of the account currency - and came to this solution:

// use: int Digs,DIGITs ;double PNT,PIP; setPIP(sym, DIGITs, PIP, Digs, PNT, 10.0);
void setPIP(string sym, int& dig, double& pip, int &pntDig, double &pnt, double refValue= 10.0){
   // © calli at MQL5 
   // refValue: Reference value of one pip in Account currency
   // dig: number of digits of 1 pip
   // pip: size of 1 pip
      pntDig = (int)MarketInfo(sym,MODE_DIGITS);
      pnt    = MarketInfo(sym,MODE_POINT);
      int xp = 9, XP=0;
      double   tiV  =  MarketInfo(sym,MODE_TICKVALUE), 
               bst  =  9999999999;
                         
      while(xp>-9){
         double m = pow(10,xp),
                p = m*tiV,
                d = fabs(p-refValue);
         if ( d < bst ) {
              XP = xp;
              bst= d;
         }
         if (d>bst) break;
         xp--;
      }
                
      dig = pntDig - XP;
      pip = pow(10,-dig);
      return;
}

Let me know, if you realize an error.

 

Hi mate!

Thanks for sharing your efforts.

One thing that would be nice and useful could be to add a trailing function to your code.

Best regards 

 
Thank you Calli!
 
calli:

I have discussed about this with WHRoeder. He disagrees with my solution. (I couldn't found the link in the mql4-forum).

I want that a PIP has always the same money-value - by default close to 10 units of the account currency - and came to this solution:

Let me know, if you realize an error.

Calli,


That looks like a good solution. By referencing it to the account currency and checking a range of values (while xp > -9), it seems like you would be able to address most, if not all, of the issues. I'll take a closer look and test it on a couple different accounts but it looks like it would suffice. Thanks for sharing!

 
Alberto Jorge Cushnir:

Hi mate!

Thanks for sharing your efforts.

One thing that would be nice and useful could be to add a trailing function to your code.

Best regards 

Hi Alberto,


We posted a Trailing Stop EA template a couple weeks ago that is very similar to this template. You shouldn't have any trouble combining the two, but if you do let me know and I am happy to help out!


Happy trading!

 
calli:

I have discussed about this with WHRoeder. He disagrees with my solution. (I couldn't found the link in the mql4-forum).

I want that a PIP has always the same money-value - by default close to 10 units of the account currency - and came to this solution:

Let me know, if you realize an error.

You will never find an universal solution, a PIP is only well defined for Forex (and yet you can find people which will disagree), for all other symbols it's trader dependant.
 
Alain Verleyen:
You will never find an universal solution, a PIP is only well defined for Forex (and yet you can find people which will disagree), for all other symbols it's trader dependant.

Well, I don't care much about what others say unless it meets my needs - somehow.

Nowadays PIP has become an "artificial" unit, broker dependent are (in mt4-Speech) "Digits", the "_Point" and the "MODE_TICKSIZE".

With my solution I know that a stop of 70 PIP will always risk approximately the same amount of my money.

Otherwise to have that risk I have to enter either 70 or 700 or 7 or ... and that is a wonderful source of mistakes, typos and errors.

 
Automated-Trading:

Robust EA Template:

Author: Inovance

Thank you Inovance.
Perhaps you can add code to open a pending order.
Reason: