IBFXDailyPivots





//+------------------------------------------------------------------+
//|                                          IBFX - Daily Pivots.mq4 |
//|                                                  Patrick Nouvion |
//|                                       http://www.interbankfx.com |
//+------------------------------------------------------------------+
#property copyright "Patrick Nouvion"
#property link      "http://www.interbankfx.com"

#property indicator_chart_window
#property indicator_buffers 7

#property indicator_color1 Maroon
#property indicator_color2 Crimson
#property indicator_color3 Crimson
#property indicator_color4 OrangeRed
#property indicator_color5 Green
#property indicator_color6 Green
#property indicator_color7 DarkGreen

#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_DASH
#property indicator_style3 STYLE_DASH
#property indicator_style4 STYLE_SOLID
#property indicator_style5 STYLE_DASH
#property indicator_style6 STYLE_DASH
#property indicator_style7 STYLE_SOLID

#property indicator_width1 2
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 2
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 2

//---- Declare the arrays ...
double R3_0[], R2_0[], R1_0[], R0_5[], Pivot[], S1_0[], S2_0[], S3_0[];

double rates_d1[2][6];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {   
   CleanUp();
   //IndicatorBuffers(13);
   //---- Set Index Buffers / Set Index Labels
   SetIndexBuffer(  0 , R3_0);   SetIndexLabel(  0, "R3" );   SetIndexStyle( 0, DRAW_LINE, STYLE_SOLID, 2, Maroon );
   //SetIndexBuffer(  1 , R2_5);   SetIndexLabel(  1, "R2.5" ); SetIndexStyle( 1, DRAW_LINE, STYLE_DOT, 1, Orchid);
   SetIndexBuffer(  1 , R2_0);   SetIndexLabel(  1, "R2" );   SetIndexStyle( 1, 0, STYLE_DASH, 1, Crimson);
   //SetIndexBuffer(  3 , R1_5);   SetIndexLabel(  3, "R1.5" ); SetIndexStyle( 3, DRAW_LINE, STYLE_DOT, 1, Orchid);
   SetIndexBuffer(  2 , R1_0);   SetIndexLabel(  2, "R1" );   SetIndexStyle( 2, DRAW_LINE, STYLE_DASH, 1, Crimson);
   //SetIndexBuffer(  5 , R0_5);   SetIndexLabel(  5, "R0.5" ); SetIndexStyle( 5, DRAW_LINE, STYLE_DOT, 1, Orchid);
   SetIndexBuffer(  3 , Pivot);  SetIndexLabel(  3, "Pivot" );SetIndexStyle( 3, DRAW_LINE, STYLE_SOLID, 2, OrangeRed);
   //SetIndexBuffer(  7 , S0_5);   SetIndexLabel(  7, "S0.5" ); SetIndexStyle( 7, DRAW_LINE, STYLE_DOT, 1, LawnGreen);
   SetIndexBuffer(  4 , S1_0);   SetIndexLabel(  4, "S1" );   SetIndexStyle( 4, DRAW_LINE, STYLE_DASH, 1, Green);
   //SetIndexBuffer(  9 , S1_5);   SetIndexLabel(  9, "S1.5" ); SetIndexStyle( 9, DRAW_LINE, STYLE_DOT, 1, LawnGreen);
   SetIndexBuffer( 5 , S2_0);   SetIndexLabel( 5, "S2" );   SetIndexStyle( 5, DRAW_LINE, STYLE_DASH, 1, Green);
   //SetIndexBuffer( 11 , S2_5);   SetIndexLabel( 11, "S2.5" ); SetIndexStyle( 11, DRAW_LINE, STYLE_DOT, 1, LawnGreen);
   SetIndexBuffer( 6 , S3_0);   SetIndexLabel( 6, "S3" );   SetIndexStyle( 6, DRAW_LINE, STYLE_SOLID, 2, DarkGreen);
      
   //----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   CleanUp();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   ArrayCopyRates(rates_d1, Symbol(), PERIOD_D1);

   int offset = 0;
   if(DayOfWeek()==1) offset=1;
   
   int Precision = CheckPrecision();

   double yesterday_close = rates_d1[1+offset][4];
   double yesterday_open = rates_d1[1+offset][1];
   double yesterday_high = rates_d1[1+offset][3];
   double yesterday_low = rates_d1[1+offset][2];
   
   string StrR3Value = "";
   string StrR2Value = "";
   string StrR1Value = "";
   string StrPivotValue = "";
   string StrS1Value = "";
   string StrS2Value = "";
   string StrS3Value = "";
   
   int counted_bars=IndicatorCounted(); 
   if(counted_bars<0) { return(-1); } 
   if(counted_bars>0) { counted_bars--; }
   int Limit = Bars-counted_bars;
   
   for( int i = Limit; i > 0; i-- )
   {  
      Pivot[i] = ( yesterday_high + yesterday_low + yesterday_close ) / 3.0 ;
       R1_0[i] = ( 2.0 * Pivot[i] ) - yesterday_low;
       S1_0[i] = ( 2.0 * Pivot[i] ) - yesterday_high;
       R2_0[i] = Pivot[i] + ( R1_0[i] - S1_0[i] );
       S2_0[i] = Pivot[i] - ( R1_0[i] - S1_0[i] );
       R3_0[i] = ( 2.0 * Pivot[i] ) + ( yesterday_high - ( 2.0 * yesterday_low ) );
       S3_0[i] = ( 2.0 * Pivot[i] ) - ( ( 2.0 * yesterday_high ) - yesterday_low ); 
       //R0_5[i] = ( Pivot[i] + R1_0[i] ) / 2.0;
       //S0_5[i] = ( Pivot[i] + S1_0[i] ) / 2.0;
       //R1_5[i] = (  R1_0[i] + R2_0[i] ) / 2.0;
       //S1_5[i] = (  S1_0[i] + S2_0[i] ) / 2.0;
       //R2_5[i] = (  R2_0[i] + R3_0[i] ) / 2.0;
       //S2_5[i] = (  S2_0[i] + S3_0[i] ) / 2.0;
       
       StrR3Value = DoubleToStr( R3_0[i], Precision );
       StrR2Value = DoubleToStr( R2_0[i], Precision );
       StrR1Value = DoubleToStr( R1_0[i], Precision );
       StrPivotValue = DoubleToStr( Pivot[i], Precision );
       StrS1Value = DoubleToStr( S1_0[i], Precision );
       StrS2Value = DoubleToStr( S2_0[i], Precision );
       StrS3Value = DoubleToStr( S3_0[i], Precision );
       
   }
   
   
   ObjectMakeLabel( "R3", 70, 10, 0);
     ObjectSetText( "R3", "R3 - " , 10, "Arial Bold", Maroon);
   ObjectMakeLabel( "R3Value", 30, 10, 0);
     ObjectSetText( "R3Value", StrR3Value , 10, "Arial ", Maroon);
   
   ObjectMakeLabel( "R2", 70, 25, 0);
     ObjectSetText( "R2", "R2 - " , 10, "Arial Bold", Crimson);
   ObjectMakeLabel( "R2Value", 30, 25, 0);
     ObjectSetText( "R2Value", StrR2Value , 10, "Arial ", Crimson);
     
   ObjectMakeLabel( "R1", 70, 40 , 0);
     ObjectSetText( "R1", "R1 - " , 10, "Arial Bold", Crimson);
   ObjectMakeLabel( "R1Value", 30, 40, 0);
     ObjectSetText( "R1Value", StrR1Value , 10, "Arial ", Crimson);
     
   ObjectMakeLabel( "Pivot", 70, 55, 0);
     ObjectSetText( "Pivot", "Pivot - " , 10, "Arial Bold", OrangeRed);
   ObjectMakeLabel( "PivotValue", 30, 55, 0);
     ObjectSetText( "PivotValue", StrPivotValue , 10, "Arial ", OrangeRed);
     
   ObjectMakeLabel( "S1", 70, 70, 0);
     ObjectSetText( "S1", "S1 - " , 10, "Arial Bold", Green);
   ObjectMakeLabel( "S1Value", 30, 70, 0);
     ObjectSetText( "S1Value", StrS1Value , 10, "Arial ", Green);
  
   ObjectMakeLabel( "S2", 70, 85, 0);
     ObjectSetText( "S2", "S2 - " , 10, "Arial Bold", Green);
   ObjectMakeLabel( "S2Value", 30, 85, 0);
     ObjectSetText( "S2Value", StrS2Value , 10, "Arial ", Green);
  
   ObjectMakeLabel( "S3", 70, 100, 0);
     ObjectSetText( "S3", "S3 - " , 10, "Arial Bold", DarkGreen);
   ObjectMakeLabel( "S3Value", 30, 100, 0);
     ObjectSetText( "S3Value", StrS3Value , 10, "Arial ", DarkGreen);
     
//----
   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
int ObjectMakeLabel( string n, int xoff, int yoff, int WindowToUse ){
   ObjectCreate( n, OBJ_LABEL, WindowToUse, 0, 0 );
   ObjectSet( n, OBJPROP_CORNER, 1 );
   ObjectSet( n, OBJPROP_XDISTANCE, xoff );
   ObjectSet( n, OBJPROP_YDISTANCE, yoff );
   ObjectSet( n, OBJPROP_BACK, true );
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
void CleanUp()
{
   ObjectDelete("R3");
   ObjectDelete("R2");
   ObjectDelete("R1");
   ObjectDelete("Pivot");
   ObjectDelete("S1");
   ObjectDelete("S2");
   ObjectDelete("S3");
   
   ObjectDelete("R3Value");
   ObjectDelete("R2Value");
   ObjectDelete("R1Value");
   ObjectDelete("PivotValue");
   ObjectDelete("S1Value");
   ObjectDelete("S2Value");
   ObjectDelete("S3Value");
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
int CheckPrecision()
{
   if( StringFind( Symbol(), "JPY", 0) != -1 ) { return(2); }
   else                                        { return(4); }
}  
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:



Indicator Curves created:

Implements a curve of type DRAW_LINE

Implements a curve of type 0

Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: