Price Increment

Author: Copyright 2017, Denis Glaz
Price Data Components
Series array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Price Increment
ÿþ//+------------------------------------------------------------------+

//|                                               PriceIncrement.mq4 |

//|                                       Copyright 2017, Denis Glaz |

//|                        https://www.mql5.com/en/users/georgewilde |

//+------------------------------------------------------------------+

#property copyright "Copyright 2017, Denis Glaz"

#property link      "https://www.mql5.com/en/users/georgewilde"

#property version   "1.00"

#property strict

#property indicator_separate_window

#property indicator_buffers 2



//+------------------------------------------------------------------+

//| Indicator properties                                             |

//+------------------------------------------------------------------+

#property indicator_color1 DarkGreen //Line color

#property indicator_color2 Maroon //Line color







double Buf_0[];

double Buf_1[];





enum style_enum

{

   style0 = 0, //LOGARITHM

   style1 = 1, //PERCENT

   style2 = 2, //ABSOLUTE

};





input style_enum   style  = style0;   //Style







//+------------------------------------------------------------------+

//| Custom indicator (de)initialization function                     |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexStyle(0,DRAW_HISTOGRAM, STYLE_SOLID, 2);

   SetIndexBuffer(0,Buf_0);

   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 2);

   SetIndexBuffer(1,Buf_1);

   

   Print("Indicator loaded successfully");

//---

   return(0);

  }

  

  

int deinit()

  {

//----

//----

   return(0);

  }

  

  

    

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int start()

{   

   int Counted_bars;

   int Process_bars;

   int i;

   double signal;



   

   Process_bars = Bars - 2;

   

   if (IndicatorCounted() == 0)

      Counted_bars = IndicatorCounted();    

   else

      Counted_bars = IndicatorCounted() - 1;   

   i = Process_bars-Counted_bars;           

   

   

   while(i >= 0)

   {

      signal = iPInc(_Period, i);      

      if(signal > 0)

      {

         Buf_0[i] = signal; //green

         Buf_1[i] = 0; //clear another bufer

      }

      else

      {

         Buf_1[i] = signal; //red

         Buf_0[i] = 0; 

      }

         

      i--;  

   }

 

   return(0);

}







double iPInc(int TF, int index) //indicator function - input timeframe and index of bar.

{

   double answer;

   

   double close_now;

   double close_prev;

   

   close_now = iClose(Symbol(), TF, index);

   close_prev = iClose(Symbol(), TF, index + 1);

   

   if (style == style0)

      answer = (log(close_now) - log(close_prev)) * 100;

   else if (style == style1)

      answer = (close_now / close_prev * 100) - 100;

   else

      answer = (close_now - close_prev) / Point;

   

   return answer;

}

Comments