Download MetaTrader 5

Help with spread filter

To add comments, please log in or register
prweza
239
prweza  

Please help with my spread filter. I'm using ECN 5 digit broker but when I use this code, the ea doesn't seem to read the spread correctly.

On my EA I do normally put an extra 0 eg  500 for a take profit of 50, just as an example ( I've tried to add/take away 0s with no luck). Is there and easier code that workes 

The code is as follows:


double Spread = (Bid-Ask)*10000;
   
if((Spread < Maxspread || Spread==Maxspread))Spre=true;

This means Spre is included on the buying condition if is spread is less than maximum spread.

Please help.

whroeder1
15925
whroeder1  
  1. double Spread = (Bid-Ask)*10000;
    That fails for JPY pairs. Don't hard code numbers.
    double Spread = (Bid-Ask)/_Point; // spread in points.
  2. The spread is Ask - Bid, your number is always negative.

  3. 0 eg 500 for a take profit of 50
    And if you forget, there goes your money. adjusting SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs.
    double   pip          = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
    int      pipsToPoints = int(pip / _Point);
    int      pipDigits    = (int)MathLog10(pipsToPoints);
    int      slippage     = 3 * pipsToPoints;

  4. if((Spread < Maxspread || Spread==Maxspread)
    Doubles are rarely equal. The == operand. - MQL4 forum
  5. Simplify
    if(Spread <= Maxspread)

  6. if(Spread <= Maxspread)Spre=true;
    Are you unsetting your flag? Simplify
    Spre= Spread <= Maxspread;
  7. Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence. Spre doesn't have any meaning.
To add comments, please log in or register