//+------------------------------------------------------------------+
//|                                               WPRSignaler v1.mq4 |
//|                                                                  |
//|                                         Copyright © 2006, ch33z3 |
//|                                    http://4xjournal.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, ch33z3"
#property link      "http://4xjournal.blogspot.com/"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Green

extern int RPeriod=14;
extern bool Alerts=false;

double wpr[];
double s[];
double l[];
double sc[];
double lc[];     

int init()
{
   IndicatorBuffers(5);

   SetIndexStyle(0,DRAW_ARROW,0,1);
   SetIndexBuffer(0,s);
   SetIndexArrow(0,234);
   SetIndexLabel(0,"Short");
   SetIndexDrawBegin(0,RPeriod);
   
   SetIndexStyle(1,DRAW_ARROW,0,1);
   SetIndexBuffer(1,l);
   SetIndexArrow(1,233);
   SetIndexLabel(1,"Long");
   SetIndexDrawBegin(1,RPeriod);
   
   SetIndexStyle(2,DRAW_ARROW,0,2);
   SetIndexBuffer(2,sc);
   SetIndexArrow(2,241);
   SetIndexLabel(2,"Close Short");
   SetIndexDrawBegin(2,RPeriod);
   
   SetIndexStyle(3,DRAW_ARROW,0,2);
   SetIndexBuffer(3,lc);
   SetIndexArrow(3,242);
   SetIndexLabel(3,"Close Long");
   SetIndexDrawBegin(3,RPeriod);
   
   SetIndexBuffer(4,wpr);
   
   return(0);
}
   
int start()
  {
   int i, counted_bars=IndicatorCounted();
   bool sd=false, ld=false, scw=false, lcw=false;
   double tfm;
   
   if(Bars<=RPeriod) return(0);
   
   s[i]=EMPTY_VALUE;
   l[i]=EMPTY_VALUE;
   sc[i]=EMPTY_VALUE;
   lc[i]=EMPTY_VALUE;
   
   if(counted_bars<1)
     {
      for(i=1;i<=RPeriod;i++) s[Bars-i]=EMPTY_VALUE;
      for(i=1;i<=RPeriod;i++) l[Bars-i]=EMPTY_VALUE;
      for(i=1;i<=RPeriod;i++) sc[Bars-i]=EMPTY_VALUE;
      for(i=1;i<=RPeriod;i++) lc[Bars-i]=EMPTY_VALUE;
     }
   
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;
   
   for(i=limit; i>=0; i--) {
   
   wpr[i]=(iWPR(NULL,0,RPeriod,i))+100;
   
   tfm=Point*MathSqrt(Period())*2;
   
   if(wpr[i]>=50 && wpr[i+1]<=50 && ld==false) {
      l[i]=Low[i]-tfm;
      ld=true;
      scw=false;
      sd=false;
      s[i]=EMPTY_VALUE;
      sc[i]=EMPTY_VALUE;
      lc[i]=EMPTY_VALUE; 
      if(Alerts && i==0) {
         Alert("Enter LONG for ", Symbol(), " on the ", Period(), " chart!");
         PlaySound("alert.wav"); }}
   
   if(wpr[i]<=50 && wpr[i+1]>=50 && sd==false) {
      s[i]=High[i]+tfm;
      sd=true;
      lcw=false;
      ld=false;
      l[i]=EMPTY_VALUE;
      sc[i]=EMPTY_VALUE;
      lc[i]=EMPTY_VALUE; 
      if(Alerts && i==0) {
         Alert("Enter SHORT for ", Symbol(), " on the ", Period(), " chart!");
         PlaySound("alert.wav"); }}
      
   if(ld && wpr[i]>85) lcw=true;
   if(lcw && wpr[i]<75) {
      lc[i]=High[i]+tfm;
      lcw=false;
      ld=false;
      s[i]=EMPTY_VALUE;
      sc[i]=EMPTY_VALUE;
      l[i]=EMPTY_VALUE; 
      if(Alerts && i==0) {
         Alert("Close LONG positions for ", Symbol(), " on the ", Period(), " chart!");
         PlaySound("alert.wav"); }}
      
   if(sd && wpr[i]<15) scw=true;
   if(scw && wpr[i]>25) {
      sc[i]=Low[i]-tfm;
      scw=false;
      sd=false;
      s[i]=EMPTY_VALUE;
      lc[i]=EMPTY_VALUE;
      l[i]=EMPTY_VALUE;
      if(Alerts && i==0) {
         Alert("Close SHORT positions for ", Symbol(), " on the ", Period(), " chart!");
         PlaySound("alert.wav"); }}
     
      }
   return(0);
  }
//+------------------------------------------------------------------+