Welcome to 4XLab.NET : Forex Lab Community Server Sign in | Join | Faq

Questions and Answers

Started by sandrov at 10-28-2007 7:55 AM. Topic has 3 replies.

Print Search
Sort Posts:    
   10-28-2007, 7:55 AM
sandrov is not online. Last active: 3/2/2008 9:00:53 PM sandrov

Top 25 Posts
Joined on 10-19-2007
Posts 2
iEMA implementation

LS.,

First of all I think this site is a brilliant initiative!

I've downloaded the sourcecode and found a small implementation glitch in the EMA function at approx. line 387 (indicators.cs). When the tickcount equals periods: no calculation is done with the input value Val. In order to correct this the code should be like:

If (tickcount == periods)

{
  emav += Val;

  emav /= (periods+1);

}

 

Cheers,

Alexander


   Report 
   12-20-2007, 11:50 AM
JoeMama is not online. Last active: 12/20/2007 11:31:39 PM JoeMama

Top 10 Posts
Joined on 06-07-2007
Posts 5
Re: iEMA implementation
Is this a valid fix, can you post the whole function so I can see your change against the original
   Report 
   03-02-2008, 9:03 AM
sandrov is not online. Last active: 3/2/2008 9:00:53 PM sandrov

Top 25 Posts
Joined on 10-19-2007
Posts 2
Re: iEMA implementation

  public void ReceiveTick(double Val)
  {
   if (tickcount < periods)
    emav += Val;
   if (tickcount ==periods)

// added this line, otherwise the Val is disregarded
   
emav += Val;
    emav /= periods;
   if (tickcount > periods)
    emav = (dampen*(Val-emav))+emav;

   if (tickcount <= (periods+1) )
   {  
    // avoid overflow by stopping use of tickcount
    // when indicator is fully primed
    tickcount++;
   }
  }


   Report 
   04-12-2008, 8:38 PM
asimon is not online. Last active: 4/26/2008 8:26:04 PM asimon

Top 10 Posts
Joined on 03-07-2006
Posts 137
Re: iEMA implementation
Do remember that C language syntax specifies that if { } are not added after an if condition, only one statement will be executed. It is one of the many reasons why we can have the The International Obfuscated C Code Contest each year.

thus the corrected function should read as follows:

public void ReceiveTick(double Val)
  {
   if (tickcount < periods)
    emav += Val;
   if (tickcount ==periods)

    // we need opening curly braces here to include 2 statements
    {
       
         emav += Val;   // added this line, otherwise the Val is disregarded
        
emav /= periods;
    }

    // curly braces are not needed here since only one statement is executed
   if (tickcount > periods)
    emav = (dampen*(Val-emav))+emav;

   if (tickcount <= (periods+1) )
   {  
    // avoid overflow by stopping use of tickcount
    // when indicator is fully primed
    tickcount++;
   }
  }



   Report 
4XLab.NET : For... » 4XLab.NET » Questions and A... » iEMA implementation

Powered by Community Server, by Telligent Systems