PAX





/*--------------------------------------------------------------+
   This indicator shows moving average of Heiken Ashi prices    |
   And a smoothed moving average...                             |                              
//--------------------------------------------------------------+
To access data from the indicator:
Main signal:
double PAX_now =    iCustom(Symbol(),NULL, "PAX",PAX,Ma_PAX,0,0);
Smoothed signal:
double SPAX_now =   iCustom(Symbol(),NULL, "PAX",PAX,Ma_PAX,5,0);
*/
#property copyright "Copyright © 2004, geoffb65."
#property link      ""

#property indicator_separate_window
#property indicator_minimum -10
#property indicator_maximum 100
#property indicator_buffers 6
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Magenta
#property indicator_color5 DodgerBlue
#property indicator_color6 Red

//---- input parameters
extern int PAX          = 9;


extern int Ma_PAX       = 14;

extern int BuyTrigger      = 20;
extern int SellTrigger     = 80;

extern color BuyTriggerColor  = DodgerBlue;
extern color SellTriggerColor = Magenta;

extern int MainTrendLong   = 50;
extern int MainTrendShort  = 50;

extern color MainTrendLongColor     = Red;
extern color MainTrendShortColor    = Green;

//---- buffers
double PAXBuffer[];
double PosBuffer[];
double NegBuffer[];

double bdn[],bup[];
double sdn[],sup[];

double marspax[];
string short_name;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   short_name = StringConcatenate("PAX(",PAX,")");   
   IndicatorBuffers(8);
   
   SetIndexBuffer(0,PAXBuffer);
   SetIndexBuffer(2,bup);
   SetIndexBuffer(1,bdn);
   SetIndexBuffer(3,sdn);
   SetIndexBuffer(4,sup);
   SetIndexBuffer(5,marspax);
   
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
   
   SetIndexBuffer(6,PosBuffer);
   SetIndexBuffer(7,NegBuffer);
      
   IndicatorShortName(short_name);

   SetIndexDrawBegin(0,PAX);
   SetIndexDrawBegin(1,PAX);
   SetIndexDrawBegin(2,PAX);
   SetIndexDrawBegin(3,PAX);
   SetIndexDrawBegin(4,PAX);
   SetIndexDrawBegin(5,PAX);
   SetIndexDrawBegin(6,PAX);
   SetIndexDrawBegin(7,PAX);
//----

 drawLine(BuyTrigger,"BuyTrigger", BuyTriggerColor);
   drawLine(SellTrigger,"SellTrigger", SellTriggerColor );
   drawLine(MainTrendLong,"MainTrendLong", MainTrendLongColor );
   drawLine(MainTrendShort,"MainTrendShort",MainTrendShortColor );

   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   
  
   
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive;
//----
   if(Bars<=PAX) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=PAX;i++) PAXBuffer[Bars-i]=0.0;
//----
   i=Bars-PAX-1;
   int ma = i;
   if(counted_bars>=PAX) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double sumn=0.0,sump=0.0;
      if(i==Bars-PAX-1)
        {
         int k=Bars-2;
         //---- initial accumulation
         while(k>=i)
           {
               int h=k+1;
               double cma = (Open[k]+High[k]+Low[k]+Close[k])/4;
               double pma = (Open[h]+High[h]+Low[h]+Close[h])/4;
               
               rel=cma-pma;
               if(rel>0) sump+=rel;
            else      sumn-=rel;
            
            k--;
           }
         positive=sump/PAX;
         negative=sumn/PAX;
        }
      else
        {
         //---- smoothed moving average
         int j=i+1;
         double ccma = (Open[i]+High[i]+Low[i]+Close[i])/4;
         double ppma = (Open[j]+High[j]+Low[j]+Close[j])/4;

         rel=ccma-ppma;
         
         if(rel>0) sump=rel;
         else      sumn=-rel;
         positive=(PosBuffer[i+1]*(PAX-1)+sump)/PAX;
         negative=(NegBuffer[i+1]*(PAX-1)+sumn)/PAX;
        }
      PosBuffer[i]=positive;
      NegBuffer[i]=negative;
      if(negative==0.0) PAXBuffer[i]=0.0;
      else
      {
          PAXBuffer[i]=100.0-100.0/(1+positive/negative);
          
          bdn[i] = 0;
          bup[i] = 0;
          sdn[i] = 0;
          sup[i] = 0;
          
          if(PAXBuffer[i]>MainTrendLong)
          bup[i] = -10;
          
          if(PAXBuffer[i]<MainTrendShort)
          bdn[i] = -10;
          
          if(PAXBuffer[i]<20 && PAXBuffer[i]>PAXBuffer[i+1])
          sup[i] = -10;
          
          if(PAXBuffer[i]>80 && PAXBuffer[i]<PAXBuffer[i+1])
          sdn[i] = -10;
            
          
      }    
      i--;
     }
     
     while(ma>=0)
     {
         marspax[ma] = iMAOnArray(PAXBuffer,0,Ma_PAX,0,MODE_EMA,ma); 
         ma--;
     }    
     
//----
   return(0);
  }
//+------------------------------------------------------------------+
void drawLine(double lvl,string name, color Col )
{
       
            ObjectDelete(name);
            ObjectCreate(name, OBJ_HLINE, WindowFind(short_name), Time[0], lvl,Time[0],lvl);
            
            
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
            
            ObjectSet(name, OBJPROP_COLOR, Col);        
            ObjectSet(name,OBJPROP_WIDTH,1);
          
       
}



Sample





Analysis



Market Information Used:

Series array that contains close prices for each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Series array that contains open prices of each bar
Series array that contains open time of each bar


Indicator Curves created:


Implements a curve of type DRAW_LINE
Implements a curve of type DRAW_HISTOGRAM

Indicators Used:


Moving average indicator


Custom Indicators Used:
PAX

Order Management characteristics:

Other Features: