Navigation:Home > Content >

trendmanagerwithbuffet.mq4

Time: 2012-08-21 | Download file:trendmanagerwithbuffet.mq4

//+------------------------------------------------------------------+
//|                                                    trendmanager.mq4 |
//|            Copyright © 2005, Paul Heap, [email protected] |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Paul Heap"
#property link      "http://www.easyforexsignals.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue

extern int TM_Period = 7;
extern int TM_Shift = 2;
extern int MinADX = 20;
extern bool filterRSI = true;

double SpanA_Buffer[];
double SpanB_Buffer[];

double BufferBuySignals[];
double BufferSellSignals[];

int a_begin;

int init()
{
   a_begin=TM_Shift;
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(0,SpanB_Buffer);
   SetIndexDrawBegin(0,TM_Period+a_begin-1);
   SetIndexLabel(0,"TM_Period+");
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(1,SpanA_Buffer);
   SetIndexDrawBegin(1,TM_Period+a_begin-1);
   SetIndexLabel(1,"TM_Period");
   
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexBuffer(2,BufferBuySignals);
   SetIndexArrow(2,233); 
   SetIndexLabel(0,"BUY");
   
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexBuffer(3,BufferSellSignals);
   SetIndexArrow(3,234); 
   SetIndexLabel(0,"SELL");

   return(0);
}

int start()
{
   int    i,k;
   int    counted_bars=IndicatorCounted();
   double high,low,price;

   if(Bars<=TM_Period) return(0);
   if(counted_bars<1)
   {
      for(i=1;i<=TM_Period;i++) 
      {
         SpanA_Buffer[Bars-i]=0;
         SpanB_Buffer[Bars-i]=0;
         BufferBuySignals[Bars-i]=0;
         BufferSellSignals[Bars-i]=0;
      }
   }

   i=Bars-TM_Period;
   if(counted_bars>TM_Period) i=Bars-counted_bars-1;
   while(i>=0)
   {
      high=High[i]; low=Low[i]; k=i-1+TM_Period;
      while(k>=i)
      {
         price=High[k];
         if(highprice)  low=price;
         k--;
      }
      SpanA_Buffer[i]  = (high+low)/2.0;
      SpanB_Buffer[i]  = SpanA_Buffer[i+TM_Shift];
      
      if (SpanA_Buffer[i] !=  SpanB_Buffer[i]) {
         if ((SpanA_Buffer[i] >  SpanB_Buffer[i]) && (SpanA_Buffer[i+1] <=  SpanB_Buffer[i+1])) {
            if ((CheckSAR(i)==true)|| (CheckSAR(i+1)==true)) {
               BufferBuySignals[i]=SpanA_Buffer[i];
            }
         }
         else   if ((SpanA_Buffer[i] <  SpanB_Buffer[i]) && (SpanA_Buffer[i+1] >=  SpanB_Buffer[i+1])) {
            if ((CheckSAR(i)==true) || (CheckSAR(i+1)==true)) {
            BufferSellSignals[i]=SpanA_Buffer[i];
            }
         }
      }
      i--;
   }

   return(0);
}


bool CheckAdx(int i) {
   double adx = iADX(Symbol(),Period(), 14, PRICE_CLOSE, MODE_MAIN,i);
   if (adx >= MinADX) {
      return(true);
   }
   else {
   return(false);
   }
}


bool CheckSAR(int i) {          
     double sar = iSAR(Symbol(),Period(),0.09,0.2, i);
     double lastsar = iSAR(Symbol(),Period(),0.09,0.2, i+1);           
               

   if  ((sar > High[i]) && (lastsar < High[i+1])){
      if (ConfirmonFasterChart(i,true, 240) == true ) {
        return(true);
       }
    }
   else
    {
        return(false);     
    }     
       // long
   if  ((sar < Low[i]) && (lastsar >  Low[i+1])){
      if (ConfirmonFasterChart(i,false, 240) == true ) {
           return(false);
        }
     }
    else
     {
       return(false);
     }               
      return(false);
   }
  


// here we have to look at the faster charts to work out if we have support there
// which means the sar must be on the right side
bool ConfirmonFasterChart(int shift, bool isashort, int UsePeriod) {
   return(true);   
   int fastperiod, superfastperiod;   
   fastperiod = 1;
   superfastperiod = 1;
   
   if (UsePeriod == 5) {
   fastperiod = 1;
   superfastperiod = 1;
   }
   
   if (UsePeriod == 15) {
   fastperiod = 5;
   superfastperiod = 1;
   }
   
   if (UsePeriod == 30) {
   fastperiod = 15;
   superfastperiod = 1;
   }
   
   if (UsePeriod == 60) {
   fastperiod = 15;
   superfastperiod = 1;
   }
   
   if (UsePeriod == 240) {
   fastperiod = 15;
   superfastperiod = 1;
   }
   
     double fastsar = iSAR(Symbol(),fastperiod,0.09,0.2, shift);
     double superfastsar = iSAR(Symbol(),superfastperiod,0.09,0.2, shift);
     // double lastfastsar = iSAR(Symbol(),fastperiod,0.09,0.2, shift+1);
    
    // double lastfastsar = iSAR(Symbol(),fastperiod,0.09,0.2, shift+1);     
     if (isashort == true) {
         if  ((fastsar > Low[shift]) && (superfastsar > Low[shift])) {
            return(true);
         }
         else
         {
            return(false);
         }
     }
     else
     {
         if  ((fastsar < High[shift]) && (fastsar < High[shift])){
            return(true);
         }
         else
         {
            return(false);
         }
     }
}

Recommend