Scripts/component.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
52
53
54
55
56
57
<#
.SYNOPSIS
    React-StockCharts MovingAverageCrossOverAlgorithmV2, CandleStickChartWithFullStochasticsIndicator, CandleStickChartWithMACDIndicator, CandleStickChartWithRSIIndicator, CandleStickChartWithBollingerBandOverlay, CandleStickChartWithMA, CandleStickChartWithSAR, CandleStickChartWithGannFan, OHLCChartWithElderRayIndicator, OHLCChartWithElderImpulseIndicator & CandleStickChartForContinuousIntraDay.
.DESCRIPTION
    React-StockCharts MovingAverageCrossOverAlgorithmV2, CandleStickChartWithFullStochasticsIndicator, CandleStickChartWithMACDIndicator, CandleStickChartWithRSIIndicator, CandleStickChartWithBollingerBandOverlay, CandleStickChartWithMA, CandleStickChartWithSAR, CandleStickChartWithGannFan, OHLCChartWithElderRayIndicator, OHLCChartWithElderImpulseIndicator & CandleStickChartForContinuousIntraDay.
.PARAMETER Id
    An id for the component
.EXAMPLE
    PS C:\> New-FinancialChart -stockData "http://localhost:10010/StockData.csv"
    PS C:\> New-FinancialChart -stockData "http://localhost:10010/StockData.csv" -chartType 'MovingAverageCrossOverAlgorithmV2'
.INPUTS
    (required) stockData - CSV delimited Stock Data
    
    (case sensitvie and ordered) Header Columns are;
    Open,High,Close,Low,Volume,Date

    Date format MUST be dd-mm-yyyy (e.g 17-01-2017) except for CandleStickChartForContinuousIntraDay ( date format MUST be in <dd-mm-yyyy hh:mm:ss> )
    Transform the data using PowerShell something like this;
    
    1 Year Stock History Data Transformation, remove double quotes, date into <dd-mm-yyyy> format
    $1y | Select-Object | ConvertTo-Csv -NoTypeInformation -Delimiter "," | ForEach-Object { $_ -replace '"', '' } | ForEach-Object { $_ -replace '/', '-' } | ForEach-Object { $_ -replace ' 10:00:00 PM', '' } | ForEach-Object { $_ -replace ',1-', ',01-' } | ForEach-Object { $_ -replace ',2-', ',02-' } | ForEach-Object { $_ -replace ',3-', ',03-' } | ForEach-Object { $_ -replace ',4-', ',04-' } | ForEach-Object { $_ -replace ',5-', ',05-' } | ForEach-Object { $_ -replace ',6-', ',06-' } | ForEach-Object { $_ -replace ',7-', ',07-' } | ForEach-Object { $_ -replace ',8-', ',08-' } | ForEach-Object { $_ -replace ',9-', ',09-' } | out-file -encoding ASCII "$($Cache:CSVDir)\$($Session:GraphStockSymbol)-AX-1y.csv"

    (optional) chartType - defaults to MovingAverageCrossOverAlgorithmV2

.OUTPUTS
    Financial Chart

.NOTES
    Requires a small NodeJS WebServer to serve up the Stock Data Files. Makes it easy to reference the data
    Example: https://github.com/darrenjrobinson/NodeWebFileServer
    https://blog.darrenjrobinson.com
#>

function New-FinancialChart {
    param(
        [Parameter()]
        [string]$Id = (New-Guid).ToString(),
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [string]$stockData,
        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
        [ValidateSet("CandleStickChartWithFullStochasticsIndicator", "MovingAverageCrossOverAlgorithmV2", "CandleStickChartForContinuousIntraDay", "CandleStickChartWithMACDIndicator", "CandleStickChartWithRSIIndicator", "CandleStickChartWithBollingerBandOverlay", "CandleStickChartWithMA", "CandleStickChartWithSAR", "CandleStickChartWithGannFan", "OHLCChartWithElderRayIndicator", "OHLCChartWithElderImpulseIndicator")]
        [string]$chartType = "MovingAverageCrossOverAlgorithmV2")

        End {

        @{
            # The AssetID of the main JS File
            assetId  = $AssetId 
            # Tell UD this is a plugin
            isPlugin = $true 
            # This ID must be the same as the one used in the JavaScript to register the control with UD
            type     = "UDFinancialChart"
            id       = $Id
            stockData     = $stockData
            chartType = $chartType
        }
    }
}