//+------------------------------------------------------------------+ //| TD DIFF.mq4 | //| Linuxser and Ign (2007) | //| Tom Demark DIFF indicator | //| From the book: New Market Timing Techniques | //| Copyright Đ 1998, Tom Demark | //| About Copyright, what you think?, Tom Demark is the creator, | //| he is the man behind the idea | //| I canīt put my name just for being the one who wrote the code. | //| I leave that task to others, I have ego but I recognize when | //| some thing is not mine. | //| Thanks Ignacio for help me with the code. | //| Linuxser (2007) | //+------------------------------------------------------------------+ #property copyright "Under The GNU General Public License" #property link "www.gnu.org" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 Blue //---- input parameters //---- buffers double UpSignalBuffer[]; double DownSignalBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicator buffers mapping SetIndexBuffer(0,UpSignalBuffer); SetIndexBuffer(1,DownSignalBuffer); //---- drawing settings SetIndexStyle(0,DRAW_ARROW,EMPTY,1); SetIndexArrow(0,241); SetIndexStyle(1,DRAW_ARROW,EMPTY,1); SetIndexArrow(1,242); //---- SetIndexEmptyValue(0,0.0); SetIndexEmptyValue(1,0.0); //---- name for DataWindow SetIndexLabel(2,"Signal Up"); SetIndexLabel(3,"Signal Down"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TODO: add your code here //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i,nCountedBars; nCountedBars=IndicatorCounted(); //---- check for possible errors if(nCountedBars<0 || Bars<5) return(-1); //---- i=Bars-nCountedBars-1; while(i>=0) { //----Calculations for Buy //Close(@) < Close(@)[-1] AND Close(@)[-1] < Close(@)[-2] AND Close(@) - Low(@) > Close(@)[-1] - Low(@)[-1] //AND True High(@) - Close(@) < True High(@)[-1]- Close(@)[-1] if(Close[i] (Close[i+1]-Low[i+1]) && (true_high(i) - Close[i]) < (true_high(i+1) - Close[i+1]) ) { UpSignalBuffer[i]= Low[i]-3*Point; } else { DownSignalBuffer[i]= EMPTY ; } //----Calculations for Sell //Close(@) > Close(@)[-1] AND Close(@)[-1] > Close(@)[-2] AND High(@) - Close(@) > High(@)[-1] - Close(@)[-1] AND Close(@) - True Low(@) < Close(@)[-1] - True Low(@)[-1] if(Close[i]>Close[i+1] && Close[i+1]>Close[i+2] && (High[i]-Close[i]) > (High[i+1]-Close[i+1]) && (Close[i] - true_low(i)) < (Close[i+1] - true_low(i+1)) ) { DownSignalBuffer[i]= High[i]+3*Point; } else { DownSignalBuffer[i]= EMPTY ; } i--; } //---- return(0); } //+------------------------------------------------------------------+ double true_high(int pos) { //high today or close yesterday whichever is greater (adjust for gap in other words) return ( MathMax(High[pos], Close[pos + 1]) ); } double true_low(int pos) { //high today or close yesterday whichever is greater (adjust for gap in other words) return ( MathMin(High[pos], Close[pos + 1]) ); }