Author: AHGduP
W%R_MA_LC

This script is a custom technical analysis tool designed for the MetaTrader platform. Its primary purpose is to visualize market momentum by combining two distinct types of data: a raw momentum reading and a smoothed average of that reading.

Core Functionality

The tool operates by analyzing price movements over a specific period to determine the "strength" of the current trend. It then plots two separate lines on a dedicated window below the main price chart:

  1. The Momentum Line (WPR): This represents the immediate momentum of the market. It captures quick fluctuations and reacts quickly to recent price changes.
  2. The Moving Average Line (MA): This calculates the average value of the momentum over a set timeframe. By smoothing out the "noise" of the raw momentum, this line helps identify the broader trend direction without the distraction of minor price spikes.

Visual Logic and Scaling

To make the data easy to read at a glance, the script performs several automatic adjustments:

  • Dynamic Normalization: The tool automatically identifies the highest and lowest points reached by both lines over a specific number of past bars (defaulting to 400). It then scales both lines into a consistent range. This ensures that the lines remain visible and proportional regardless of how volatile the market is at any given moment.
  • Color Coding: The two lines are displayed in different colors (Chartreuse and Red) to allow for clear visual separation between the "fast" momentum and the "slow" average trend.
  • Reference Levels: The indicator includes several horizontal grid levels (such as 85, 50, and 15) to help traders identify overbought or oversold conditions relative to the scaled data.

Real-Time Interaction

The script includes a dynamic text label that updates automatically on your screen. It compares the current value of the immediate momentum against its moving average:

  • If the immediate momentum is higher than the average, the value is displayed in Lime, suggesting upward pressure.
  • If the immediate momentum is lower than the average, the value is displayed in Red, suggesting downward pressure.

Summary for the User

Essentially, this tool acts as a "filter." By plotting the raw momentum against its own moving average and scaling them perfectly to your screen, it helps you distinguish between temporary market noise and actual shifts in trend direction. The color-coded text label provides a quick summary of whether the current immediate movement is leading or lagging behind the broader trend.

Indicators Used
Larry William percent range indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
W%R_MA_LC
//+------------------------------------------------------------------+
//|                                              W%R_MA_LC.mq4
//+------------------------------------------------------------------+
#property copyright "AHGduP"
#property link      "W%R_MA_LC"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Chartreuse
#property indicator_width1 2
#property indicator_color2 Red//DodgerBlue
#property indicator_width2 2

//#property indicator_minimum 0
//#property indicator_maximum 100
//=========================================================================
#property indicator_level1 100
#property indicator_level2 85
//#property indicator_level3 80

#property indicator_level4 50

//#property indicator_level5 20
#property indicator_level6 15
#property indicator_level7 0

#property indicator_levelcolor SlateGray //C'160,160,160'   //DarkGray  
#property indicator_levelstyle STYLE_DOT
#property indicator_levelwidth 1

//==========================================================================
extern int   WPR_Per     = 16;
extern int   MA_Per      = 8 ;

extern int  LineSize1     = 2;
extern int  LineSize2     = 2;
extern int  CountBars    = 400; 

double wpr_Buffer1[];
double wpr_Buffer2[];
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void init() {
      IndicatorDigits(+1); 
      SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,LineSize1);
      SetIndexBuffer(0,wpr_Buffer1);
      SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,LineSize2);
      SetIndexBuffer(1,wpr_Buffer2);
    
//+------------------------------------------------------------------+
  string  ThisName = "WPR_MA_LC";
       string Text=ThisName;
        Text=Text+"(";
        Text=Text+" "+DoubleToStr(WPR_Per,0);
        Text=Text+", "+DoubleToStr(MA_Per,0);
        Text=Text+")  ";
        IndicatorShortName("WPR_MA_LC");
        SetIndexLabel(0,"WPR_MA_LC");
//+------------------------------------------------------------------+        
    return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {     Refresh();
        return(0);
  }           
//=====================================================================    
    void start()
    {   Refresh();
      draw_wpr(1,wpr_Buffer1,wpr_Buffer2);
      draw_wpr(2,wpr_Buffer1,wpr_Buffer2);
   }
//+--------------------------------------------------------

void draw_wpr(int buf_num,double &b1[],double &b2[]){
   int LoopBegin;
   if (CountBars==0) LoopBegin=Bars-1;
   else LoopBegin=CountBars-1;
    int limit=Bars-CountBars;
     SetIndexDrawBegin(0,Bars-CountBars);
     SetIndexDrawBegin(1,Bars-CountBars);
     
       int numinput       = WPR_Per;
  
    if(buf_num==2) 
      {    numinput       = MA_Per;   
      }

    int    i,y=0;
 
   double min=0,max=-100;   
   for(i=0,y=0;i<LoopBegin;i++){
   
      b1[i]=iWPR(NULL,0,WPR_Per,i);

       while(limit>0)
     {
      double sum=0,ma= 0;
      for(int j=0;j<MA_Per;j++)
      { sum = sum + iWPR(NULL,0,WPR_Per,limit+j);}
      
      ma = sum / MA_Per;
//----
      b2[limit-1] = ma;
    //  Comment(ma);
      limit--;
     }
      
      min = MathMin(min,MathMin(b1[i],b2[i]));
      max = MathMax(max,MathMax(b1[i],b2[i]));
      }  
   min = MathAbs(min);
   max = max + min;
   for(i=0;i<LoopBegin;i++)
    {
      b1[i] = 100 * ( b1[i] + min )/max;
      b2[i] = 100 * ( b2[i] + min )/max;
   }

//========================LABEL========================================================================================   
   
  {                       ObjectCreate ("wprlc_lab", OBJ_LABEL,WindowFind("WPR_MA_LC"), 0, 0);
    if ( b1[0] > b2[0] ){ ObjectSetText("wprlc_lab", "WPR=  "+DoubleToStr(b1[0],1)+"", 12, "Tahoma Bold", Lime);}
    if ( b1[0] < b2[0] ){ ObjectSetText("wprlc_lab", "WPR=  "+DoubleToStr(b1[0],1)+"", 12, "Tahoma Bold", Red);}
                          ObjectSet    ("wprlc_lab", OBJPROP_XDISTANCE, 1150);
                          ObjectSet    ("wprlc_lab", OBJPROP_YDISTANCE, 70); 
  }
  }
//=====================================================================================================================
  void Refresh() 
      {       
             ObjectDelete("wprlc_lab");     
      
      }
//--------------------------------------------------------------------------------------------------------------------+ 

Comments