enum ENUM_PIVOT_POINT { PIVOT_POINT_NONE = 0, PIVOT_POINT_MAIN = 1, PIVOT_POINT_R1 = 2, PIVOT_POINT_R2 = 3, PIVOT_POINT_S1 = 4, PIVOT_POINT_S2 = 5 }; //---- double DayLowest (int shiftdays) { return iLow(Symbol(),PERIOD_D1,shiftdays); } double DayHighest (int shiftdays) { return iHigh(Symbol(),PERIOD_D1,shiftdays); } double DayClose (int shiftdays) { return iClose(Symbol(),PERIOD_D1,shiftdays); } double DayOpen (int shiftdays) { return iOpen(Symbol(),PERIOD_D1,shiftdays); }
double Pivot (ENUM_PIVOT_POINT p, int shift=1) { double plow = DayLowest(shift); double phigh = DayHighest(shift); double pclose = DayClose(shift); double pmain = (plow + phigh + pclose) /3; switch (p) { case PIVOT_POINT_MAIN: return pmain; case PIVOT_POINT_R1: return (pmain*2)-plow; case PIVOT_POINT_R2: return pmain + (phigh-plow); case PIVOT_POINT_S1: return (pmain*2)-phigh; case PIVOT_POINT_S2: return pmain - (phigh-plow); default: return 0; } }
Some snippets of my extended symbol class which you can modify for your needs.
Enjoy
Doerk
Hello Doerk,
Thank you for the reply and the code. I have one question though. Can I make the changes in order to apply this code to any date? Thank you again for your help.
Trader07:
Hello Doerk,
Thank you for the reply and the code. I have one question though. Can I make the changes in order to apply this code to any date? Thank you again for your help.
Yes.
You have to deal with iBarShift(). This function returns the amount of candles you need to shift back to a specific date. Like this:
datetime datesearch=D'2015.02.01'; int nbars = iBarShift(Symbol(),PERIOD_D1,datesearch); double pivotmain=Pivot(PIVOT_POINT_MAIN,nbars);
Thank you very much for the help. It's greatly appreciated.
You´re welcome.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello Fellow Members,
I had a question concerning pivot points and data history. All pivot point indicators I find for MT4 only allow for the pivots to be applied to the current day. I wanted to do some backtesting using pivots points but I’ve had to calculate them by hand and use the horizontal line tool to see what they were for dates in the past.
Is it possible to create an indicator that allows you to apply pivot points to a specific date? Say I’m reviewing a years’ worth of data and I want to apply the pivots to a specific date to see how they performed. Is that possible?
Thanking you in advance for any and all help.