//+------------------------------------------------------------------+ //| SupportResistance.mq5 | //| Copyright 2021, ernst | //| https://www.mql5.com/en/users/pippod | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, ernst" #property link "https://www.mql5.com/en/users/pippod" #property version "1.00" #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 2 //--- plot Res #property indicator_label1 "Resistance" #property indicator_type1 DRAW_LINE #property indicator_color1 clrPaleGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Sup #property indicator_label2 "Support" #property indicator_type2 DRAW_LINE #property indicator_color2 clrTomato #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- indicator buffers double ResBuffer[]; double SupBuffer[]; double UpperBuffer[]; double LowerBuffer[]; int handle=INVALID_HANDLE; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- if((handle=iFractals(_Symbol,_Period))==INVALID_HANDLE) return(INIT_FAILED); //--- indicator buffers mapping SetIndexBuffer(0,ResBuffer,INDICATOR_DATA); SetIndexBuffer(1,SupBuffer,INDICATOR_DATA); SetIndexBuffer(2,UpperBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(3,LowerBuffer,INDICATOR_CALCULATIONS); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- const int toCopy=(prev_calculated<1)?rates_total:(rates_total!=prev_calculated)?rates_total-prev_calculated+2:3; //--- if(CopyBuffer(handle,0,0,toCopy,UpperBuffer)!=toCopy || CopyBuffer(handle,1,0,toCopy,LowerBuffer)!=toCopy) return(0); //--- const int begin=(prev_calculated<1)?3:(rates_total!=prev_calculated)?prev_calculated-2:prev_calculated-3; //--- for(int i=begin;i