How to detect MACD cross?

Post Reply
User avatar
remix919
Trader
Posts: 91
Joined: Wed Jan 23, 2013 2:42 am
Location: Some Road in the USA

How to detect MACD cross?

Post by remix919 »

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?
EA's are the best way to trade. Why? Because they take the emotion out of trading.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: How to detect MACD cross?

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
remix919
Trader
Posts: 91
Joined: Wed Jan 23, 2013 2:42 am
Location: Some Road in the USA

Re: How to detect MACD cross?

Post by remix919 »

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.
EA's are the best way to trade. Why? Because they take the emotion out of trading.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: How to detect MACD cross?

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
remix919
Trader
Posts: 91
Joined: Wed Jan 23, 2013 2:42 am
Location: Some Road in the USA

Re: How to detect MACD cross?

Post by remix919 »

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.
EA's are the best way to trade. Why? Because they take the emotion out of trading.
Post Reply

Return to “Coders Hangout”