Spread filter for EA

 

Hello guys.

Can you tell me if the code in this way can be correct or where i`m doing wrong?

Thanks to everyone.

    //++++ Spread Filter
    extern double MaxSpread = 5.0;
    int MarketInfo()
    
    if {(StringFind(Symbol(), "JPY") >= 0){ {Spread = (Ask-Bid)*100; } else {Spread = (Ask-Bid)*10000; }}}
     
     switch (MarketInfo(Symbol(), MODE_DIGITS)) 
     {
      case 3:
      case 5:
         Spread = MarketInfo(Symbol(), MODE_SPREAD) / 10;
         break;
      default:
         Spread = MarketInfo(Symbol(), MODE_SPREAD);
         break;}
      if(Spread >= MaxSpread) { return(0);}
      
 
BlackDragon02: Can you tell me if the code in this way can be correct or where i`m doing wrong?
  1. Don't
paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. extern double MaxSpread = 5.0;
    What unit, points or pips. Use pips and adjust 4/5 digit brokers.
    Spread = (Ask-Bid)*100; } else {Spread = (Ask-Bid)*10000;
    You hard coded values, works on 5 digit Forex only.
    Spread = (Ask-Bid)/_Point; // Spread in points. Equivalent to MarketInfo(spread)

  3. adjusting SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs.
    double   pip          = StringFind(_Symbol,"JPY") < 00.010.0001;
    int      pipsToPoints = int(pip / _Point);
    int      pipDigits    = (int)MathLog10(pipsToPoints);
    int      slippage     = 3 * pipsToPoints;
  4.      switch (MarketInfo(Symbol(), MODE_DIGITS)) 
         {
          case 3:
          case 5:
             Spread = MarketInfo(Symbol(), MODE_SPREAD) / 10;
             break;
          default:
             Spread = MarketInfo(Symbol(), MODE_SPREAD);
             break;}
    Verbose. Simplified:
    Spread = MarketInfo(Symbol(), MODE_SPREAD) / pipsToPoints; // Spread in pips



 
Comments that do not relate to this topic, have been moved to "Request for free coding. No work, no learning, no reading".
Reason: