Download MetaTrader 5
To add comments, please log in or register
Publish your article to let the traders see it in MetaTrader 5!
flwilliams87
207
flwilliams87 2015.06.30 00:09 
My EMA array keeps showing a negative value, is that normal or did I do something wrong?
Miroslav Popov
365
Miroslav Popov 2015.06.30 00:37  

Can you post your code?

It is very difficult to guess what is the problem without more information.

An EMA must never show negative values. It represents an averaged price of the asset you are using. The market prices are never negative, therefore your EMA must also not be negative.



flwilliams87
207
flwilliams87 2015.06.30 01:26  
Miroslav Popov:

Can you post your code?

It is very difficult to guess what is the problem without more information.

An EMA must never show negative values. It represents an averaged price of the asset you are using. The market prices are never negative, therefore your EMA must also not be negative.



That's what I thought.  Its obvious Im doing something wrong but I can't seem to locate it the error/bug.  Im trying to copy two EMA values into an array.  EMA 5 and EMA 10. Thoughts?  And thanks in advance for the help!

EMA5_Handle=iMA(Symbol(),0,5,0,MODE_E<A,InpAppliedPrice1);
EMA5_Handle=iMA(Symbol(),0,10,0,MODE_E<A,InpAppliedPrice1);


   CopyBuffer(EMA5_Handle,MODE_EMA,0,17,EMA5_ARRAY);
   ArraySetAsSeries(EMA5_ARRAY,true);
  
   CopyBuffer(EMA10_Handle,MODE_EMA,0,17,EMA10_ARRAY);
   ArraySetAsSeries(EMA10_ARRAY,true);

Miroslav Popov
365
Miroslav Popov 2015.06.30 02:06  

Can you try setting the mode to MODE_EMA.

You have misspelled the therm to MODE_E<A

flwilliams87
207
flwilliams87 2015.06.30 02:20  
Miroslav Popov:

Can you try setting the mode to MODE_EMA.

You have misspelled the therm to MODE_E<A

MY mistake; that was a bad cut and paste.  Below is the code without any variables or misspellings...

EMA5_Handle=iMA(Symbol(),0,5,0,MODE_EMA,PRICE_CLOSE);
EMA5_Handle=iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE);


   CopyBuffer(EMA5_Handle,MODE_EMA,0,17,EMA5_ARRAY);
   ArraySetAsSeries(EMA5_ARRAY,true);
  
   CopyBuffer(EMA10_Handle,MODE_EMA,0,17,EMA10_ARRAY);
   ArraySetAsSeries(EMA10_ARRAY,true);

Alain Verleyen
Moderator
30635
Alain Verleyen 2015.06.30 09:46  

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


Alain Verleyen
Moderator
30635
Alain Verleyen 2015.06.30 09:49  
flwilliams87:

MY mistake; that was a bad cut and paste.  Below is the code without any variables or misspellings...


You used 2 times the same handle :
EMA5_Handle=iMA(Symbol(),0,5,0,MODE_EMA,PRICE_CLOSE);
EMA5_HandleEMA10_Handle=iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE);
Your code doesn't include any error processing, it's very bad practice.
flwilliams87
207
flwilliams87 2015.06.30 15:46  
Alain Verleyen:
You used 2 times the same handle :
Your code doesn't include any error processing, it's very bad practice.

Thanks Alan and I will include more error handling in my code. Do you think the problem might be my CopyBuffer command? Or could it be something else?


EMA5_Handle=iMA(Symbol(),0,5,0,MODE_EMA,PRICE_CLOSE);
EMA5_Handle=iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE);
SMA50_Handle=iMA(Symbol(),0,50,0,MODE_SMA,PRICE_CLOSE);

   CopyBuffer(EMA5_Handle,MODE_EMA,0,17,EMA5_ARRAY);
   ArraySetAsSeries(EMA5_ARRAY,true);
  
   CopyBuffer(EMA10_Handle,MODE_EMA,0,17,EMA10_ARRAY);
   ArraySetAsSeries(EMA10_ARRAY,true);

   CopyBuffer(SMA50_Handle,MODE_SMA,0,17,SMA50_ARRAY);
   ArraySetAsSeries(SMA50_ARRAY,true);
Alain Verleyen
Moderator
30635
Alain Verleyen 2015.06.30 16:13  
flwilliams87:

Thanks Alan and I will include more error handling in my code. Do you think the problem might be my CopyBuffer command? Or could it be something else?


It seems you didn't read all my previous post.
flwilliams87
207
flwilliams87 2015.06.30 17:38  
flwilliams87:

Thanks Alan and I will include more error handling in my code. Do you think the problem might be my CopyBuffer command? Or could it be something else?


No I must have missed what you are referring to. I saw where you corrected my spelling of EMA10_Handle and other than using the source button Im confused.
Alain Verleyen
Moderator
30635
Alain Verleyen 2015.06.30 18:46  
flwilliams87:
No I must have missed what you are referring to. I saw where you corrected my spelling of EMA10_Handle and other than using the source button Im confused.

Exactly I changed the variable name. But in the code you posted after, it's again 2 times EMA5_Handle.

By the way, you still don't show the code where we can see you get negative values. Which values ? Which array, indexes ?

/ /12
To add comments, please log in or register