Market Speedometer

shanmugapradeep

Active Trader
Dec 18, 2020
157
12
34
39
Hello,

I Built Market Speedometer to check if market speed is high, low or in normal using MT4 Volume (Tick) data and ATR data. Hope this will useful for peoples. if you have any suggestion or fix please let me know.

Code:
//+------------------------------------------------------------------+
//| Market Speed Monitor EA                                         |
//+------------------------------------------------------------------+
#property strict

extern int     ATRPeriod = 1;
extern int     SpeedLookback = 30;
extern int SpeedBuffer = 20;
input ENUM_TIMEFRAMES Timeframe = PERIOD_M1;

double avgATR = 0, avgVolume = 0;

//+------------------------------------------------------------------+
//| Expert initialization                                            |
//+------------------------------------------------------------------+
int OnInit()
  {
   Print("Market Speed Monitor initialized.");
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double currentATR = iATR(NULL, Timeframe, ATRPeriod, 0);
   double currentVolume = iVolume(NULL, Timeframe, 0);

   avgATR = GetAverageATR(ATRPeriod, SpeedLookback);
   avgVolume = GetAverageVolume(SpeedLookback);

   double currentSpeed = currentATR * currentVolume;
   double averageSpeed = avgATR * avgVolume;

   double highThreshold = 1 + (SpeedBuffer / 100.0);
   double lowThreshold  = 1 - (SpeedBuffer / 100.0);
   string speedStatus;
   if(currentSpeed > averageSpeed * highThreshold)
      speedStatus = "Market Speed: HIGH";
   else
      if(currentSpeed < averageSpeed * lowThreshold)
         speedStatus = "Market Speed: LOW";
      else
         speedStatus = "Market Speed: NORMAL";

   Comment(
      "Current Speed   : ", DoubleToString(currentSpeed, 2),
      "\nAverage Speed   : ", DoubleToString(averageSpeed, 2),
      "\n-------------------------------",
      "\nCurrent ATR     : ", DoubleToString(currentATR, 2),
      "\nAverage ATR     : ", DoubleToString(avgATR, 2),
      "\nCurrent Volume  : ", DoubleToString(currentVolume, 2),
      "\nAverage Volume  : ", DoubleToString(avgVolume, 2),
      "\n-------------------------------",
      "\nMarket Status   : ", speedStatus
   );

  }

//+------------------------------------------------------------------+
//| Function: Calculate average ATR                                 |
//+------------------------------------------------------------------+
double GetAverageATR(int atrPeriod, int lookback)
  {
   double total = 0;
   for(int i = 0; i < lookback; i++)
      total += iATR(NULL, Timeframe, atrPeriod, i);
   return total / lookback;
  }

//+------------------------------------------------------------------+
//| Function: Calculate average Volume                              |
//+------------------------------------------------------------------+
double GetAverageVolume(int lookback)
  {
   double total = 0;
   for(int i = 0; i < lookback; i++)
      total += iVolume(NULL, Timeframe, i);
   return total / lookback;
  }
//+------------------------------------------------------------------+
 
  • 👍
Reactions: Enivid