Divergence/ Convergence

[Deleted]  
I would like to update my code so that my EA can detect divergence/convergence between price and momentum. My idea goes something like  this:   Have three variables, macda, macdb and macdc. Macda would be on the current bar ie 0 shift, macdb on a 1 bar shift and macdc on a 2 bar shift . A peak would occur when macdb<macdc and macda (when current macd is below 0) and when macdb>macda and macdc (when current macd is above 0.) Another variable would need to be implemented and a value assigned to it when a peak occurred and i understand that this would need to be an array variable, lets call it peak[x] where x will increase each time a peak occurs and peak[x] = macdb. Divergence would occur when the current peak > the previous peak (when current macd is below 0) and when current peak < the previous peak (when current macd is above 0.)  i.e peak[x] > peak[x-1] and macdb <0 or peak[x] < peak[x-1] and macdb >0. I have attached a sample of my code where i have tried to implement this theory however it does not genereate any buy or sell signals. Does any body know what i am doing wrong and how to adjust the code to make it work.?                                                                                                                                                                                                                                                                                          
 

"Does any body know what i am doing wrong "

Uh, probably forgetting to do something important...

 

In order for somebody to help you, you need to attach the sample code or insert it in your message.

Regards...

[Deleted]  
Please find code attached below.
Files:
 

Try again.

for(int pos=0; pos<=sum; pos++) { OrderSelect(pos,SELECT_BY_POS,MODE_TRADES); if(OrderSymbol()==Symbol() && OrderMagicNumber()==Expert_ID)continue; int totalpeaks=10; for (int x=0; x<=totalpeaks; x++) { if((macdb<0 && macdb<=macda && macdb<=macdc)||(macdb>0 && macdb>=macda && macdb>=macdc)) peak[x]=macdb; { if (x>0 && peak[x]>peak[x-1] && peak[x]<0 && peak[x-1]<0 && MacdCurrent>SignalCurrent && MacdPrevious<=SignalPrevious && MacdCurrent<0 ) { //---- open a BUY position if (OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-stoploss*Points, Ask+TakeProfit*Points,"macd sample",Expert_ID,0,Red ) < 0 ) { _GetLastError = GetLastError(); Alert( "Error OrderSend # ", _GetLastError ); return(-1); } return(0); } } { //---- if the MACD has met the zero line top-down, if (x>0 && peak[x]0 && peak[x-1]>0 && MacdCurrent=SignalPrevious && MacdCurrent>0) { //---- open a SELL position if (OrderSend(Symbol(), OP_SELL, Lots,Bid,3,Bid+stoploss*Points,Bid-TakeProfit*Points,"macd sample", Expert_ID,0, Red ) < 0 ) { _GetLastError = GetLastError(); Alert( "Error OrderSend # ", _GetLastError ); return(-1); } return(0); } } } return(0); } }