Volatility_Pivot_mtf





//+------------------------------------------------------------------+
//|       RisenbergVolatilityCapture      aka   Volatility.Pivot.mq4 |
//|mtf 2008forextsd.com    ki                                        |
//+------------------------------------------------------------------+
#property copyright "thanks to S.B.T. (Japan)"//RisenbergVolatilityCapture
#property link      "http://sufx.core.t3-ism.net/" //<<< convert this from VT, thanks mate !!!
//----
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DarkOrchid
//---- input parameters
extern double     atr_range=100;
extern double     ima_range=10;
extern double     atr_factor=3;
extern bool       atr_Mode = true;
extern double     DeltaPrice=30;
//extern int MaxBarsToCount   = 500;
extern int TimeFrame = 0;
extern string  TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
string  IndicatorFileName;


//---- buffers
double TrStop[];
double ATR[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2);
//---- indicators
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, TrStop);
//   SetIndexStyle(1, DRAW_NONE);
   SetIndexBuffer(1, ATR);
//----
   string short_name="RVC("+ima_range+"|"+atr_factor+")["+TimeFrame+"]"; 
   IndicatorShortName(short_name);
   SetIndexLabel(0,"range base ["+TimeFrame+"]("+ima_range+"|"+atr_factor+")");
 
   IndicatorFileName = WindowExpertName();
   if (TimeFrame < Period()) TimeFrame = Period();

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int      limit,i;
   if(counted_bars < 0) return(-1);
  limit = Bars-counted_bars;
//  limit= MathMin(limit,MaxBarsToCount);

   if (TimeFrame != Period())
      {
          limit = MathMax(limit,TimeFrame/Period());

         datetime TimeArray[];
        ArrayCopySeries(TimeArray ,MODE_TIME ,NULL,TimeFrame);
           for(i=0,int y=0; i<limit; i++)
           {
           if(Time[i]<TimeArray[y]) y++;
  TrStop[i]=iCustom(NULL,TimeFrame,IndicatorFileName,atr_range,ima_range,atr_factor,atr_Mode,DeltaPrice,0,y);
           }
         return(0);         
      }

 //  int counted_bars=IndicatorCounted();
 //  int limit;
 //  int i;
//----
   double DeltaStop;
//----
//   limit=Bars;

     for(i=0; i < limit; i ++) 
     {
      ATR[i]=iATR(NULL,0,atr_range,i);
     }
     for(i=limit - 1; i>=0; i --) 
     {
        if (atr_Mode) 
        {
         DeltaStop=iMAOnArray(ATR,0,ima_range,0,MODE_EMA,i) * atr_factor;
         //DeltaStop = iATR(NULL,0,atr_range,i) * atr_factor;
         }
          else 
         {
         DeltaStop=DeltaPrice*Point;
        }
        if (Close[i]==TrStop[i + 1]) 
        {
         TrStop[i]=TrStop[i + 1];
         }
          else 
         {
           if (Close[i+1]<TrStop[i+1] && Close[i]<TrStop[i+1]) 
           {
            TrStop[i]=MathMin(TrStop[i + 1], Close[i] + DeltaStop);
            }
             else 
            {
              if (Close[i+1]>TrStop[i+1] && Close[i]>TrStop[i+1]) 
              {
               TrStop[i]=MathMax(TrStop[i+1], Close[i] - DeltaStop);
               }
                else 
               {
               if (Close[i] > TrStop[i+1]) TrStop[i]=Close[i] - DeltaStop; else TrStop[i]=Close[i] + DeltaStop;
              }
           }
        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

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


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:


Indicator of the average true range
Moving average indicator


Custom Indicators Used:
IndicatorFileName

Order Management characteristics:

Other Features: