As a work around you can use a self calculated EMA with c = 2/(201) = 0,01:
double emaCalc(const double nxt, const double prv, const double c) { return( (nxt-prv)*c + prv ); }
Start with the previous close as the prev. value of this ema. This way you have values from the beginning but of course it's not the sma(200) but it slowly approaches the sma.
Just curious , Can use a "for loop" to read Close[1] until Close[200] and divide 200 ? then continue insert the new candlestick after every new close price into it ?
i didnt know can work this way or not, looks very complicated to code it.
- Carl Schreiber #: As a work around you can use a self calculated EMA with c = 2/(201) = 0,01:
That will not work. Exponential requires 3.45×(Length+1) bars to converge to 1/10 percent. (EMA Period 5 requires 21 initial bars.)
Moving average - WikipediaOP's original post was about the oldest 200 bars.
- Paulf #: because when i start the backtest i saw there are history candlestick available and there are candlestick value available when mouseover the candlestick.
“Because” is not an answer to my question: “how do you calculate a 200 period SMA when you have less than 200 candle?” The answer is you can't. Doesn't matter if you use SMA or EMA, it can not be done. You “saw there are history candlesticks available.” Yes, you did, but you did not see 200. That is why the MA did not display.
-
What I do, when dealing with large MAs, is compute MA(n) when n is the number of candles available up to length. This also solves № 1 problem. But this requires coding. Alternatively, just ignore all ticks until you have 200 bars.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
im using MQL4 and im using iMA function as below :
double MAscds = iMA(NULL,0,200,0,MODE_SMA,PRICE_CLOSE,0);
After executed the EA, the MA200 only able to appear after 200 Candlesticks. MY Question is how can i have the MA200 at the 1st candlestick after i run my EA ?
Thanks