//+------------------------------------------------------------------+ //| ATRStops_v1_HTF.mq5 | //| Copyright © 2006, NNN | //+------------------------------------------------------------------+ //--- Copyright #property copyright "Copyright © 2006, " //--- A link to the author's site #property link "" #property description "ATRStops_v1 indicator from any timeframe" //--- The indicator version #property version "1.00" //--- The indicator is drawn in the main window #property indicator_chart_window //--- 4 buffers are used for the indicator #property indicator_buffers 4 //--- 4 graphical constructions are used #property indicator_plots 4 //+----------------------------------------------+ //| Parameters of the bullish indicator | //+----------------------------------------------+ //--- Indicator 1 is drawn as a line #property indicator_type1 DRAW_LINE //--- Blue is used for the indicator line color #property indicator_color1 clrBlue //--- Solid line is used for indicator 1 #property indicator_style1 STYLE_SOLID //--- The width of the indicator 1 is 2 #property indicator_width1 2 //--- The label of the indicator #property indicator_label1 "Upper ATRStops_v1" //+----------------------------------------------+ //| Parameters of the bearish indicator | //+----------------------------------------------+ //--- Indicator 2 is drawn as a line #property indicator_type2 DRAW_LINE //--- IndianRed is used for the indicator line color #property indicator_color2 clrIndianRed //--- Solid line is used for indicator 2 #property indicator_style2 STYLE_SOLID //--- The width of the indicator 2 is 2 #property indicator_width2 2 //--- The label of the indicator #property indicator_label2 "Lower ATRStops_v1" //+----------------------------------------------+ //| Parameters of the bullish indicator | //+----------------------------------------------+ //--- Indicator 3 is drawn as a symbol #property indicator_type3 DRAW_ARROW //--- RoyalBlue is used for the indicator line color #property indicator_color3 clrRoyalBlue //--- The width of the indicator 3 is 4 #property indicator_width3 4 //--- The label of the indicator #property indicator_label3 "Buy ATRStops_v1" //+----------------------------------------------+ //| Parameters of the bearish indicator | //+----------------------------------------------+ //--- Indicator 4 is drawn as a symbol #property indicator_type4 DRAW_ARROW //--- DarkOrange is used for the indicator line color #property indicator_color4 clrDarkOrange //--- The width of the indicator 4 is 4 #property indicator_width4 4 //--- The label of the indicator #property indicator_label4 "Sell ATRStops_v1" //+----------------------------------------------+ //| Declaring constants | //+----------------------------------------------+ #define RESET 0 // A constant for returning a command to recalculate the indicator to the terminal //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input ENUM_TIMEFRAMES TimeFrame=PERIOD_H6; // Chart period of the iSAR indicator input uint Length=10; // Period of the indicator input uint ATRPeriod=5; // Period of the ATR indicator input double Kv=2.5; // Volatility by ATR input int Shift=0; // Horizontal shift of the indicator in bars //+----------------------------------------------+ //--- Declaring dynamic arrays that further will be used as indicator buffers double ExtMapBufferUp[]; double ExtMapBufferDown[]; double ExtMapBufferUp1[]; double ExtMapBufferDown1[]; //--- Declaring a variable for storing the indicator initialization result bool Init; string Symbol_; //--- Declaring integer variables for the indicator handles int Ind_Handle; //--- Declaring integer variables of the start of data calculation int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { Init=true; //--- Checking correctness of the chart periods if(TimeFramerates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator { limit=rates_total-min_rates_total-2; // starting index for the calculation of all bars LastCountBar=limit; } else limit=int(LastCountBar)+rates_total-prev_calculated; // starting index for the calculation of new bars //--- indexing elements in arrays as in timeseries ArraySetAsSeries(time,true); //--- main cycle of calculation of the indicator for(bar=limit; bar>=0 && !IsStopped(); bar--) { //--- Zero out the contents of the indicator buffers for the calculation ExtMapBufferUp[bar]=EMPTY_VALUE; ExtMapBufferDown[bar]=EMPTY_VALUE; ExtMapBufferUp1[bar]=EMPTY_VALUE; ExtMapBufferDown1[bar]=EMPTY_VALUE; //--- Copy new data to the iTime array if(CopyTime(Symbol_,TimeFrame,time[bar],1,iTime)<=0) return(RESET); if(time[bar]>=iTime[0] && time[bar+1]