-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-TEMA.ps1
51 lines (40 loc) · 1.45 KB
/
Get-TEMA.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<#
.SYNOPSIS
Calculates the Triple Exponential Moving Average (TEMA) for a given set of data points.
.DESCRIPTION
The Get-TEMA function calculates the TEMA using the Exponential Moving Average (EMA) for a given set of data points.
It returns a list of TEMA values.
This function depends on the following:
- Function: Get-EMA (https://github.com/voytas75/PoshTrade/blob/main/code/Get-EMA.ps1)
.PARAMETER DataPoints
The array of data points for which to calculate the TEMA.
.PARAMETER Period
The period or number of data points to consider for the TEMA calculation.
.EXAMPLE
$dataPoints = 1..20 | ForEach-Object {Get-Random -Minimum 1 -Maximum 100}
$period = 10
$temaValues = Get-TEMA -DataPoints $dataPoints -Period $period
Write-Output $temaValues
#>
function Get-TEMA {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[double[]]$DataPoints,
[Parameter(Mandatory = $true)]
[int]$Period
)
# Calculate the first EMA
$ema1 = Get-EMA -DataPoints $DataPoints -Period $Period
# Calculate the second EMA
$ema2 = Get-EMA -DataPoints $ema1 -Period $Period
# Calculate the third EMA
$ema3 = Get-EMA -DataPoints $ema2 -Period $Period
# Calculate the TEMA values
$temaValues = New-Object 'System.Collections.Generic.List[Double]'
for ($i = 0; $i -lt $DataPoints.Length; $i++) {
$tema = 3 * $ema1[$i] - 3 * $ema2[$i] + $ema3[$i]
$temaValues.Add($tema)
}
return $temaValues
}