Navigation:Home > Content >

ATRstopLine.mq4

Time: 2011-12-21 | Download file:ATRstopLine.mq4

//+------------------------------------------------------------------+
//|                                                  ATRstopLine.mq4 |
//|                                                                  |
//|                                                          by Raff |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"

#property indicator_chart_window
#property  indicator_buffers 1
#property  indicator_color1  Aqua
#property  indicator_width1  2

//---- parameters
extern int    ATR_TimeFrame = 1440;
extern int    ATR_Period = 50;
extern double Factor = 0.5;
extern double Dividor = 5;
extern int    Entry_Bar = 22;
extern bool   Long = true;
extern bool   HiLoPrice = false;
//---- buffers
double ExtMapBuffer1[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(4);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(0,DRAW_LINE);
   return(0);
  }

//+------------------------------------------------------------------+
//| ATRstopLine                                                      |
//+------------------------------------------------------------------+
int start()
  {
int i;
double ATRval = Factor * iATR(NULL,ATR_TimeFrame,ATR_Period,0);
double PriceHigh;
double PriceLow;
double PriceHigh2;
double PriceLow2;

if (Long==true)
{
      ExtMapBuffer1[Entry_Bar]= Low[Entry_Bar] - ATRval;
      for( i=Entry_Bar-1;i>=0;i--)
      {
        PriceHigh=Close[i];
        PriceLow=Close[i];
        PriceHigh2=Close[i+1];
        PriceLow2=Close[i+1];
        if (HiLoPrice==true)
        {
          PriceHigh=High[i];
          PriceLow=Low[i];
          PriceHigh2=High[i+1];
          PriceLow2=Low[i+1];
        }

         if (PriceHigh <= PriceHigh2)
         ExtMapBuffer1[i]= ExtMapBuffer1[i+1];
         else
         {
         if (ExtMapBuffer1[i+1] >= PriceHigh - ATRval)
            ExtMapBuffer1[i] = ExtMapBuffer1[i+1];
         else    
            ExtMapBuffer1[i]= PriceHigh - ATRval;
         }
      if (Dividor>0) if( MathAbs(ExtMapBuffer1[i]-ExtMapBuffer1[i+1]) < ATRval/Dividor ) ExtMapBuffer1[i]=ExtMapBuffer1[i+1];
      }   
}   
else
{
      ExtMapBuffer1[Entry_Bar]= High[Entry_Bar] + ATRval;
      for( i=Entry_Bar-1;i>=0;i--)
      { 
        PriceHigh=Close[i];
        PriceLow=Close[i];
        PriceHigh2=Close[i+1];
        PriceLow2=Close[i+1];
        if (HiLoPrice==true)
        {
          PriceHigh=High[i];
          PriceLow=Low[i];
          PriceHigh2=High[i+1];
          PriceLow2=Low[i+1];
        }

         if (PriceLow >= PriceLow2)
         ExtMapBuffer1[i]= ExtMapBuffer1[i+1];
         else
         {
         if(ExtMapBuffer1[i+1] <= PriceLow + ATRval)
            ExtMapBuffer1[i]=ExtMapBuffer1[i+1];
         else
            ExtMapBuffer1[i]= PriceLow + ATRval;
         }
      if (Dividor>0) if( MathAbs(ExtMapBuffer1[i]-ExtMapBuffer1[i+1]) < ATRval/Dividor ) ExtMapBuffer1[i]=ExtMapBuffer1[i+1];
      }
}       
      
   return(0);
  }
//+------------------------------------------------------------------+

Recommend