//////////////////////////////////////////// // DIBA Indicator.mq4 // Mark Chaudhary // mark@phluffynet.com //////////////////////////////////////////// #property copyright "Mark Chaudhary" #property link "http://caveceteris.com" #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 Blue #property indicator_color2 Red // internal parameter int shift, nBars=1000; int length=4; // 4 bar indicator static double upperSlope, lowerSlope, hi[4], lo[4]; // indicator buffers double buySignal[]; double sellSignal[]; double slope1[]; double slope2[]; //////////////////////////////////////////// // Custom indicator initialization function //////////////////////////////////////////// int init(){ string short_name; SetIndexBuffer(0,buySignal); SetIndexBuffer(1,sellSignal); SetIndexBuffer(2,slope1); SetIndexBuffer(3,slope2); SetIndexStyle(0,DRAW_ARROW,2,1); SetIndexStyle(1,DRAW_ARROW,2,1); SetIndexStyle(2,12); SetIndexStyle(3,12); SetIndexArrow(0,241); SetIndexArrow(1,242); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); //DataWindow label short_name="DIBA("+length+")"; IndicatorShortName(short_name); SetIndexLabel(0,"DIBA BUY"); SetIndexLabel(1,"DIBA SELL"); SetIndexLabel(2,"SLOPE1"); SetIndexLabel(3,"SLOPE2"); SetIndexDrawBegin(0,length); SetIndexDrawBegin(1,length); return(0); } /////////////////// // DIBA Start /////////////////// int start(){ // Initialize Signal Buffers for (shift=nBars;shift>=0;shift--){ buySignal[shift]=0; sellSignal[shift]=0; } for (shift=nBars-length;shift>=1;shift--) if (arrowCondition()) { loadArraysAndGetSlopes(); if (buyCondition()){ Alert("DIBA BUY ",Symbol(),"-",Period()); buySignal[shift-1]=Low[shift-1]-200*Point; } else if (sellCondition()){ Alert("DIBA SELL ",Symbol(),"-",Period()); sellSignal[shift-1]=High[shift-1]+200*Point; } } return(0); } /////////////////////////////////////////////////////////////// // ArrowCondition - Determines if the Arrow pattern is present /////////////////////////////////////////////////////////////// bool arrowCondition(){ //bar 1 is an inside bar if (High[shift] < High[shift+1] && Low[shift] > Low[shift+1]) { //bar 2 is inside relative to bars 3 & 4 if (High[shift+1] < High[ArrayMaximum(High,4,shift)] && Low[shift+1] > Low[ArrayMinimum(Low,4,shift)]){ //high of bar 2 is below that of bar 3 && low of bar 2 is above low of bar 4 if (High[shift+1] < High[shift+2] && Low[shift+1] > Low[shift+3]) return (true); } } return (false); } ///////////////////////////////////////// // Buy Condition //////////////////////////////////////// bool buyCondition(){ if(Close[shift-1] > Close[shift] + slope1[shift]) return (true); else return (false); } ///////////////////////////////////////// // Sell Condition //////////////////////////////////////// bool sellCondition(){ if(Close[shift-1] < Close[shift] + slope2[shift]) return (true); else return (false); } /////////////////////////////////////////////////////////////////////////////////////////////////// // LoadArraysAndGetSlopes - Loads the last 4 highs and lows & calculating the 2 slopes of the arrow /////////////////////////////////////////////////////////////////////////////////////////////////// void loadArraysAndGetSlopes(){ //Alert("LOADING ARRAYS"); int upX1=0; int upX2=0; int loX1=0; int loX2=0; double highest,high2, lowest, low2; highest = High[shift]; lowest = Low[shift]; for (int j=0;j<4;j++){ hi[j] = High[shift+j]; lo[j] = Low[shift+j]; if (hi[j]>highest){ high2=highest; highest=hi[j]; upX2=upX1; upX1=j; } if(lo[j]