Navigation:Home > Content >

ATR_Pivots_Lnx_v3.mq4

Time: 2010-08-22 | Download file:ATR_Pivots_Lnx_v3.mq4

//+------------------------------------------------------------------+
//|   Original Indicator Auto-Pivot Plotter Labels.mq4 Elton Treloar |
//|           I called this one Pivot Point Medians + GMT correction |
//|                                         and was made by Linuxser |
//|  Thanks to Rosh form metaquotes forum for fix the redraw problem |
//|  April 2008                                                      |
//|                                               Linuxser, May 2008 |
//|                                                                  |
//+------------------------------------------------------------------+
//|                                              Written by Linuxser |   
//|                                       http://www.linuxser.com.ar |                               
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"
#define IND_NAME "ATR Pivot Points "
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 C'255,200,100'
#property indicator_color2 C'133,211,166'
#property indicator_color3 C'255,200,100'
#property indicator_color4 C'133,211,166'
#property indicator_color5 C'255,200,100'
#property indicator_color6 C'133,211,166'
#property indicator_color7 C'255,200,100'
#property indicator_color8 C'133,211,166'

//---- input parameters
extern int       perATR=21;
extern int       StartHour=0;
extern int       StartMinute=0;
extern int       HistoryDays=15;
extern int       AtrPeriod = PERIOD_D1;
/*+----------------------------------------------------+
 MyPeriod = Period in minutes to consideration, could be:
 1440 for D1
 60 for H1
 240 for H4
 1 for M1
 15 for M15
 30 for M30
 5 for M5
 43200 for MN1
 10080 for W1
 +-------------------------------------------------------*/
extern int  Formula= 0;
/*+----------------------------------------------------+
 Formula = Calculation Method, could be:
 0 for (High+Low+Close)/3
 1 for (Open+High+Low+Close)/4
 2 for Close only
 3 for Open only

 +-------------------------------------------------------*/
extern color     LabelColor=C'0,0,0';
extern int       fontsize=8;
extern bool      Showlabels = true;
extern int       LabelShiftToRight =10;
double           DaysToPlot;
int nDigits;
//---- buffers
double R3Buffer[];
double R2Buffer[];
double R1Buffer[];
double R0Buffer[];
double S0Buffer[];
double S1Buffer[];
double S2Buffer[];
double S3Buffer[];


string Pivot="Pivot",Sup0="S 0", Res0="R 0",Sup1="S 1", Res1="R 1";
string Sup2="S 2", Res2="R 2", Sup3="S 3", Res3="R 3";

datetime LabelShiftTime;

double LastRedraw = 0;

double P,R,S,S0,R0,S1,R1,S2,R2,S3,R3;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,EMPTY);
   SetIndexStyle(1,DRAW_LINE,EMPTY);
   SetIndexStyle(2,DRAW_LINE,EMPTY);
   SetIndexStyle(3,DRAW_LINE,EMPTY);
   SetIndexStyle(4,DRAW_LINE,EMPTY);
   SetIndexStyle(5,DRAW_LINE,EMPTY);
   SetIndexStyle(6,DRAW_LINE,EMPTY);
   SetIndexStyle(7,DRAW_LINE,EMPTY);
   SetIndexBuffer(0,S0Buffer);
   SetIndexBuffer(1,R0Buffer);
   SetIndexBuffer(2,S1Buffer);
   SetIndexBuffer(3,R1Buffer);
   SetIndexBuffer(4,S2Buffer);
   SetIndexBuffer(5,R2Buffer);
   SetIndexBuffer(6,S3Buffer);
   SetIndexBuffer(7,R3Buffer);
   SetIndexLabel(0,NULL);
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,NULL);
   SetIndexLabel(4,NULL);
   SetIndexLabel(5,NULL);
   SetIndexLabel(6,NULL);
   SetIndexLabel(7,NULL);
   
   IndicatorShortName(IND_NAME);
   
   if(Symbol()=="GBPJPY" || Symbol()=="EURJPY" || Symbol()=="USDJPY" || Symbol()=="GOLD" || Symbol()=="USDMXN") nDigits = 2;
   if(Symbol()=="GBPUSD" || Symbol()=="EURUSD" || Symbol()=="NZDUSD" || Symbol()=="USDCHF"  ||
   Symbol()=="USDCAD" || Symbol()=="AUDUSD" || Symbol()=="EURUSD" || Symbol()=="EURCHF"  || Symbol()=="EURGBP"
   || Symbol()=="EURCAD" || Symbol()=="EURAUD" || Symbol()=="AUDNZD")nDigits = 4;
