//+------------------------------------------------------------------+
//|                                                       WPR-CB.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, zznbrm"
#property indicator_chart_window

//---- input parameters
extern int    eintPeriod = 14;
extern double edblLevel = -80.0;
extern int    eintArrowCode = SYMBOL_RIGHTPRICE;
extern int    eintArrowWidth = 1;
extern int    eintArrowOffset = 1;
extern color  eclrDefault = White;
extern color  eclrAbove = Lime;
extern color  eclrBelow = Red;

string gstrArrowName;
string gstrDesc;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{                  
   gstrArrowName = "WPR-CB-Price" + DoubleToStr( edblLevel, 1 );
   gstrDesc = DoubleToStr( edblLevel, 1 ) + " Level";
   IndicatorShortName( "WPR-CB" );   
   SetIndexLabel( 0, NULL );
   return( 0 );
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   ObjectDelete( gstrArrowName );
   return( 0 );
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{    
   double dblPrice = getPrice();   
   color clr = eclrDefault;
   
   if ( Close[0] > dblPrice )            clr = eclrAbove;
   else if ( Close[0] < dblPrice )       clr = eclrBelow;
      
   drawArrow( gstrArrowName, eintArrowCode, clr, dblPrice, eintArrowWidth, gstrDesc );          
   return( 0 );
}

//+------------------------------------------------------------------+
//| getPrice                                                         |
//+------------------------------------------------------------------+
double getPrice()
{
   double dblHigh = High[ArrayMaximum( High, eintPeriod, 0 )];
   double dblLow = Low[ArrayMinimum( Low, eintPeriod, 0 )];   
   double dblPrice = dblHigh - ( ( edblLevel / (-100.0) ) * ( dblHigh - dblLow ) );
  
   return( dblPrice );
}

//+------------------------------------------------------------------+
//| drawArrow                                                        |
//+------------------------------------------------------------------+
void drawArrow( string strName, int intCode, color clr, double dblPrice, int intWidth, string strDesc )
{
   if ( ObjectFind( strName ) == -1 )
   {
      ObjectCreate( strName, OBJ_ARROW, 0, Time[0]+(eintArrowOffset*Period()*60), dblPrice );
      ObjectSet( strName, OBJPROP_ARROWCODE, intCode );      
      ObjectSet( strName, OBJPROP_WIDTH, intWidth );    
      ObjectSetText( strName, strDesc );  
   }
   else
   {
      ObjectMove( strName, 0, Time[0]+(eintArrowOffset*Period()*60), dblPrice ); 
   }
        
   ObjectSet( strName, OBJPROP_COLOR, clr );
}





