//+------------------------------------------------------------------+ //| 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 Green #property indicator_style2 STYLE_SOLID #property indicator_width2 2 //--- plot buffer 3 #property indicator_label3 "R1" #property indicator_type3 DRAW_LINE #property indicator_color3 Red #property indicator_style3 STYLE_SOLID #property indicator_width3 2 //--- 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, }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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_H4)) { 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;i