//+------------------------------------------------------------------+ //| Gann high low activator.mq5 | //| mladen | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "www.forex-tsd.com" #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 1 #property indicator_label1 "Gann high low" #property indicator_type1 DRAW_COLOR_HISTOGRAM2 #property indicator_color1 DeepSkyBlue,PaleVioletRed #property indicator_width1 1 // // // // // input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame input int LookBack = 10; // Look back period // // // // // double gannBufferUp[]; double gannBufferDn[]; double colorBuffer[]; double countBuffer[]; double trend[]; // // // // ENUM_TIMEFRAMES timeFrame; int mtfHandle; bool calculating; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int OnInit() { SetIndexBuffer(0,gannBufferUp,INDICATOR_DATA); SetIndexBuffer(1,gannBufferDn,INDICATOR_DATA); SetIndexBuffer(2,colorBuffer ,INDICATOR_COLOR_INDEX); SetIndexBuffer(3,countBuffer ,INDICATOR_CALCULATIONS); // // // // // timeFrame = MathMax(_Period,TimeFrame); calculating = (timeFrame==_Period); if (!calculating) { string name = getIndicatorName(); mtfHandle = iCustom(NULL,timeFrame,name,PERIOD_CURRENT,LookBack); } IndicatorSetString(INDICATOR_SHORTNAME,periodToString(timeFrame)+" Gann high low activator("+string(LookBack)+")"); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // 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 &TickVolume[], const long &Volume[], const int &Spread[]) { // // // // // if (calculating) { if (ArraySize(trend)!=rates_total) ArrayResize(trend,rates_total); for (int i=(int)MathMax(prev_calculated-1,0); i 0) trend[i] = trend[i-1]; if (Close[i] > high) trend[i] = 1; if (Close[i] < low) trend[i] = -1; if (trend[i] == 1) colorBuffer[i]=0; if (trend[i] ==-1) colorBuffer[i]=1; gannBufferUp[i] = High[i]; gannBufferDn[i] = Low[i]; } countBuffer[rates_total-1] = MathMax(rates_total-prev_calculated+1,1); return(rates_total); } // // // // // datetime times[]; datetime startTime = Time[0]-PeriodSeconds(timeFrame); datetime endTime = Time[rates_total-1]; int bars = CopyTime(NULL,timeFrame,startTime,endTime,times); if (times[0]>Time[0] || bars<1) return(prev_calculated); double colors[]; CopyBuffer(mtfHandle,2,0,bars,colors); double counts[]; CopyBuffer(mtfHandle,3,0,bars,counts); int maxb = (int)MathMax(MathMin(counts[bars-1]*PeriodSeconds(timeFrame)/PeriodSeconds(Period()),rates_total-1),1); // // // // // for(int i=(int)MathMax(prev_calculated-maxb,0);i -1 && d < bars) { gannBufferUp[i] = High[i]; gannBufferDn[i] = Low[i]; colorBuffer[i] = colors[d]; } } return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // double iSma(const double& array[], int length, int i) { double avg = 0; for (int k=0; k=0; k++) avg += array[i-k]; return(avg/length); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int dateArrayBsearch(datetime& times[], datetime toFind, int total) { int mid = 0; int first = 0; int last = total-1; while (last >= first) { mid = (first + last) >> 1; if (toFind == times[mid] || (mid < (total-1) && (toFind > times[mid]) && (toFind < times[mid+1]))) break; if (toFind < times[mid]) last = mid - 1; else first = mid + 1; } return (mid); } // // // // // string getIndicatorName() { string progPath = MQL5InfoString(MQL5_PROGRAM_PATH); string terminalPath = TerminalInfoString(TERMINAL_PATH); int startLength = StringLen(terminalPath)+17; int progLength = StringLen(progPath); string indicatorName = StringSubstr(progPath,startLength); indicatorName = StringSubstr(indicatorName,0,StringLen(indicatorName)-4); return(indicatorName); } // // // // // string periodToString(int period) { int i; static int _per[]={1,2,3,4,5,6,10,12,15,20,30,0x4001,0x4002,0x4003,0x4004,0x4006,0x4008,0x400c,0x4018,0x8001,0xc001}; static string _tfs[]={"1 minute","2 minutes","3 minutes","4 minutes","5 minutes","6 minutes","10 minutes","12 minutes", "15 minutes","20 minutes","30 minutes","1 hour","2 hours","3 hours","4 hours","6 hours","8 hours", "12 hours","daily","weekly","monthly"}; if (period==PERIOD_CURRENT) period = Period(); for(i=0;i<20;i++) if(period==_per[i]) break; return(_tfs[i]); }