TA.SMA
Calculates the Simple Moving Average (SMA) indicator.
TA.SMA(inReal)
TA.SMA(inReal, optInTimePeriod)Examples
Compute a 14-period SMA on 30-minute K-lines.
javascript
function main() {
var records = exchange.GetRecords(PERIOD_M30)
if (!records) return
var sma = TA.SMA(records, 14)
Log(sma)
// Output: an array as long as the K-lines; the warm-up part at the start is NaN
}
python
def main():
records = exchange.GetRecords(PERIOD_M30)
if not records:
return
sma = TA.SMA(records, 14)
Log(sma)
# Output: a list as long as the K-lines; the warm-up part at the start is None
rust
fn main() {
let Ok(records) = exchange.GetRecords(None, PERIOD_M30, None) else { return };
let sma = TA.SMA(&records, 14);
Log!(sma);
// Output: an array as long as the K-lines; the warm-up part at the start is NaN
}Returns
| Type | Description |
array | The return value of the |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | K-line (candlestick) data. |
optInTimePeriod | number | No | Calculation period. |
See Also
Remarks
The default value of the optInTimePeriod parameter of the TA.SMA() function is: 9.
TA.SMA() is identical to TA.MA(): both compute the simple moving average.