Can I find out the biggest spread at the past in MT4? - page 2

 
Sky L:

Do you know any method to find out the biggest spread at the past in MT4?

I will move this topic to the MQL4 and MT4 section.

In future please post in the correct section.

 
Icham Aidibe:

https://docs.mql4.com/constants/structures/mqlrates

Was doubting about mt4, but here it is. It's possible to retrieve the higher spread on a pre-defined interval by using mqlrates :

... then all you have to do is to start a for-loop on rates[x].spread ...

edit : you may also try with arraymax ... maybe by coping it into the array or something like that - i don't remember exactly how i did it

Thank you so much, Icham.

I don't know code so much recently.

Do you know any easier way for a beginner?

Best regards,

Sky

 
Keith Watford:

I will move this topic to the MQL4 and MT4 section.

In future please post in the correct section.

Thank you, Keith.

Actually, I might need it in both of them 4 and 5. 

Best regards,

Sky

 
You have to remember it yourself. I use a power mean to get the average ten (10) day maximum:
double   EMA(double previous, double current, double length){
   double   alpha = 2.0 / (length + 1);
   return previous + alpha * (current - previous);
}
double   PMA(double previous, double current, double length, double power){
   // en.wikipedia.org/wiki/Generalized_mean#Special_cases (Power Mean)
   previous = MathPow(previous, power);
   current  = MathPow(current,  power);
      double   ma = EMA(previous, current, length);
   return MathPow(ma, 1.0 / power);
}
⋮
   //{ Average/Maximum Spread.   (Must run per tick.)
      static const string  nameMax        = _Symbol + "SpreadMax";
      static const string  nameAve        = _Symbol + "SpreadAve";
      static const string  nameCount      = _Symbol + "Spread_C";
      static const string  nameElapsed    = _Symbol + "Spread_E";
      static const double  power          = 20;
      static const COUNT   secondsPerDay  = 86400; // 24*60*60

      static double     spreadMax, spreadAve, nTicks, nSeconds;
      static datetime   then;
      datetime now         = TimeCurrent();
      double   spreadCur   = MathMax(0,Ask - Bid) / _Point;
      if(prev_calculated == 0){
         then  = now;
         if(!GlobalVariableGet(nameMax,     spreadMax)
         || !GlobalVariableGet(nameAve,     spreadAve)
         || !GlobalVariableGet(nameCount,   nTicks)
         || !GlobalVariableGet(nameElapsed, nSeconds)
         || spreadMax == 0.0 || !MathIsValidNumber(spreadMax)
         ){ spreadAve = spreadMax = spreadCur;  nTicks = 0; nSeconds = 1;  }
      }
      nTicks += 1;   nSeconds += SECONDS(now - then); then  = now;
      if(nSeconds > 10*secondsPerDay){ nTicks *= 0.9; nSeconds *= 0.9;  } //EMA
            double   ticksPerDay = secondsPerDay * nTicks / nSeconds;
         double   weight      = MathMin(ticksPerDay, nTicks);
      spreadMax   = PMA(spreadMax, spreadCur, weight, power);
      spreadAve   = EMA(spreadAve, spreadCur, weight);

      GlobalVariableSet(nameMax,  spreadMax);
      GlobalVariableSet(nameAve,  spreadAve);
      GlobalVariableSet(nameCount,   nTicks);
      GlobalVariableSet(nameElapsed, nSeconds);
   //} Average/Maximum Spread.   (Must run per tick.)

Most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134. The charts show Bid prices only. Turn on the Ask line to see how big the spread is, Tools → Options (control+O) → charts → Show ask line.
 
William Roeder:
You have to remember it yourself. I use a power mean to get the average ten (10) day maximum.
Most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134. The charts show Bid prices only. Turn on the Ask line to see how big the spread is, Tools → Options (control+O) → charts → Show ask line.

Thank you, William.

Tools → Options (control+O) → charts → Show ask line.

I tried it, but I didn't understand what is the difference between show ask line or not.

Could you explain any more detail?

Best regards,

Sky


 
Sky L:

Thank you so much, Icham.

I don't know code so much recently.

Do you know any easier way for a beginner?

Best regards,

Sky

yes wait few minutes 

 
Icham Aidibe:

yes wait few minutes 

Thank you for take you time, Icham.

 
Sky L:

Thank you so much, Icham.

I don't know code so much recently.

Do you know any easier way for a beginner?

Best regards,

Sky

void OnStart()
  {
   int x = 1000;
   MqlRates rates[];
   int copied=CopyRates(NULL,0,0,x,rates);
   int spread[];
   for(int i=0;i<ArraySize(rates);i++) { ArrayResize(spread,ArraySize(spread)+1); spread[i] = rates[i].spread; }
   
   printf("*** Max spread : %g / Min spread : %g on the last %g bars",spread[ArrayMaximum(spread,0,WHOLE_ARRAY)],spread[ArrayMinimum(spread,0,WHOLE_ARRAY)],x);
   
  }
mqlspread (EURUSD,W1)   *** Max spread : 50 / Min spread : 0 on the last 1000 bars
 
SpreadWatch
SpreadWatch
  • www.mql5.com
This indicator is ideal for scalpers who need to know the biggest spread possible with his broker. This will limit his stop-loss. Stop-loss should be higher than the biggest spread to minimize stop-hunt and slippage issues.  Included lowest spread.
 
Icham Aidibe:

Thank you so much, Icham.