Login Page - Create Account

Support Board


Date/Time: Thu, 19 Sep 2024 21:42:41 +0000



Post From: Exponential Moving Averages Calculation

[2014-02-23 04:35:01]
Sierra Chart Engineering - Posts: 104368
This is the actual code:

SCFloatArrayRef ExponentialMovingAverage_S(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length)
{
  if (Index >= In.GetArraySize())
    return Out;

  if(Index < 1 || Length < 1)
    return Out;

  if (Index < Length -1)
    Length = Index+1;

  
  float Multiplier1 = 2.0f / (Length + 1);
  float Multiplier2 = 1.0f - Multiplier1;
  float PreviousMovingAverageValue = Out[Index - 1 ];
  //Check for a previous moving average value of 0 so we can properly initialize the previous value, and also check for out of range values.
  if (PreviousMovingAverageValue == 0.0f || !((PreviousMovingAverageValue > -FLT_MAX) && (PreviousMovingAverageValue < FLT_MAX)))
    Out[Index - 1] = In[Index-1];
  
  Out[Index] = (Multiplier1 * In[Index]) + (Multiplier2 * Out[Index - 1]);
  
  
  return Out;
}

Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing