//+------------------------------------------------------------------+ //| PivotPointUniversal.mq5 | //| Copyright VDV Soft | //| vdv_2001@mail.ru | //+------------------------------------------------------------------+ #property copyright "VDV Soft" #property link "vdv_2001@mail.ru" #property version "1.00" #property description "Classical pivot levels." #property indicator_chart_window #define count_buffers 9 #property indicator_buffers count_buffers #property indicator_plots count_buffers //--- plot buffer 1 #property indicator_label1 "Pivot" #property indicator_type1 DRAW_LINE #property indicator_color1 Orange #property indicator_style1 STYLE_DOT #property indicator_width1 2 //--- plot buffer 2 #property indicator_label2 "S1" #property indicator_type2 DRAW_LINE #property indicator_color2 Purple #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot buffer 3 #property indicator_label3 "R1" #property indicator_type3 DRAW_LINE #property indicator_color3 Purple #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- plot buffer 4 #property indicator_label4 "S2" #property indicator_type4 DRAW_LINE #property indicator_color4 DodgerBlue #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- plot buffer 5 #property indicator_label5 "R2" #property indicator_type5 DRAW_LINE #property indicator_color5 DodgerBlue #property indicator_style5 STYLE_SOLID #property indicator_width5 1 //--- plot buffer 6 #property indicator_label6 "S3" #property indicator_type6 DRAW_LINE #property indicator_color6 DarkGreen #property indicator_style6 STYLE_SOLID #property indicator_width6 1 //--- plot buffer 7 #property indicator_label7 "R3" #property indicator_type7 DRAW_LINE #property indicator_color7 DarkGreen #property indicator_style7 STYLE_SOLID #property indicator_width7 1 //--- plot buffer 8 #property indicator_label8 "S4" #property indicator_type8 DRAW_LINE #property indicator_color8 DarkGreen #property indicator_style8 STYLE_SOLID #property indicator_width8 1 //--- plot buffer 9 #property indicator_label9 "R4" #property indicator_type9 DRAW_LINE #property indicator_color9 DarkGreen #property indicator_style9 STYLE_SOLID #property indicator_width9 1 //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum PivotType { PIVOT_CLASSIC=0, PIVOT_FIBONACCI=1, PIVOT_DEMARK=2, PIVOT_CAMARILLA=3, PIVOT_WOODIES=4 }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum inptime { TIME_TRADE_SERVER, TIME_GMT }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum inpperiod { DAY, WEEKLY, MONTHLY }; input PivotType InpPivotType=PIVOT_CLASSIC; //Pivot type input inpperiod InpPeriod=DAY; // Period input inptime InpTime=TIME_TRADE_SERVER; //Time //---- buffers double PBuffer[]; double S1Buffer[]; double R1Buffer[]; double S2Buffer[]; double R2Buffer[]; double S3Buffer[]; double R3Buffer[]; double S4Buffer[]; double R4Buffer[]; // Global variable int ShiftTime; // Displacement of the buffer for construction of levels in the future //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { // Displacement of the buffer for construction of levels in the future string period; string shiftGMT=" TRADE SERVER "; switch(InpPeriod) { case DAY: //--- Verify Time Period if(PeriodSeconds(_Period)>=PeriodSeconds(PERIOD_H2)) { return(-1); } period="(DAY)"; shiftGMT=(InpTime==TIME_GMT)?" GMT ":" TRADE SERVER "; ShiftTime=int((TimeTradeServer()-TimeGMT())/PeriodSeconds(_Period))+int(PeriodSeconds(PERIOD_D1)/PeriodSeconds(_Period)); break; case WEEKLY: //--- Verify Time Period if(PeriodSeconds(_Period)>=PeriodSeconds(PERIOD_D1)) { return(-1); } period="(WEEKLY)"; ShiftTime=int((TimeTradeServer()-TimeGMT())/PeriodSeconds(_Period))+int(PeriodSeconds(PERIOD_W1)/PeriodSeconds(_Period)); break; case MONTHLY: //--- Verify Time Period if(PeriodSeconds(_Period)>=PeriodSeconds(PERIOD_MN1)) { return(-1); } period="(MONTHLY)"; ShiftTime=int((TimeTradeServer()-TimeGMT())/PeriodSeconds(_Period))+int(PeriodSeconds(PERIOD_MN1)/PeriodSeconds(_Period)); break; } IndicatorSetString(INDICATOR_SHORTNAME,"PivotPoint"+period+shiftGMT+"time"); //--- indicator buffers mapping SetIndexBuffer(0,PBuffer,INDICATOR_DATA); SetIndexBuffer(1,S1Buffer,INDICATOR_DATA); SetIndexBuffer(2,R1Buffer,INDICATOR_DATA); SetIndexBuffer(3,S2Buffer,INDICATOR_DATA); SetIndexBuffer(4,R2Buffer,INDICATOR_DATA); SetIndexBuffer(5,S3Buffer,INDICATOR_DATA); SetIndexBuffer(6,R3Buffer,INDICATOR_DATA); SetIndexBuffer(7,S4Buffer,INDICATOR_DATA); SetIndexBuffer(8,R4Buffer,INDICATOR_DATA); IndicatorSetInteger(INDICATOR_DIGITS,_Digits); for(int i=0;iOpenDay) pivot=2*HighDay+LowDay+CloseDay; if(CloseDay==OpenDay) pivot=HighDay+LowDay+2*CloseDay; support1=pivot/2-HighDay; resistance1=pivot/2-LowDay; pivot=EMPTY_VALUE; support2=EMPTY_VALUE; support3=EMPTY_VALUE; support4=EMPTY_VALUE; resistance2=EMPTY_VALUE; resistance3=EMPTY_VALUE; resistance4=EMPTY_VALUE; break; case PIVOT_CAMARILLA: range=HighDay-LowDay; pivot=EMPTY_VALUE; support1=CloseDay-range*1.1/12; support2=CloseDay-range*1.1/6; support3=CloseDay-range*1.1/4; support4=CloseDay-range*1.1/2; resistance1=range*1.1/12+CloseDay; resistance2=range*1.1/6+CloseDay; resistance3=range*1.1/4+CloseDay; resistance4=range*1.1/2+CloseDay; break; case PIVOT_WOODIES: range=HighDay-LowDay; pivot=(HighDay+LowDay+2*CloseDay)/4; support1=2*pivot-HighDay; support2=pivot-HighDay+LowDay; support3=EMPTY_VALUE; support4=EMPTY_VALUE; resistance1=2*pivot-LowDay; resistance2=pivot+HighDay-LowDay; resistance3=EMPTY_VALUE; resistance4=EMPTY_VALUE; break; } shift=Index-ShiftTime+int(shiftGMT/PeriodSeconds(_Period)); for(int i=0;i<=shift_end;i++) { PBuffer[shift+i]=pivot; S1Buffer[shift+i]=support1; S2Buffer[shift+i]=support2; S3Buffer[shift+i]=support3; S4Buffer[shift+i]=support4; R1Buffer[shift+i]=resistance1; R2Buffer[shift+i]=resistance2; R3Buffer[shift+i]=resistance3; R4Buffer[shift+i]=resistance4; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double LineY(int Index,double StartY,double EndY,int StartX,int EndX) { double LINH=StartY*(Index-EndX)/(StartX-EndX)+EndY*(Index-StartX)/(EndX-StartX); return(LINH); } //+------------------------------------------------------------------+