//----

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----

   ObjectDelete("PBRes3");
   ObjectDelete("PBRes2");
   ObjectDelete("PBRes1");
   ObjectDelete("PBRes0");
   ObjectDelete("PBSup0");
   ObjectDelete("PBSup1");
   ObjectDelete("PBSup2");
   ObjectDelete("PBSup3");   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted(); 
  
//---- exit if period is greater than daily charts
    if(Period() > 240)
   {
   Print("Error - Chart period is greater than 1 day.");
   return(-1); // then exit
   }
  
//---- indicator calculation

{
   if (counted_bars==0)
   if(counted_bars<0) return(-1);
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   
   
}

   int limit=Bars-counted_bars;
   int StartMinutesIntoDay=(StartHour*60)+StartMinute; // 8' o'clock x 60 = 480
   int CloseMinutesIntoDay=StartMinutesIntoDay-Period(); //
   
   if (DaysToPlot>Bars) DaysToPlot=Bars;
   DaysToPlot = HistoryDays*1440/Period();
   SetIndexDrawBegin(0,Bars-DaysToPlot);
   SetIndexDrawBegin(1,Bars-DaysToPlot);
   SetIndexDrawBegin(2,Bars-DaysToPlot);
   SetIndexDrawBegin(3,Bars-DaysToPlot);
   SetIndexDrawBegin(4,Bars-DaysToPlot);
   SetIndexDrawBegin(5,Bars-DaysToPlot);
   SetIndexDrawBegin(6,Bars-DaysToPlot);
   SetIndexDrawBegin(7,Bars-DaysToPlot);
   // ****************************************************
   //    Check That cloes time isn't now a negative number.
   //    Correct if it is by adding a full day's worth 
   //    of minutes.
   // ****************************************************
   
   if (CloseMinutesIntoDay<0)
      {
         CloseMinutesIntoDay=CloseMinutesIntoDay+1440;
      }
      
   // ****************************************************
   //    Establish the nuber of bars in a day.
   // ****************************************************
   int BarsInDay=1440/Period();
    
   // ******************************************************************************************
   // ******************************************************************************************
   //                                        Main Loop                                      
   // ******************************************************************************************
   // ******************************************************************************************
   
   for(int i=0; iPreviousHigh) PreviousHigh=High[SearchHighLow];
         if (Low[SearchHighLow] 1)          
         {
   
         ObjectCreate("PBSup0", OBJ_TEXT, 0, LabelShiftTime, 0);   
         ObjectSetText("PBSup0", "PB L0 " +DoubleToStr(S0,nDigits),fontsize,"Trebuchet MS",LabelColor);         
         ObjectSet("PBSup0",OBJPROP_BACK,1);
         ObjectMove("PBSup0", 0, LabelShiftTime,S0);
         ObjectCreate("PBRes0", OBJ_TEXT, 0, LabelShiftTime, 0);   
         ObjectSetText("PBRes0", "PB U0 " +DoubleToStr(R0,nDigits),fontsize,"Trebuchet MS",LabelColor);
         ObjectSet("PBRes0",OBJPROP_BACK,1);
         ObjectMove("PBRes0", 0, LabelShiftTime,R0);  
         ObjectCreate("PBSup1", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("PBSup1", "PB L1 " +DoubleToStr(S1,nDigits),fontsize,"Trebuchet MS",LabelColor);
         ObjectSet("PBSup1",OBJPROP_BACK,1);
         ObjectMove("PBSup1", 0, LabelShiftTime,S1);
         ObjectCreate("PBRes1", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("PBRes1", "PB U1 " +DoubleToStr(R1,nDigits),fontsize,"Trebuchet MS",LabelColor);
         ObjectSet("PBRes1",OBJPROP_BACK,1);
         ObjectMove("PBRes1", 0, LabelShiftTime,R1);
         ObjectCreate("PBSup2", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("PBSup2", "PB L2 " +DoubleToStr(S2,nDigits),fontsize,"Trebuchet MS",LabelColor);
         ObjectSet("PBSup2",OBJPROP_BACK,1);
         ObjectMove("PBSup2", 0, LabelShiftTime,S2);
         ObjectCreate("PBRes2", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("PBRes2", "PB U2 " +DoubleToStr(R2,nDigits),fontsize,"Trebuchet MS",LabelColor);
         ObjectSet("PBRes2",OBJPROP_BACK,1);
         ObjectMove("PBRes2", 0, LabelShiftTime,R2);
         ObjectCreate("PBSup3", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("PBSup3", "PB L3 " +DoubleToStr(S3,nDigits),fontsize,"Trebuchet MS",LabelColor);
         ObjectSet("PBSup3",OBJPROP_BACK,1);
         ObjectMove("PBSup3", 0, LabelShiftTime,S3);
         ObjectCreate("PBRes3", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("PBRes3", "PB U3 " +DoubleToStr(R3,nDigits),fontsize,"Trebuchet MS",LabelColor);  
         ObjectSet("PBRes3",OBJPROP_BACK,1);
         ObjectMove("PBRes3", 0, LabelShiftTime,R3);
      
         ObjectsRedraw(); 
         LastRedraw = TimeLocal();
         }
         
         }
   
      
}  
}
    R3Buffer[i]=R3;
    R2Buffer[i]=R2;
    R1Buffer[i]=R1;
    R0Buffer[i]=R0;
    S0Buffer[i]=S0; 
    S1Buffer[i]=S1;
    S2Buffer[i]=S2;
    S3Buffer[i]=S3;
    
   }
      // Extra1[i]=OpenPriceAt+i;

      //   **********************************************
      //      Calculate the mid-levels in to the buffers. 
      //      (for mid-levels version)
      //   **********************************************(Twe)
      // Res1[i] =((R1-P)/2)+P;    //M3
      // Res2[i] =((R2-R1)/2)+R1;  //M4
      // Res3[i] =((R3-R2)/2)+R2;  
      // Supp1[i]=((P-S1)/2)+S1;   //M2
      // Supp2[i]=((S1-S2)/2)+S2;  //M1
      // Supp3[i]=((S2-S3)/2)+S3;


       //End of 'DaysToPlot 'if' statement.
     
      // ***************************************************************************************
      //                            End of Main Loop
      // ***************************************************************************************
  

   // *****************************************
   //    Return from Start() (Main Routine)
   return(0);
  
  }
//+-------------------------------------------------------------------------------------------------------+
//  END Custom indicator iteration function
//+-------------------------------------------------------------------------------------------------------+


// *****************************************************************************************
// *****************************************************************************************
// -----------------------------------------------------------------------------------------
//    The following routine will use "StartingBar"'s time and use it to find the 
//    general area that SHOULD contain the bar that matches "TimeToLookFor"
// -----------------------------------------------------------------------------------------
int FindLastTimeMatchFast(int TimeToLookFor,int StartingBar)
   {
   int StartingBarsTime=(TimeHour(Time[StartingBar])*60)+TimeMinute(Time[StartingBar]);
   
   // ***************************************************
   //    Check that our search isn't on the otherside of 
   //    the midnight boundary and correct for calculations
   // ***************************************************
   if (StartingBarsTime0)
      {
        for (int SearchCount=SuggestedBar ;SearchCount>(SuggestedBar-DeltaBarFound-2) ;SearchCount--)
            {
            // ******************************************************************************
            //    Find time (in minutes) of the current bar AND the two bars either side of it.
            // This is done to allow for any missing bars in the data.   i.e. If THE bar you 
            // were after were to be missing you'd never get a valid close/open time.  
            //    This is the same reason for searching rather than just looking back a certain
            // number of bars from the close time. Missing bars upset the count back and 
            // screw up all pivot calculations. There is still room for error but it's improved.
            // The best calculations will come from having the best data. ...of course. :)
            // ******************************************************************************
            //
            int PreviousBarsTime=(TimeHour(Time[SearchCount+1])*60)+TimeMinute(Time[SearchCount+1]);
            int CurrentBarsTime=(TimeHour(Time[SearchCount])*60)+TimeMinute(Time[SearchCount]);
            int NextBarsTime=(TimeHour(Time[SearchCount-1])*60)+TimeMinute(Time[SearchCount-1]);
      
            if (CurrentBarsTime==TimeToLookFor)
               {
               return(SearchCount);    // *** If current bar is what we are after than lets get out.
                                 // *** without mucking about with the rest of the checks.
               }
      
            // **********************************
            //    Check that previous bar doesn't
            // lay on a different day.
            //    Adjust if it is
            // **********************************
            if(PreviousBarsTime>CurrentBarsTime)  
               {                                       
               PreviousBarsTime=PreviousBarsTime-1440;
               }
            // **********************************
            //    Check that following bar doesn't
            // lay on a different day. 
            //    Adjust if it is.
            // **********************************
            if(NextBarsTime        

Recommend