Author: Dmitry Yakovlev, Russia,Omsk WM R865705290089
WPROnChart

This script is a technical analysis tool designed for the MetaTrader trading platform. It functions by combining two different types of market data—momentum and moving averages—to visualize price trends, volatility zones, and potential turning points on a chart.

Core Logic and Functionality

1. Hybrid Trend Visualization The primary logic of the script involves merging the Williams Percent Range (WPR) with a Moving Average (MA).

  • The WPR is typically used to measure momentum and identifies whether an asset is overbought or oversold.
  • The Moving Average smooths out price fluctuations to show the general direction of the trend. By combining these two, the script creates a "Signal" line that reflects both the current strength of the market movement and its underlying historical average.

2. Dynamic Level Scaling The indicator includes an optional feature to display horizontal reference levels. These levels act as visual boundaries:

  • They are calculated based on the Moving Average but are offset by specific percentages.
  • These "bands" help traders identify areas where price might be stretched too far from the average, potentially indicating a reversal or a period of exhaustion.

3. Automatic Pivot Detection (Extremums) Beyond drawing lines, the script contains logic to automatically identify significant market pivots:

  • The code scans historical data to find specific "V-shaped" or "inverted V-shaped" patterns in the momentum data.
  • When it detects a peak (where momentum moves from up to down) or a trough (where momentum moves from down to up), it automatically places visual markers (arrows) on the chart.
  • Green arrows generally indicate potential upward momentum shifts, while Red arrows highlight potential downward shifts.

4. Configuration and User Experience The script is designed with several customizable parameters, allowing users to adjust:

  • Periodicity: The timeframe window used to calculate momentum.
  • Moving Average Settings: The length and type of the average used for smoothing.
  • Visual Toggles: Users can choose whether to see the extra boundary levels or the automated pivot arrows.

5. Administrative Features The script includes a background management system that tracks usage. It features an automated notification system designed to interact with the user at set intervals (e.g., every 10 days). If the conditions are met, it can prompt the user with a message box and provide a link to support the developer’s work through a donation gateway.

Indicators Used
Larry William percent range indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1Uses files from the file systemIt reads information from a fileIt writes information to file
13 Views
0 Downloads
0 Favorites
WPROnChart
#property copyright "Dmitry Yakovlev, Russia,Omsk WM R865705290089"
#property link      "http://fehu.nxt.ru/   dmitryyakv@yandex.ru"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 RoyalBlue
#property indicator_width1 2
#property indicator_color2 RoyalBlue
#property indicator_width2 1
#property indicator_color3 RoyalBlue
#property indicator_width3 1
#property indicator_color4 RoyalBlue
#property indicator_width4 1

#import  "shell32.dll"           //Connect a dll (provided with Windows)             
  int ShellExecuteA(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd); 
#import "user32.dll"
  int MessageBoxA(int hWnd ,string lpText,string lpCaption,int uType);
//------------------------------------------------------------------------------------------------------
extern int period=14;
extern int MA=50;
extern int Scale=100;
extern int ShowLevels=1;
extern int ShowExtremums=1;
extern string  _donate1="Äëÿ \"ñïàñèáî\" :-)";
extern string  _donate2="R865705290089";
extern string  _advert="Íàïèøó íà çàêàç,ïåðåäåëàþ.";

//---- buffers
double Signal[];
double Buffer1[];
double Buffer0[];
double Buffer5[];
double WPR[];
//----
int draw_begin1=0;
int draw_begin2=0;

int lblcnt=40;
int init()
{
   int i;
   string short_name;
   
   string tmp;
   for(int k=0;k<lblcnt;k++)
   {
      tmp="myWPRSignal"+period+"_"+k;
      ObjectDelete(tmp);
   }

   CheckDonate();

   IndicatorBuffers(4);

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0, Signal);
   if(ShowLevels==1)
   {
      SetIndexStyle(1,DRAW_LINE);
      SetIndexBuffer(1, Buffer1);
      SetIndexStyle(2,DRAW_LINE);
      SetIndexBuffer(2, Buffer5);
      SetIndexStyle(3,DRAW_LINE);
      SetIndexBuffer(3, Buffer0);
   }
   else
      for(i=1;i<=3;i++) SetIndexStyle(i,DRAW_NONE);
   
   for(i=4;i<=7;i++) SetIndexStyle(i,DRAW_NONE);
   
   short_name="WPR("+period+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
   SetIndexLabel(1,"-80%");
   SetIndexLabel(2,"-50%");
   SetIndexLabel(3,"-20%");
//----
   draw_begin1=period;
   SetIndexDrawBegin(0,draw_begin1);
   SetIndexDrawBegin(1,draw_begin1);
   SetIndexDrawBegin(2,draw_begin1);
   SetIndexDrawBegin(3,draw_begin1);
