stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

How to detect MACD cross?
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1451
Page 1 of 1
Author:  remix919 [ Sun Feb 03, 2013 10:29 pm ]
Post subject:  How to detect MACD cross?

I setup 2 variables to detect the value of the MACD in the current period and last period

Code: Select all

double li_1 = iMACD(NULL,0,7,22,1,PRICE_CLOSE,0,0);
double li_2 = iMACD(NULL,0,7,22,1,PRICE_CLOSE,0,1);
then I want it to detect the cross and either buy or sell based on the cross direction.

Code: Select all

          if (li_1 > 0 && li_2 < 0){
          lo_1=True;
          }
         if (li_1 < 0 && li_2 > 0){
         lo_2=True;
          }
However, it doesn't seem to work properly, could someone point me in the right direction?
Author:  SteveHopwood [ Sun Feb 03, 2013 11:45 pm ]
Post subject:  Re: How to detect MACD cross?

The first thing you have to do is start using sensible variable names that mean something, so if this is actually your code then stop being so bloody silly. Only an idiot uses variable names like these.

I went cross-eyed merely trying to read the code snippet you posted. Your snippet looked like decompiled code. Is it? If so, forget trying to translate it. I did so once and will never do so again; decompiled code is gibberish.

You will have taken a leap forward in your understanding of coding once you work out for yourself why decompiled code is impossible to work with.

:D
Author:  remix919 [ Sun Feb 03, 2013 11:54 pm ]
Post subject:  Re: How to detect MACD cross?

It's not decompiled code, I had downloaded a simple EA that just had basic buy and sell functions and they had their indicators listed with li_x and I had just replaced the indi with my own but kept the variable name.
Author:  SteveHopwood [ Mon Feb 04, 2013 12:25 am ]
Post subject:  Re: How to detect MACD cross?

remix919 wrote:It's not decompiled code, I had downloaded a simple EA that just had basic buy and sell functions and they had their indicators listed with li_x and I had just replaced the indi with my own but kept the variable name.
That is decompiled code, fella. It may have escaped your notice, but I know a thingy or umpteen about this stuff.

It is up to you whether you follow my advice or not. Fact is,what you have posted is unintelligible gibberish that will be ignored unless you happen to come across a very patient reader. They are rare.

:D
Author:  remix919 [ Mon Feb 04, 2013 2:16 am ]
Post subject:  Re: How to detect MACD cross?

O, ok, well, what I was trying to do was have an EA that had 2 MACD indicators, one based on the current period, and the 2nd being 1 period back. I wanted it to trigger a buy/sell based on when the MACD crosses 0, so I figured if the first MACD > 0 and 2nd MACD < 0 at the same time, it would mean there had been a cross.
All times are UTC Page 1 of 1