The code plots the exponential average of a security Close price with a smoothing factor of 0.2. Note that studies using ema2 fetch a necessary number of additional bars for correct initialization, so adding more initialization data by increasing additionalBars input has little impact on the study.
Is there anything like this in NinjaScript?
If not, how would I go about getting the value of Ema2(Close, 5, 0.2) for instance?
I do not know ThinkScript, but what you describe can easily be achieved in NinjaScript.
Usually you use an integer period to calculate an exponential moving average. If n is the integer period, this translates into a smoothing factor k = 2/(n+1). To obtain the smoothing factor 0.2, you would need to select a period of 9, as k = 2/(n+1) = 2/(9+1) = 2/10 = 0.2
Of course it is possible to change the formula of the EMA to use a smoothing factor instead of the period.
NinjaTrader uses the variable BarsRequired to cut off the unstable period during the initialization of an indicator. You can simply declare a variable prefetch, and allocate the selected value to BarsRequired.
I have modified the default EMA to catch a prefetch value and to use a smoothing constant instead of a period.
The following 2 users say Thank You to Fat Tails for this post: