Putting simple math formula in EA?

 

Im trying to get the difference between to 2 moving averages, and not doing well. I want to subract one MA's price close from the other MA's price close and then see if the sum is greater than or less then my magic number which is a decimal number. How can i do this with out all the errors?

I have been getting unexpected token on my decimal number, semicolon, parenthesis, while trying to do this.

 
jboddie:

Im trying to get the difference between to 2 moving averages, and not doing well. I want to subract one MA's price close from the other MA's price close and then see if the sum is greater than or less then my magic number which is a decimal number. How can i do this with out all the errors?

I have been getting unexpected token on my decimal number, semicolon, parenthesis, while trying to do this.

if ((dMagic - (dMA1 - dMA2)) > 0)

 Print("The result is less than the magic number");

else

 Print("The result is greater than or equal to the magic number");

 

Ok here is what i come up with that doesnt produce errors but wont trade when im looking at my chart and knowing it should trade.

double Buy1_1 = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 100, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

if ((.009 + (Buy1_1 - Buy1_2)) > 0) Order = SIGNAL_BUY;

 
jboddie:

Im trying to get the difference between to 2 moving averages, and not doing well. I want to subract one MA's price close from the other MA's price close and then see if the sum is greater than or less then my magic number which is a decimal number. How can i do this with out all the errors?

I have been getting unexpected token on my decimal number, semicolon, parenthesis, while trying to do this.

why are you comparing difference between MAs to a magicnumber?

 

Well its not really THE magic number. Im a total newb to this stuff but after fooling around I seen something that grabbed my attention. The possible signal i seen goes against all logic of what i learned thru my youtube education. Anyways, what i seen was trading against the longer term trend but from my chart setup it seems to hold true. I just want to put it to an EA and back test it long term just to see what happens. What i was trying to do is get the difference between the 2 MA's and trigger a trade once it crossed the threshold of a 90 pip spread. What i was seeing in the charts although it was against the trend was that the price would back track as the slower MA was catching up. Its probably nuthing, but its education to me as i get better.

 
c0d3:

why are you comparing difference between MAs to a magicnumber?

I'd assumed from the previous post that the use of "magic" number was an unfortunate coincidence and is nothing to do with order labelling :-) I think he just means a value which he sets (his intellectual property).

 
Exactly cloudbreaker, much better put then what i said. What you said works out in several ways to keep it from getting errors but wont trade. I had previously done a similar thing with MACD and ADX with success. Dont know why i cant get it to work in this case. Thanks for the help regardless.
 
jboddie:
Exactly cloudbreaker, much better put then what i said. What you said works out in several ways to keep it from getting errors but wont trade. I had previously done a similar thing with MACD and ADX with success. Dont know why i cant get it to work in this case. Thanks for the help regardless.

Is it returning an error message in the journal?

Reason: