My EMA array keeps showing a negative value, is that normal?

 
My EMA array keeps showing a negative value, is that normal or did I do something wrong?
 

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.



 
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);

 

Can you try setting the mode to MODE_EMA.

You have misspelled the therm to MODE_E<A

 
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);

 

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.


 
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.
 
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);
 
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:

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.
 
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 ?

Reason: