Navigation:Home > Content >

Trix_-_signals.mq4

Time: 2012-08-17 | Download file:Trix_-_signals.mq4

//+------------------------------------------------------------------+
//|                                                   Trix Clean.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "www.forex-tsd.com"
#property link      "www.forex-tsd.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2

//
//
//
//
//

extern int  TrixPeriod      = 14;
extern int  TrixPrice       = PRICE_CLOSE;
extern int  SignalPeriod    =  0;
extern int  SignalMethod    =  3;
extern bool alertsOn        = true;
extern bool alertsOnCurrent = true;
extern bool alertsMessage   = true;
extern bool alertsSound     = false;
extern bool alertsEmail     = false;

//
//
//
//
//

double TrixBuffer[];
double SignBuffer[];
double EmaBuffer1[];
double EmaBuffer2[];
double EmaBuffer3[];
double trend[];
double arrowUp[];
double arrowDn[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   IndicatorBuffers(8);
   SetIndexBuffer(0,arrowUp); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,159);
   SetIndexBuffer(1,arrowDn); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,159);
   SetIndexBuffer(2,TrixBuffer);
   SetIndexBuffer(3,SignBuffer);
   SetIndexBuffer(4,EmaBuffer1);
   SetIndexBuffer(5,EmaBuffer2);
   SetIndexBuffer(6,EmaBuffer3);
   SetIndexBuffer(7,trend);

   //
   //
   //
   //
   //

   IndicatorShortName("Trix ("+TrixPeriod+","+SignalPeriod+")");
   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
   double alpha = 2.0/(1.0+TrixPeriod);
   int    counted_bars=IndicatorCounted();
   int    limit,i;

   if(counted_bars < 0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit  = MathMin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //

   for(i=limit; i>=0; i--)
   {
      double price = iMA(NULL,0,1,0,MODE_SMA,TrixPrice,i);
         EmaBuffer1[i] = EmaBuffer1[i+1]+alpha*(price        -EmaBuffer1[i+1]);
         EmaBuffer2[i] = EmaBuffer2[i+1]+alpha*(EmaBuffer1[i]-EmaBuffer2[i+1]);
         EmaBuffer3[i] = EmaBuffer3[i+1]+alpha*(EmaBuffer2[i]-EmaBuffer3[i+1]);
         
         if (EmaBuffer3[i+1]!=0)
              TrixBuffer[i] = 100*(EmaBuffer3[i]-EmaBuffer3[i+1])/EmaBuffer3[i+1];
         else TrixBuffer[i] = 0.00;
   }   
   for (i=limit;i>=0;i--)
   {
      if (SignalPeriod>1)
            SignBuffer[i] = iMAOnArray(TrixBuffer,0,SignalPeriod,0,SignalMethod,i);
      else  SignBuffer[i] = 0;
      
      //
      //
      //
      //
      //
      
      arrowUp[i] = EMPTY_VALUE;
      arrowDn[i] = EMPTY_VALUE;
      trend[i]   = trend[i+1];
         if (TrixBuffer[i]>SignBuffer[i]) trend[i] =  1;
         if (TrixBuffer[i]        

Recommend