MACD Sample not compatible with 5 digit brokers

 

I've been messing with the MACD Sample EA to help learn MQL4 programming. I've had a heck of a time figuring some things out though, since the trailing stop never worked. I finally understand now that since I'm using a broker that has 5 digits instead of 4, that messes things up in the code because it's assuming Points is the number of decimals for a pip, but it's really 1/10th of a pip.

I've seen various threads in my searching on ways to try and detect this automatically and adjust the Points value as needed. I'd like to suggest this be handled correctly in the MACD Sample script you provide with new MetaTrader installs, though. Providing an example script that won't work with certain brokers is a bit silly. ;)

 

R

You could just change the input values for any parameter that engages with Point, as in

extern double TakeProfit = 500.0;     // Pip-sensitive
extern double Lots = 0.1;
extern double TrailingStop = 300.0;   // Pip-sensitive
extern double MACDOpenLevel=30.0;     // Pip-sensitive
extern double MACDCloseLevel=20.0;    // Pip-sensitive

or you could use this quickly edited MACD Sample - see attached

-BB-

Files:
 
The above may work, may not. For 5 digit brokers you must modify TP, SL, AND slippage. For ECN brokers you must open the order and THEN set the stops.
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
 

saed

 

Roy7 has highlighted something that really does need attention, the world has indeed moved on since the examples were coded!

WHRoeder raises valid points re Slippage and ECN

Watch the Code Base for an updated MACD Sample in the next few days

-BB-

 

Woop woop!

(sign of support slash enthusiasm)

 

No need to contain the enthusiasm any longer - here it is https://www.mql5.com/en/code/10317

-BB-

 
Very nice sample!!
 

Well - not quite - wait for version 452 for more... definitive example..

-BB-

 
To be honest, it's a much better sample than the former one (seems I have a really old MACD sample in my folder) :) That's what I meant. Can't comment on the one I haven't seen yet, right? :)
 

> really old MACD sample

Yes, I think the originals were the first of a new era for MQL

I believe the first uses were for indicators, scripts and literal 'advisers' that 'knew' all the systems rules & put up an arrow on chart or put up an order dialog box for confirmation by the user

Using advisers as total auto-traders then developed in the same era as XxxxxTrader, Xxxxxxxcharts and other systems

Nothing then new about algo-trading systems, banks had been using them for years but it was a new era for the retail trader

The snag with a completely sorted EA is that the structure would be completely opaque to the new coder

Also very, very hard to extend or change and very easy to break without means of fixing

So I kept as much of the vanilla original as I could while adding the necessary new functionality

FWIW

-BB-

PS

The fixed one (ver 452) is now available here

Reason: