//+------------------------------------------------------------------+ //| Scratchs_PivotPoints.mq4 | //| Scratch | //| scratch85@nurfuerspam.de | //| | //| This work is licensed under a Creative Commons | //| Attribution-ShareAlike 3.0 Germany License. | //| http://creativecommons.org/licenses/by-sa/3.0/de/ | //+------------------------------------------------------------------+ #property copyright "Scratch" #property link "scratch85@nurfuerspam.de" #define PP_STANDARD 0 #define PP_WOODIE 1 #define PP_CAMARILLA 2 #define PP_FIBONACCI 3 string strEAName = "Scratchs_PivotPoints"; string strVersion = "20110508"; extern int iMode = 0; extern int iBasePeriod = PERIOD_D1; extern int iShift = 1; double a1dPP[]; double a1dR1[]; double a1dS1[]; double a1dR2[]; double a1dS2[]; double a1dR3[]; double a1dS3[]; #property indicator_chart_window #property indicator_buffers 7 #property indicator_color1 Silver #property indicator_color2 Red #property indicator_color3 Green #property indicator_color4 Red #property indicator_color5 Green #property indicator_color6 Red #property indicator_color7 Green //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { int i; IndicatorBuffers(7); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); IndicatorShortName(StringConcatenate(strEAName," ",strVersion," - ",iBasePeriod," (",Period(),") / ",iMode)); i = 0; SetIndexBuffer(i,a1dPP); SetIndexStyle(i,DRAW_LINE,0,2); SetIndexDrawBegin(i,1); i++; SetIndexBuffer(i,a1dR1); SetIndexStyle(i,DRAW_LINE,0,2); SetIndexDrawBegin(i,1); i++; SetIndexBuffer(i,a1dS1); SetIndexStyle(i,DRAW_LINE,0,2); SetIndexDrawBegin(i,1); i++; SetIndexBuffer(i,a1dR2); SetIndexStyle(i,DRAW_LINE,0,2); SetIndexDrawBegin(i,1); i++; SetIndexBuffer(i,a1dS2); SetIndexStyle(i,DRAW_LINE,0,2); SetIndexDrawBegin(i,1); i++; SetIndexBuffer(i,a1dR3); SetIndexStyle(i,DRAW_LINE,0,2); SetIndexDrawBegin(i,1); i++; SetIndexBuffer(i,a1dS3); SetIndexStyle(i,DRAW_LINE,0,2); SetIndexDrawBegin(i,1); if(iBasePeriod == 0) { iBasePeriod = Period(); } if(Period() > iBasePeriod) { iBasePeriod = Period(); } return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i; int iLimit; int iCountedBars = IndicatorCounted(); datetime dtBar; int iShifting; double dH,dL,dC; if(iCountedBars < 0) { return(-1); } if(iCountedBars > 0) { iCountedBars--; } iLimit = Bars - iCountedBars; for(i = 0;i < iLimit;i++) { if(iBasePeriod > Period()) { dtBar = MathFloor(Time[i] / iBasePeriod) * iBasePeriod; iShifting = iBarShift(Symbol(),iBasePeriod,dtBar,false); } else { iShifting = i; } dH = iHigh(Symbol(),iBasePeriod,iShifting + iShift); dL = iLow(Symbol(),iBasePeriod,iShifting + iShift); dC = iClose(Symbol(),iBasePeriod,iShifting + iShift); switch(iMode) { case PP_STANDARD: a1dPP[i] = (dH + dL + dC) / 3; a1dR1[i] = (2 * a1dPP[i]) - dL; a1dS1[i] = (2 * a1dPP[i]) - dH; a1dR2[i] = a1dPP[i] + (dH - dL); a1dS2[i] = a1dPP[i] - (dH - dL); a1dR3[i] = dH + (2 * (a1dPP[i] - dL)); a1dS3[i] = dL - (2 * (dH - a1dPP[i])); break; case PP_WOODIE: a1dPP[i] = (dH + dL + (2 * dC)) / 4; a1dR1[i] = (2 * a1dPP[i]) - dL; a1dS1[i] = (2 * a1dPP[i]) - dH; a1dR2[i] = a1dPP[i] + dH - dL; a1dS2[i] = a1dPP[i] - dH + dL; break; case PP_CAMARILLA: a1dPP[i] = (dH + dL + dC) / 3; a1dR1[i] = dC + ((dH - dL) * 1.0833); a1dS1[i] = dC - ((dH - dL) * 1.0833); a1dR2[i] = dC + ((dH - dL) * 1.1666); a1dS2[i] = dC - ((dH - dL) * 1.1666); a1dR3[i] = dC + ((dH - dL) * 1.2500); a1dS3[i] = dC - ((dH - dL) * 1.2500); //a1dR4[i] = dC + ((dH - dL) * 1.5000); //a1dS4[i] = dC - ((dH - dL) * 1.5000); break; case PP_FIBONACCI: a1dPP[i] = (dH + dL + dC) / 3; a1dR1[i] = a1dPP[i] + ((dH - dL) * 0.382); a1dS1[i] = a1dPP[i] - ((dH - dL) * 0.382); a1dR2[i] = a1dPP[i] + ((dH - dL) * 0.618); a1dS2[i] = a1dPP[i] - ((dH - dL) * 0.618); a1dR3[i] = a1dPP[i] + ((dH - dL) * 1.000); a1dS3[i] = a1dPP[i] - ((dH - dL) * 1.000); break; default: a1dPP[i] = (dH + dL + dC) / 3; a1dR1[i] = (2 * a1dPP[i]) - dL; a1dS1[i] = (2 * a1dPP[i]) - dH; a1dR2[i] = a1dPP[i] + (dH - dL); a1dS2[i] = a1dPP[i] - (dH - dL); a1dR3[i] = dH + 2 * (a1dPP[i] - dL); a1dS3[i] = dL - 2 * (dH - a1dPP[i]); break; } } return(0); } //+------------------------------------------------------------------+