Standard iMA no working

 

Hi there, 

I am busy creating an EA that uses 55 EMA and the price close. It must perform some action when price closes above/below EMA 55. I have tested this and it sometime behaves in an unexpected manner. I am not sure if it is my code or there's just a bug in iMA function itself. The specific date used is 2017-01-03, where it Print("MA BUY"); but the price didn't close above EMA 55.


This is my code snippet

//Test MA
void testMa() {
   
   double previousEmaLevel  =  NormalizeDouble( iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, 1), Digits); 
   double previousClose =  iClose(SYMBOL, CURRENT_TIMEFRAME, 1);
   
   if ( (previousClose > previousEmaLevel) ) {
      
      Print("MA BUY");
   }
   
   else if ( (previousEmaLevel > previousClose) ) {
      
      Print("MA SELL");
   }

Please assist.

Thanks

 
Appsoluxions: I am not sure if it is my code or there's just a bug in iMA function itself
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. If there were a bug in iMA, wouldn't it have been found and fixed a decade ago? PICNIC
  3. Use the debugger or print out your variables, and find out why.
 
whroeder1:
  1. Please edit your post.
    For large amounts of code, attach it.

  2. If there were a bug in iMA, wouldn't it have been found and fixed a decade ago? PICNIC
  3. Use the debugger or print out your variables, and find out why.


1.1 Thanks for the pointers on decorating code.

2.1. Why does it has it be found in decade? Is that the MQL rule? 

2.2. It can be a PICNIC- I clearly stated that "I am not sure if it's my code" - I posted my code so that experts like you can help with resolve this PICNIC - If you cannot leave it other coders.


Thank you!

User error - Wikipedia
User error - Wikipedia
  • en.wikipedia.org
A user error is an error made by the human user of a complex system, usually a computer system, in interacting with it. Although the term is sometimes used by human–computer interaction practitioners, the more formal human error term is used in the context of human reliability. Related terms such as PEBKAC (Problem Exists Between Keyboard And...
 
Appsoluxions: Why does it has it be found in decade? Is that the MQL rule?
Why would you think a bug would be hidden, never seen, for more a decade (when MT4 was first written,) not by the thousands of coders, but only you would find it??
 
whroeder1:
Why would you think a bug would be hidden, never seen, for more a decade (when MT4 was first written,) not by the thousands of coders, but only you would find it??

Because I might have tested something that other coders have never tested - Oh! wait that's not possible in your world - Stereotypical . Well it's possible in my world...http://www.csoonline.com/article/2927441/application-security/11-software-bugs-that-took-way-too-long-to-meet-their-maker.html#slide1. 

You have diverted my question to your personal arrogance. Don't bother respond - I found a temporary solution until I found out what I did wrong on the iMA for it to behave not as I expect. I used 

iBands(NULL,0,55,2,0,PRICE_LOW,MODE_MAIN,0)


to get the output I was expecting when using iMA.


See, I was busy looking for alternatives while you were busy personalizing my thread.


Please don't reply - you have said enough! 

11 software bugs that took way too long to meet their maker
11 software bugs that took way too long to meet their maker
  • By Phil Johnson
  • www.csoonline.com
All software has bugs, but even the most well known applications can have errors and vulnerabilities that somehow go undetected for years - or decades
 

Let's talk about "personal arrogance".


//Test MA
void testMa() {
   
   double previousEmaLevel  =  NormalizeDouble( iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, 1), Digits); 
   double previousClose =  iClose(SYMBOL, CURRENT_TIMEFRAME, 1);
   
   if ( (previousClose > previousEmaLevel) ) {
      
      Print("MA BUY");
   }
   
   else if ( (previousEmaLevel > previousClose) ) {
      
      Print("MA SELL");
   }


iBands(NULL,0,55,2,0,PRICE_LOW,MODE_MAIN,0)


  1. Your sample code is meaningless because of:
    1. it always returns the same value - index 1. 
    2. you compare that to the iBands value with a different index (0.)
    3. you compare that to the iBands value with a different price (PRICE_LOW)
    4. you compare that to the iBands indicator which uses simple moving average, while your code uses an exponential moving average 
    5. we don't know if symbol and timeframe are the same because you didn't specify what SYMBOL and CURRENT_TIMEFRAME are
    6. You didn't print out the local variables to determine if indicators return correct values
  2. You didn't bother to provide an example that can be compiled and tested.
  3. Yet, you conclude that problem is in a moving average function which many traders use for a number of years.
  4. Bonus: it didn't occur to you to grab any of the moving average indicators from the codebase and compare it with iMA.

Yeah, I think you should continue with this attitude, that's the best strategy to get an answer.