Why the rise and fall of the macd histogram can not be detected correctly?

 

Dear all,
  I have write a simplified version of MACD to show the rise and fall of the MACD historgram(the difference of the MACD line and the macd signal line). I use the following code to show a 1 to indicate the historgram is rising , a -1 to indicate the historgram value is falling.the histupdn[] is the buffer used to be shown 
  for(i=1; i<limit; i++){
    if(hist[i]<hist[i-1]) histupdn[i]=1;
    if(hist[i]>hist[i-1]) histupdn[i]=-1;
 }



But the result it not as what I expected whatever I expected no matter how hard I tried. As shown in the figure below, the histogram value is falling, but the histupdn[] value is always 1.The upper part is a normal chart. the middle part of the figure is the output of a normal MACD indicator. The lower part of the figure is the output to indicate the rise and fall of the MACD histogram.

The output of the histupdn[] is incorrect between A and B. 

the code that I used to show the MACD histogram is attached for some nice man to check it up....
Many thanks for your time and efforts, and your prompt reply.

 
tzm:

Dear all,
  I have write a simplified version of MACD to show the rise and fall of the MACD historgram(the difference of the MACD line and the macd signal line). I use the following code to show a 1 to indicate the historgram is rising , a -1 to indicate the historgram value is falling.the histupdn[] is the buffer used to be shown 



But the result it not as what I expected whatever I expected no matter how hard I tried. As shown in the figured below, the histogram value is falling, but the histupdn[] value is always 1.

 

the code that I used to show the MACD histogram is attached for some nice man to check it up....
Many thanks for your time and efforts, and your prompt reply.

"Always in motion the future is."
 
angevoyageur: "Always in motion the future is."
If Yoda's so smart, speak good English why can't he?
You're off topic. :D
 
tzm: But the result it not as what I expected
 ArrayResize(diff,limit+2);
  ArrayResize(dea,limit+2);
  ArrayResize(hist,limit+2);
  for(int i=0; i<limit; i++) diff[i]=iMA(..
  for(i=0; i<limit; i++) dea[i]=iMAOnArray(diff,Bars,SignalSMA,0,MODE_SMA,i);
  1. After the first time, limit is 1, so diff is 3 elements. How can you do a SignalSMA (9) period SMA on 3 elements?
  2. Drop those arrayResize's and make them indicator buffers.
  3. The decrement counted is not necessary
  4. Don't look at the future
     for(i=1; i<limit; i++){
        if(hist[i]>hist[i-1]) histupdn[i]=1;
        if(hist[i]<hist[i-1]) histupdn[i]=-1;
     for(i=0; i<limit; i++){
        if(hist[i]>hist[i+1]) histupdn[i]=1;
        else                  histupdn[i]=-1;
  5. Get in the habit of counting down.
 
WHRoeder:
If Yoda's so smart, speak good English why can't he?
You're off topic. :D

;-)
 
WHRoeder:
  1. After the first time, limit is 1, so diff is 3 elements. How can you do a SignalSMA (9) period SMA on 3 elements?
  2. Drop those arrayResize's and make them indicator buffers.
  3. The decrement counted is not necessary
  4. Don't look at the future
  5. Get in the habit of counting down.

Dear  WHRoeder:

Thank you for your prompt reply. After following the instructions in  your reply. I got the expected result.