Indicators: MACD Divergence - page 2

 

Hi Alain,

thank you for providing this nice indicator.

I have a little problem though. I am trying to implement it in an EA and have issues copying the buffer and getting a meaningful value to create a signal.

Buffer 0 and 1 are the buffers that give out a value as soon as a divergence is detected. When there is no divergence those buffers don't give a value back in data window.

So far so good, but when I copy both buffers the value that is given back is always a the same for both buffers and does not reflect the value given back in the data window.

This is how I copy the buffer:

         if(CopyBuffer(macddiv_handle,0,1,1,macddiv_value1)<0 || CopyBuffer(macddiv_handle,1,1,1,macddiv_value2)<0)
            {
               Alert("Error Copying Buffer macddivergence - error:",GetLastError());
               ResetLastError();
               return;
            }     

Afterwards I just Print the values to the journal and get these strange results for every candle:

2013.11.18 13:33:36    2013.01.02 02:20:00   val2: 1.797693134862316e+308
2013.11.18 13:33:36    2013.01.02 02:20:00   val1: 1.797693134862316e+308
2013.11.18 13:33:36    2013.01.02 02:15:00   val2: 1.797693134862316e+308
2013.11.18 13:33:36    2013.01.02 02:15:00   val1: 1.797693134862316e+308
2013.11.18 13:33:36    2013.01.02 02:10:00   val2: 1.797693134862316e+308
2013.11.18 13:33:36    2013.01.02 02:10:00   val1: 1.797693134862316e+308

Can you help me to get a meaningful value?

 
Klammeraffe:

Hi Alain,

thank you for providing this nice indicator.

I have a little problem though. I am trying to implement it in an EA and have issues copying the buffer and getting a meaningful value to create a signal.

Buffer 0 and 1 are the buffers that give out a value as soon as a divergence is detected. When there is no divergence those buffers don't give a value back in data window.

So far so good, but when I copy both buffers the value that is given back is always a the same for both buffers and does not reflect the value given back in the data window.

This is how I copy the buffer:

Afterwards I just Print the values to the journal and get these strange results for every candle:

2013.11.18 13:33:36    2013.01.02 02:20:00   val2: 1.797693134862316e+308
2013.11.18 13:33:36    2013.01.02 02:20:00   val1: 1.797693134862316e+308
2013.11.18 13:33:36    2013.01.02 02:15:00   val2: 1.797693134862316e+308
2013.11.18 13:33:36    2013.01.02 02:15:00   val1: 1.797693134862316e+308
2013.11.18 13:33:36    2013.01.02 02:10:00   val2: 1.797693134862316e+308
2013.11.18 13:33:36    2013.01.02 02:10:00   val1: 1.797693134862316e+308

Can you help me to get a meaningful value?

It's a meaningful value, it corresponds to EMPTY_VALUE which equals DBL_MAX by default. It's a good practice to use it for indicator's buffer value who don't have to be drawn on the chart.

You can manage it the following way in your EA :

if(macddiv_value1[index] != EMPTY_VALUE) ...
 
angevoyageur:

It's a meaningful value, it corresponds to EMPTY_VALUE which equals DBL_MAX by default. It's a good practice to use it for indicator's buffer value who don't have to be drawn on the chart.

You can manage it the following way in your EA :

Thank you for your help. It's much appreciated!

Okay, I was looking for !=0.

However the problem is, that even the candles that produce signals give out this value even though the data window gives out another one.


   if (entry_signal==2)
      {
         Print("val1: ",macddiv_value1[0]);
         Print("val2: ",macddiv_value2[0]);
         
         buy_condition_1 = macddiv_value1[0] != EMPTY_VALUE;
         
         sell_condition_1 = macddiv_value2[0] != EMPTY_VALUE; 
      }
 
Klammeraffe:

Thank you for your help. It's much appreciated!

Okay, I was looking for !=0.

However the problem is, that even the candles that produce signals give out this value even though the data window gives out another one.


Where is the value of val2 at 2013.01.02 13:50:00 in your log ? It doesn't show.
 
angevoyageur:
Where is the value of val2 at 2013.01.02 13:50:00 in your log ? It doesn't show.

That's a good question. I haven't noticed it. But this is exactly the value that is missing to produce is a signal, isn't it?

Because value2 is the value of buffer 1 which shows the bearish divergence.

Strange.

 
Klammeraffe:

That's a good question. I haven't noticed it. But this is exactly the value that is missing to produce is a signal, isn't it?

Because value2 is the value of buffer 1 which shows the bearish divergence.

Strange.

Yes weird. Anyway, did you read this "useless answer" above in the topic ?

Forum

Indicators: MACD Divergence

angevoyageur, 2013.11.05 19:14

So friendly.

The signal is given at closing of a candle, 1 candle in the past (2 if you count open candle and not 3). It's normal and it's how it have to work. Divergence is based on research of extremum (top/bottom). If you have a way to detect an extremum on the current candle, I suggest you to learn programming and provide us, for free, this great innovation.

Thank you for your input.

I let you read it, understand it, and use it to fix your code. If you don't found I will give you the answer tomorrow 
 
angevoyageur:

Yes weird. Anyway, did you read this "useless answer" above in the topic ?

I let you read it, understand it, and use it to fix your code. If you don't found I will give you the answer tomorrow 
I did not. But that answer isn't useless at all. Thank you for your help. I fixed it :)
 

What is the MACD Indicator? How do I use it? (based on dailyforex article)

One of the most common technical indicators that is used by day traders in the financial markets can be seen in the Moving Average Convergence Divergence -- more commonly referred to as the MACD. But one mistake that many new traders make is that they will simply start using this indicator without really understanding how it functions or makes its calculations. This can lead to costly mistakes that should have been completely avoidable. So, it makes sense to study the logic and calculations behind the MACD (and all other indicators) in order to more accurately configure your day trading positions and generate gains on a consistent basis.




The Moving Average Convergence Divergence (MACD) Defined

Anyone with any experience in the forex markets and in technical analysis strategies has likely heard a great deal about the Moving Average Convergence Divergence (MACD). But what exactly does the MACD tell us -- and how is it calculated? Without an understanding of these areas, it can be difficult to see trading signals as they emerge. Here, will deconstruct the MACD indicator and explain how and why it is commonly used.

“In its most basic form,” said Haris Constantinou, markets analyst, “the MACD is a momentum indicator that is designed to follow existing trends and find new ones.” The MACD does this by showing the differences and relationships between a two-level combination of moving averages and price activity itself.

MACD Calculations

To determine and calculate the MACD, we must subtract a 26 period Exponential Moving Average (EMA) from a 12 period EMA. Then, a 9 period EMA of the MACD is plotted, and this becomes the Signal Line for the indicator. The Signal Line is plotted over the MACD and this will be used as the trigger reading for trading signals (both buy signals and sell signals). These elements form the basis of the MACD construction, and it is important to have a strong understanding of these elements if you plan on using the indicator in your daily trading.

Three Common Approaches to the MACD

Now that we understand the basics of how the MACD is calculated, it is a good idea to look at some of the common ways that the MACD is viewed by traders so that we can get a sense of how exactly the indicator is used to identify trading opportunities. There are a few different ways the indicator can be interpreted, and the three of the most common methods proven to be the most effective for traders include

  • Crossovers,
  • Divergences,
  • and in identifying Overbought / Oversold conditions
Since the indicator has become a major part of the technical trading community, it is a good idea to look at some of these approaches in greater depth. But before you can do this, it is essential you understand the basics. Failure to do this is what leads to a large number of losses for many traders that are just getting started.