//----
   ArraySetAsSeries(WPR,true);
   return(0);
  }

void deinit()
{
   string tmp;
   for(int k=0;k<lblcnt;k++)
   {
      tmp="myWPRSignal"+period+"_"+k;
      ObjectDelete(tmp);
   }
}

int start()
  {
   int    i,k;
   int    counted_bars=IndicatorCounted();
   double price;
//----
   if(Bars<=draw_begin2) return(0);
   if(ArraySize(WPR)!=Bars) ArrayResize(WPR,Bars);
   //---- initial zero
   if(counted_bars<1)
      for(i=1;i<=draw_begin2;i++)
      {
         Signal[Bars-i]=0;
         Buffer0[Bars-i]=0;
         Buffer1[Bars-i]=0;
         Buffer5[Bars-i]=0;
         WPR[Bars-i]=0;
      }
   
   double kk=Point*Scale/100;
   int limit=Bars-counted_bars;
   for(i=0; i<limit; i++)
   {
      WPR[i]=iWPR(Symbol(),0,period,i);
      Signal[i]=iMA(Symbol(),0,MA,0,MODE_EMA,PRICE_MEDIAN,i)+(WPR[i]+50)*kk;
      if(ShowLevels==1)
      {
         Buffer1[i]=iMA(Symbol(),0,MA,0,MODE_EMA,PRICE_MEDIAN,i)+30*kk;
         Buffer5[i]=iMA(Symbol(),0,MA,0,MODE_EMA,PRICE_MEDIAN,i);
         Buffer0[i]=iMA(Symbol(),0,MA,0,MODE_EMA,PRICE_MEDIAN,i)-30*kk;
      }
   }
   
   //<-signal
   if(ShowExtremums==1)
   {
      int wpr;
      double wpr0,wpr1,wpr2;
      i=0;k=0;
      while(k<lblcnt && i<Bars)
      {
         wpr=0;
         while(i<Bars && wpr==0)
         {
            wpr0=iWPR(Symbol(),0,period,i+0);
            wpr1=iWPR(Symbol(),0,period,i+1);
            wpr2=iWPR(Symbol(),0,period,i+2);
            if(wpr0>wpr1 && wpr2>wpr1) wpr=+1;
            if(wpr0<wpr1 && wpr2<wpr1) wpr=-1;
            if(wpr!=0) break;
            i++;
         }

         string tmp="myWPRSignal"+period+"_"+k;
         ObjectDelete(tmp);
         if(wpr==+1)
         {
            ObjectCreate(tmp,OBJ_ARROW,0,Time[i],Low[i]);
            ObjectSet(tmp,OBJPROP_ARROWCODE,108);
            ObjectSet(tmp,OBJPROP_COLOR,Lime);
            k++;
         }
         if(wpr==-1)
         {
            ObjectCreate(tmp,OBJ_ARROW,0,Time[i],High[i]+(WindowPriceMax()-WindowPriceMin())/10);
            ObjectSet(tmp,OBJPROP_ARROWCODE,108);
            ObjectSet(tmp,OBJPROP_COLOR,Red);
            k++;
         }
         i+=1;
      }
   }
   //->
   
   return(0);
}

void CheckDonate()
{
   int fd=0; string pay="0"; datetime dt=0;
   string fn="WPROC.txt";
   fd=FileOpen(fn,FILE_READ|FILE_CSV,";");
   if(fd>=1)
   {
      pay=FileReadString(fd); if(pay!="0" && pay!="1") pay="0";
      dt=StrToTime(FileReadString(fd));
   }
   else
   {
      dt=TimeCurrent();
      fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
      FileWrite(fd,"0",TimeToStr(dt,TIME_DATE));
   }
   FileClose(fd);
   
   if(pay=="0" && (TimeCurrent()-dt)>10*24*60*60) // 5 äíåé
   {
      if(MessageBoxA(0,"Åñëè Âàì ïîíðàâèëñÿ èíäèêàòîð On Chart WPR,\n õîòèòå ïîìî÷ü àâòîðó ìàòåðèàëüíî?","Âîïðîñ",4)==6)
      {
         ShellExecuteA(0,"Open","iexplore.exe","wmk:payto?Purse=R865705290089&Amount=100&Desc=Indicator&BringToFront=Y&ExecEvenKeeperIsOffline=Y","",7);
         pay="1";
      }
      dt=TimeCurrent();
      
      fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
      FileWrite(fd,pay,TimeToStr(dt,TIME_DATE));
      FileClose(fd);
   }
   FileClose(fd);
}

Comments