From de8dc79b1e1559e92a976d0a313cbe495b5550e6 Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Fri, 22 Apr 2022 10:23:12 -0700 Subject: [PATCH 1/4] readme Signed-off-by: Miha Kralj workflow workflow Signed-off-by: Miha Kralj --- .github/workflows/main_automation.yml | 26 +++++++++++++------------- Tests/Tests.csproj | 1 + 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main_automation.yml b/.github/workflows/main_automation.yml index 5546f943..f424d9a0 100644 --- a/.github/workflows/main_automation.yml +++ b/.github/workflows/main_automation.yml @@ -31,29 +31,29 @@ jobs: - name: Install JetBrains run: dotnet tool install JetBrains.dotCover.GlobalTool --global - name: Install Sonar Scanner - run: dotnet tool install dotnet-sonarscanner --global + run: dotnet tool install dotnet-sonarscanner --global - name: Install dotnet-coverage run: dotnet tool install dotnet-coverage --global - name: Install CodeCov run: dotnet tool install --global Codecov.Tool - name: Sonar start - env: + env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} #run: dotnet sonarscanner begin /o:"mihakralj" /k:"mihakralj_QuanTAlib" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths="./coverage.xml" - run: dotnet sonarscanner begin /o:"mihakralj" /k:"mihakralj_QuanTAlib" - /d:sonar.login="${{ secrets.SONAR_TOKEN }}" - /d:sonar.host.url="https://sonarcloud.io" + run: dotnet sonarscanner begin /o:"mihakralj" /k:"mihakralj_QuanTAlib" + /d:sonar.login="${{ secrets.SONAR_TOKEN }}" + /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths=./coveragereport.html - name: Build Core DLL - run: dotnet build ./Source/QuanTAlib.csproj --verbosity normal --configuration Release --nologo + run: dotnet build ./Source/QuanTAlib.csproj --verbosity normal --configuration Release --nologo - name: Build Quantower DLL - run: dotnet build ./Quantower/Quantower.csproj --verbosity normal --configuration Release --nologo + run: dotnet build ./Quantower/Quantower.csproj --verbosity normal --configuration Release --nologo - name: dotnet Test - run: dotnet test ./Tests/Tests.csproj --verbosity normal --configuration Release --nologo + run: dotnet test ./Tests/Tests.csproj --verbosity normal --configuration Release --nologo - name: DotCover Test XML run: dotnet dotcover test ./Tests/Tests.csproj --verbosity normal --framework net7.0 --dcReportType=DetailedXML --dcoutput=./coveragereport.xml - name: DotCover Test HTML @@ -62,7 +62,7 @@ jobs: # run: dotnet-coverage collect 'dotnet test' -f xml -o './coverage.xml' - name: Sonar reporter - env: + env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" @@ -82,7 +82,7 @@ jobs: # type: 'zip' # directory: \Quantower\Settings\Scripts\Indicators\QuanTAlib # filename: QL_Quantower.zip - +# # - name: Release # uses: marvinpinto/action-automatic-releases@latest # with: @@ -91,15 +91,15 @@ jobs: # prerelease: true # title: "Pre-release Build" # files: /Quantower/Settings/Scripts/Indicators/QuanTAlib/*.zip - +# # - name: Push package to nuget.org # run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' # --api-key ${{ secrets.NUGET_DEPLOY_KEY_QUANTLIB }} # --source https://api.nuget.org/v3/index.json # --skip-duplicate - +# # - name: Push package to github # run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' # --api-key ${{ secrets.GITHUB_TOKEN }} # --source https://nuget.pkg.github.com/mihakralj/index.json -# --skip-duplicate +# --skip-duplicate \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 8b027b94..5edf051d 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -25,6 +25,7 @@ all + From c7feec202288614560d7fbc2374a8ceaf919419b Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Sat, 23 Apr 2022 11:22:59 -0700 Subject: [PATCH 2/4] Refactor charts --- .DS_Store | Bin 0 -> 6148 bytes QuanTAlib.sln | 125 ++++++++++++---------------- Quantower/Indicators/ATR_chart.cs | 46 ++++++++++ Quantower/Indicators/BIAS_chart.cs | 3 - Quantower/Indicators/DEMA_chart.cs | 4 - Quantower/Indicators/EMA_chart.cs | 4 - Quantower/Indicators/ENTP_chart.cs | 4 - Quantower/Indicators/HEMA_chart.cs | 4 - Quantower/Indicators/HMA_chart.cs | 112 ++++++++++++------------- Quantower/Indicators/JMA_chart.cs | 5 -- Quantower/Indicators/KURT_chart.cs | 3 - Quantower/Indicators/MAD_chart.cs | 3 - Quantower/Indicators/MAPE_chart.cs | 3 - Quantower/Indicators/MAX_chart.cs | 4 - Quantower/Indicators/MED_chart.cs | 3 - Quantower/Indicators/MIN_chart.cs | 4 - Quantower/Indicators/MSE_chart.cs | 3 - Quantower/Indicators/PSDEV_chart.cs | 5 -- Quantower/Indicators/PVAR_chart.cs | 4 - Quantower/Indicators/RMA_chart.cs | 4 - Quantower/Indicators/SDEV_chart.cs | 5 -- Quantower/Indicators/SMAPE_chart.cs | 4 - Quantower/Indicators/SMA_chart.cs | 14 ++-- Quantower/Indicators/TEMA_chart.cs | 4 - Quantower/Indicators/VAR_chart.cs | 6 +- Quantower/Indicators/WMAPE_chart.cs | 5 -- Quantower/Indicators/WMA_chart.cs | 5 -- Quantower/Indicators/ZLEMA_chart.cs | 6 +- Quantower/Quantower.csproj | 26 +++++- Source/Basics/ZL_Series.cs | 68 +++++++-------- Source/QuanTAlib.csproj | 2 +- Tests/Tests.csproj | 20 ++++- 32 files changed, 235 insertions(+), 273 deletions(-) create mode 100644 .DS_Store create mode 100644 Quantower/Indicators/ATR_chart.cs diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0596783036f602d9926401cae85d01e7a90154a8 GIT binary patch literal 6148 zcmeHK%}T>S5T0$TO(;SR3OxqA7Ob@t#Y?F50W_iqm736^!I&*+Y7V84v%Zi|;`2DO zyA?|-coMNQF#FBUPnP`>cCr8Gy)mLW#p!ciQJvu5*Ml**Nj&8k(kYSyj)Aag$pvdOp` zq}MdNkTMSEb`V}h!@TcopU5N&qGXt=f@mw>$0G%(ixR_m0o|kMUC?Uo@QpzdR*d2IugK#)_Ri`)Lx(sMXQ$s&o*ZMjn{~W?+$l zvYtBB|4+Za|1TEtj2U1C{uKkF((`*=+>+_7OPix!>!RMFl2Bfu@v{UC)rv8fT5%m! a3Hn_!5Iuv1M)aWYkAR|q2WH?`8TbH3&P|E{ literal 0 HcmV?d00001 diff --git a/QuanTAlib.sln b/QuanTAlib.sln index cc6b9863..0d9aeabf 100644 --- a/QuanTAlib.sln +++ b/QuanTAlib.sln @@ -1,74 +1,51 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.2.32210.308 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}" - ProjectSection(ProjectDependencies) = postProject - {5096AEA1-81BC-46E7-9F2B-B408AFAA850C} = {5096AEA1-81BC-46E7-9F2B-B408AFAA850C} - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuanTAlib", "Source\QuanTAlib.csproj", "{AAE21F8A-9BC2-4647-A9EB-4DC86C569080}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{3AA87FFE-4EEE-4C1B-82E0-2A5E40E2254D}" - ProjectSection(SolutionItems) = preProject - Docs\bars_and_HMA.dib = Docs\bars_and_HMA.dib - Docs\Comparing_w_TALIB.ipynb = Docs\Comparing_w_TALIB.ipynb - Docs\getting_started.ipynb = Docs\getting_started.ipynb - Docs\Indicators.md = Docs\Indicators.md - Docs\LICENSE = Docs\LICENSE - Docs\ma-comparison.dib = Docs\ma-comparison.dib - Docs\macd_example.ipynb = Docs\macd_example.ipynb - Docs\QuanTAlib_Indicators.dib = Docs\QuanTAlib_Indicators.dib - Docs\QuanTAlib_test.ipynb = Docs\QuanTAlib_test.ipynb - Docs\README.md = Docs\README.md - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{8D8CD223-7A8C-46C4-A326-58E0B735FBA4}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Quantower", "Quantower\Quantower.csproj", "{5096AEA1-81BC-46E7-9F2B-B408AFAA850C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Debug|Any CPU.ActiveCfg = Debug|x64 - {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Debug|Any CPU.Build.0 = Debug|x64 - {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Debug|x64.ActiveCfg = Debug|x64 - {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Debug|x64.Build.0 = Debug|x64 - {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Release|Any CPU.Build.0 = Release|Any CPU - {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Release|x64.ActiveCfg = Release|x64 - {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Release|x64.Build.0 = Release|x64 - {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Debug|Any CPU.Build.0 = Release|Any CPU - {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Debug|x64.ActiveCfg = Debug|Any CPU - {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Debug|x64.Build.0 = Debug|Any CPU - {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Release|Any CPU.Build.0 = Release|Any CPU - {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Release|x64.ActiveCfg = Release|Any CPU - {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Release|x64.Build.0 = Release|Any CPU - {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Debug|Any CPU.Build.0 = Release|Any CPU - {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Debug|x64.ActiveCfg = Release|Any CPU - {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Debug|x64.Build.0 = Release|Any CPU - {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Release|Any CPU.Build.0 = Release|Any CPU - {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Release|x64.ActiveCfg = Release|Any CPU - {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Release|x64.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D} = {8D8CD223-7A8C-46C4-A326-58E0B735FBA4} - {AAE21F8A-9BC2-4647-A9EB-4DC86C569080} = {8D8CD223-7A8C-46C4-A326-58E0B735FBA4} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {E5592DC2-0542-45B2-A0CF-C6B1EDC72B87} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32210.308 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuanTAlib", "Source\QuanTAlib.csproj", "{AAE21F8A-9BC2-4647-A9EB-4DC86C569080}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Quantower", "Quantower\Quantower.csproj", "{5096AEA1-81BC-46E7-9F2B-B408AFAA850C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Debug|x64.ActiveCfg = Debug|Any CPU + {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Debug|x64.Build.0 = Debug|Any CPU + {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Release|Any CPU.Build.0 = Release|Any CPU + {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Release|x64.ActiveCfg = Release|x64 + {AAE21F8A-9BC2-4647-A9EB-4DC86C569080}.Release|x64.Build.0 = Release|x64 + {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Debug|x64.ActiveCfg = Release|Any CPU + {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Debug|x64.Build.0 = Release|Any CPU + {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Release|Any CPU.Build.0 = Release|Any CPU + {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Release|x64.ActiveCfg = Release|x64 + {5096AEA1-81BC-46E7-9F2B-B408AFAA850C}.Release|x64.Build.0 = Release|x64 + {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Debug|x64.ActiveCfg = Debug|x64 + {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Debug|x64.Build.0 = Debug|x64 + {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Release|Any CPU.Build.0 = Release|Any CPU + {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Release|x64.ActiveCfg = Release|x64 + {283EACC9-3AF6-4DAE-9C1C-0F7F8C8CD70D}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E5592DC2-0542-45B2-A0CF-C6B1EDC72B87} + EndGlobalSection +EndGlobal diff --git a/Quantower/Indicators/ATR_chart.cs b/Quantower/Indicators/ATR_chart.cs new file mode 100644 index 00000000..ce467455 --- /dev/null +++ b/Quantower/Indicators/ATR_chart.cs @@ -0,0 +1,46 @@ +using System.Drawing; +using TradingPlatform.BusinessLayer; +namespace QuanTAlib; + +public class ATR_chart : Indicator +{ + #region Parameters + + [InputParameter("Smoothing period", 0, 1, 999, 1, 1)] + private readonly int Period = 10; + + #endregion Parameters + + private readonly TBars bars = new(); + + /////// + private ATR_Series indicator; + /////// + + public ATR_chart() + { + this.SeparateWindow = true; + this.Name = "ATR - Average True Range"; + this.Description = "Average True Range description"; + this.AddLineSeries("ATR", Color.RoyalBlue, 3, LineStyle.Solid); + } + + protected override void OnInit() + { + this.ShortName = + "ATR (" + this.Period + ")"; + this.indicator = new(source: bars, period: this.Period, useNaN: false); + } + + protected override void OnUpdate(UpdateArgs args) + { + bool update = !(args.Reason == UpdateReason.NewBar || + args.Reason == UpdateReason.HistoricalBar); + this.bars.Add(this.Time(), this.GetPrice(PriceType.Open), + this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), + this.GetPrice(PriceType.Close), + this.GetPrice(PriceType.Volume), update); + double result = this.indicator[this.indicator.Count - 1].v; + this.SetValue(result); + } +} diff --git a/Quantower/Indicators/BIAS_chart.cs b/Quantower/Indicators/BIAS_chart.cs index 9d1adadb..7dde6123 100644 --- a/Quantower/Indicators/BIAS_chart.cs +++ b/Quantower/Indicators/BIAS_chart.cs @@ -38,8 +38,6 @@ public class BIAS_chart : Indicator new(source: bars.Select(this.DataSource), period: this.Period); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,7 +46,6 @@ public class BIAS_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result, 0); } diff --git a/Quantower/Indicators/DEMA_chart.cs b/Quantower/Indicators/DEMA_chart.cs index ebca279a..76c63628 100644 --- a/Quantower/Indicators/DEMA_chart.cs +++ b/Quantower/Indicators/DEMA_chart.cs @@ -38,8 +38,6 @@ public class DEMA_chart : Indicator period: this.Period, useNaN: false); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +46,6 @@ public class DEMA_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result); } diff --git a/Quantower/Indicators/EMA_chart.cs b/Quantower/Indicators/EMA_chart.cs index 2dcbe4bd..27055ade 100644 --- a/Quantower/Indicators/EMA_chart.cs +++ b/Quantower/Indicators/EMA_chart.cs @@ -38,8 +38,6 @@ public class EMA_chart : Indicator period: this.Period, useNaN: false); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +46,6 @@ public class EMA_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result); } diff --git a/Quantower/Indicators/ENTP_chart.cs b/Quantower/Indicators/ENTP_chart.cs index d7e49cb3..5e1974eb 100644 --- a/Quantower/Indicators/ENTP_chart.cs +++ b/Quantower/Indicators/ENTP_chart.cs @@ -38,8 +38,6 @@ public class ENTP_chart : Indicator period: this.Period, useNaN: true); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +46,6 @@ public class ENTP_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result, 0); diff --git a/Quantower/Indicators/HEMA_chart.cs b/Quantower/Indicators/HEMA_chart.cs index 47b4d369..273648fc 100644 --- a/Quantower/Indicators/HEMA_chart.cs +++ b/Quantower/Indicators/HEMA_chart.cs @@ -38,8 +38,6 @@ public class HEMA_chart : Indicator period: this.Period, useNaN: false); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +46,6 @@ public class HEMA_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result); } diff --git a/Quantower/Indicators/HMA_chart.cs b/Quantower/Indicators/HMA_chart.cs index 39aa660d..2c1f5f96 100644 --- a/Quantower/Indicators/HMA_chart.cs +++ b/Quantower/Indicators/HMA_chart.cs @@ -1,56 +1,56 @@ -using System.Drawing; -using TradingPlatform.BusinessLayer; -namespace QuanTAlib; - -public class HMA_chart : Indicator -{ - #region Parameters - - [InputParameter("Smoothing period", 0, 1, 999, 1, 1)] - private int Period = 10; - - [InputParameter("Data source", 1, variants: new object[] - { "Open", 0, "High", 1, "Low", 2, "Close", 3, "HL2", 4, "OC2", 5, - "OHL3", 6, "HLC3", 7, "OHLC4", 8, "Weighted (HLCC4)", 9 })] - private int DataSource = 3; - - #endregion Parameters - - private readonly TBars bars = new(); - - /////// - private HMA_Series indicator; - /////// - - public HMA_chart() - { - this.SeparateWindow = false; - this.Name = "HMA - Hull Moving Average"; - this.Description = "Hull Moving Average description"; - this.AddLineSeries("HMA", Color.RoyalBlue, 3, LineStyle.Solid); - } - - protected override void OnInit() - { - this.ShortName = - "HMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; - this.indicator = new(source: bars.Select(this.DataSource), - period: this.Period, useNaN: false); - } - - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - - protected override void OnUpdate(UpdateArgs args) - { - bool update = !(args.Reason == UpdateReason.NewBar || - args.Reason == UpdateReason.HistoricalBar); - this.bars.Add(this.Time(), this.GetPrice(PriceType.Open), - this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), - this.GetPrice(PriceType.Close), - this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - - double result = this.indicator[this.indicator.Count - 1].v; - this.SetValue(result); - } -} +using System.Diagnostics; +using System.Drawing; +using TradingPlatform.BusinessLayer; +namespace QuanTAlib; + +public class HMA_chart : Indicator +{ + #region Parameters + + [InputParameter("Smoothing period", 0, 1, 999, 1, 1)] + private int Period = 10; + + [InputParameter("Data source", 1, variants: new object[] + { "Open", 0, "High", 1, "Low", 2, "Close", 3, "HL2", 4, "OC2", 5, + "OHL3", 6, "HLC3", 7, "OHLC4", 8, "Weighted (HLCC4)", 9 })] + private int DataSource = 3; + + #endregion Parameters + + private readonly TBars bars = new(); + + /////// + private HMA_Series indicator; + /////// + + public HMA_chart() + { + this.SeparateWindow = false; + this.Name = "HMA - Hull Moving Average"; + this.Description = "Hull Moving Average description"; + this.AddLineSeries("HMA", Color.RoyalBlue, 3, LineStyle.Solid); + } + + protected override void OnInit() + { + this.ShortName = + "HMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.indicator = new(source: bars.Select(this.DataSource), + period: this.Period, useNaN: false); + Debug.WriteLine("Send to debug output."); +} + + protected override void OnUpdate(UpdateArgs args) + { + Debug.WriteLine("Send to debug output."); + + bool update = !(args.Reason == UpdateReason.NewBar || + args.Reason == UpdateReason.HistoricalBar); + this.bars.Add(this.Time(), this.GetPrice(PriceType.Open), + this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), + this.GetPrice(PriceType.Close), + this.GetPrice(PriceType.Volume), update); + double result = this.indicator[this.indicator.Count - 1].v; + this.SetValue(result); + } +} diff --git a/Quantower/Indicators/JMA_chart.cs b/Quantower/Indicators/JMA_chart.cs index 92d811f6..9f9c016d 100644 --- a/Quantower/Indicators/JMA_chart.cs +++ b/Quantower/Indicators/JMA_chart.cs @@ -37,9 +37,6 @@ public class JMA_chart : Indicator this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); } - - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +45,6 @@ public class JMA_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result); } diff --git a/Quantower/Indicators/KURT_chart.cs b/Quantower/Indicators/KURT_chart.cs index aae895d5..81cad58d 100644 --- a/Quantower/Indicators/KURT_chart.cs +++ b/Quantower/Indicators/KURT_chart.cs @@ -38,8 +38,6 @@ public class KURT_chart : Indicator period: this.Period, useNaN: true); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,7 +46,6 @@ public class KURT_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result, 0); } diff --git a/Quantower/Indicators/MAD_chart.cs b/Quantower/Indicators/MAD_chart.cs index 668c22c7..dc675d2b 100644 --- a/Quantower/Indicators/MAD_chart.cs +++ b/Quantower/Indicators/MAD_chart.cs @@ -38,8 +38,6 @@ public class MAD_chart : Indicator period: this.Period, useNaN: true); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,7 +46,6 @@ public class MAD_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); double result = this.indicator[this.indicator.Count - 1].v; diff --git a/Quantower/Indicators/MAPE_chart.cs b/Quantower/Indicators/MAPE_chart.cs index 2c891dab..57e47fcb 100644 --- a/Quantower/Indicators/MAPE_chart.cs +++ b/Quantower/Indicators/MAPE_chart.cs @@ -38,8 +38,6 @@ public class MAPE_chart : Indicator period: this.Period, useNaN: true); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,7 +46,6 @@ public class MAPE_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); double result = this.indicator[this.indicator.Count - 1].v; diff --git a/Quantower/Indicators/MAX_chart.cs b/Quantower/Indicators/MAX_chart.cs index c1cbc2c6..a0d2d851 100644 --- a/Quantower/Indicators/MAX_chart.cs +++ b/Quantower/Indicators/MAX_chart.cs @@ -38,8 +38,6 @@ public class MAX_chart : Indicator new(source: bars.Select(this.DataSource), period: this.Period); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +46,6 @@ public class MAX_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result, 0); diff --git a/Quantower/Indicators/MED_chart.cs b/Quantower/Indicators/MED_chart.cs index b692a879..98fa6428 100644 --- a/Quantower/Indicators/MED_chart.cs +++ b/Quantower/Indicators/MED_chart.cs @@ -37,8 +37,6 @@ public class MED_chart : Indicator this.indicator = new(source: bars.Select(this.DataSource), period: this.Period); } - - protected void OnNewData(bool update = false) { this.indicator.Add(update); } protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -47,7 +45,6 @@ public class MED_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result, 0); } diff --git a/Quantower/Indicators/MIN_chart.cs b/Quantower/Indicators/MIN_chart.cs index 9ee0458d..c35a5700 100644 --- a/Quantower/Indicators/MIN_chart.cs +++ b/Quantower/Indicators/MIN_chart.cs @@ -38,8 +38,6 @@ public class MIN_chart : Indicator new(source: bars.Select(this.DataSource), period: this.Period); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +46,6 @@ public class MIN_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result, 0); diff --git a/Quantower/Indicators/MSE_chart.cs b/Quantower/Indicators/MSE_chart.cs index 2bce6b72..dce7d818 100644 --- a/Quantower/Indicators/MSE_chart.cs +++ b/Quantower/Indicators/MSE_chart.cs @@ -38,8 +38,6 @@ public class MSE_chart : Indicator period: this.Period, useNaN: true); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,7 +46,6 @@ public class MSE_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); double result = this.indicator[this.indicator.Count - 1].v; diff --git a/Quantower/Indicators/PSDEV_chart.cs b/Quantower/Indicators/PSDEV_chart.cs index 5cb89173..d10f65b3 100644 --- a/Quantower/Indicators/PSDEV_chart.cs +++ b/Quantower/Indicators/PSDEV_chart.cs @@ -37,9 +37,6 @@ public class PSDEV_chart : Indicator this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); } - - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +45,6 @@ public class PSDEV_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result, 0); diff --git a/Quantower/Indicators/PVAR_chart.cs b/Quantower/Indicators/PVAR_chart.cs index 20416403..2fa31678 100644 --- a/Quantower/Indicators/PVAR_chart.cs +++ b/Quantower/Indicators/PVAR_chart.cs @@ -38,8 +38,6 @@ public class PVAR_chart : Indicator period: this.Period, useNaN: true); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +46,6 @@ public class PVAR_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result, 0); diff --git a/Quantower/Indicators/RMA_chart.cs b/Quantower/Indicators/RMA_chart.cs index 77f72ba6..53357414 100644 --- a/Quantower/Indicators/RMA_chart.cs +++ b/Quantower/Indicators/RMA_chart.cs @@ -38,8 +38,6 @@ public class RMA_chart : Indicator period: this.Period, useNaN: false); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +46,6 @@ public class RMA_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result); } diff --git a/Quantower/Indicators/SDEV_chart.cs b/Quantower/Indicators/SDEV_chart.cs index 1f528dc9..6a8709a0 100644 --- a/Quantower/Indicators/SDEV_chart.cs +++ b/Quantower/Indicators/SDEV_chart.cs @@ -37,9 +37,6 @@ public class SDEV_chart : Indicator this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); } - - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +45,6 @@ public class SDEV_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result, 0); diff --git a/Quantower/Indicators/SMAPE_chart.cs b/Quantower/Indicators/SMAPE_chart.cs index 298226f0..b0005e89 100644 --- a/Quantower/Indicators/SMAPE_chart.cs +++ b/Quantower/Indicators/SMAPE_chart.cs @@ -38,8 +38,6 @@ public class SMAPE_chart : Indicator period: this.Period, useNaN: true); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +46,6 @@ public class SMAPE_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result, 0); diff --git a/Quantower/Indicators/SMA_chart.cs b/Quantower/Indicators/SMA_chart.cs index baf01aca..3b1933e9 100644 --- a/Quantower/Indicators/SMA_chart.cs +++ b/Quantower/Indicators/SMA_chart.cs @@ -7,12 +7,12 @@ public class SMA_chart : Indicator #region Parameters [InputParameter("Smoothing period", 0, 1, 999, 1, 1)] - private int Period = 10; + private readonly int Period = 10; [InputParameter("Data source", 1, variants: new object[] { "Open", 0, "High", 1, "Low", 2, "Close", 3, "HL2", 4, "OC2", 5, "OHL3", 6, "HLC3", 7, "OHLC4", 8, "Weighted (HLCC4)", 9 })] - private int DataSource = 3; + private readonly int DataSource = 3; #endregion Parameters @@ -36,11 +36,9 @@ public class SMA_chart : Indicator "SMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); - } - - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - - protected override void OnUpdate(UpdateArgs args) + } + + protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || args.Reason == UpdateReason.HistoricalBar); @@ -48,8 +46,6 @@ public class SMA_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result); } diff --git a/Quantower/Indicators/TEMA_chart.cs b/Quantower/Indicators/TEMA_chart.cs index f80261c6..72904f66 100644 --- a/Quantower/Indicators/TEMA_chart.cs +++ b/Quantower/Indicators/TEMA_chart.cs @@ -38,8 +38,6 @@ public class TEMA_chart : Indicator period: this.Period, useNaN: false); } - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +46,6 @@ public class TEMA_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result); } diff --git a/Quantower/Indicators/VAR_chart.cs b/Quantower/Indicators/VAR_chart.cs index 3af3ff87..cbb05692 100644 --- a/Quantower/Indicators/VAR_chart.cs +++ b/Quantower/Indicators/VAR_chart.cs @@ -37,9 +37,7 @@ public class VAR_chart : Indicator this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); } - - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - + protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +46,6 @@ public class VAR_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result, 0); diff --git a/Quantower/Indicators/WMAPE_chart.cs b/Quantower/Indicators/WMAPE_chart.cs index 60731245..f8a66212 100644 --- a/Quantower/Indicators/WMAPE_chart.cs +++ b/Quantower/Indicators/WMAPE_chart.cs @@ -44,15 +44,10 @@ public class WMAPE_chart : Indicator this.ShortName = "WMAPE (" + QuanTAlib.TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.indicator = new(source: this.bars.Select(this.DataSource), period: this.Period, useNaN: true); } - - protected void OnNewData(bool update = false) => this.indicator.Add(update); - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || args.Reason == UpdateReason.HistoricalBar); this.bars.Add(this.Time(), this.GetPrice(PriceType.Open), this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; diff --git a/Quantower/Indicators/WMA_chart.cs b/Quantower/Indicators/WMA_chart.cs index e40bad95..fc9ab073 100644 --- a/Quantower/Indicators/WMA_chart.cs +++ b/Quantower/Indicators/WMA_chart.cs @@ -37,9 +37,6 @@ public class WMA_chart : Indicator this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); } - - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || @@ -48,8 +45,6 @@ public class WMA_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); - double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result); } diff --git a/Quantower/Indicators/ZLEMA_chart.cs b/Quantower/Indicators/ZLEMA_chart.cs index f9f7e4c8..16ee75ee 100644 --- a/Quantower/Indicators/ZLEMA_chart.cs +++ b/Quantower/Indicators/ZLEMA_chart.cs @@ -37,10 +37,7 @@ public class ZLEMA_chart : Indicator this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); } - - protected void OnNewData(bool update = false) { this.indicator.Add(update); } - - protected override void OnUpdate(UpdateArgs args) + protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || args.Reason == UpdateReason.HistoricalBar); @@ -48,7 +45,6 @@ public class ZLEMA_chart : Indicator this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); - this.OnNewData(update); double result = this.indicator[this.indicator.Count - 1].v; this.SetValue(result); diff --git a/Quantower/Quantower.csproj b/Quantower/Quantower.csproj index 0fbcbe7d..44a503ad 100644 --- a/Quantower/Quantower.csproj +++ b/Quantower/Quantower.csproj @@ -8,15 +8,33 @@ Indicator Quantower_QTAlib QuanTAlib - Release - bin\ + embedded + AnyCPU + disable + False + + True + 3 + True + anycpu + full + + + + embedded + True + 3 + True + anycpu + + - + - + diff --git a/Source/Basics/ZL_Series.cs b/Source/Basics/ZL_Series.cs index 9eaa7ea7..c4843d19 100644 --- a/Source/Basics/ZL_Series.cs +++ b/Source/Basics/ZL_Series.cs @@ -1,35 +1,35 @@ -namespace QuanTAlib; -using System; - -/* -ZL: Zero Lag - Data is de-lagged by removing the data from “lag” days ago, thus removing - (or attempting to) the cumulative effect of the moving average. - -Calculation: - Lag = (Period-1)/2 - ZL = Data + (Data - Data(Lag days ago) ) - -Sources: - https://mudrex.com/blog/zero-lag-ema-trading-strategy/ - - */ - -public class ZL_Series : Single_TSeries_Indicator -{ - public ZL_Series(TSeries source, int period, bool useNaN = false) : base(source, period:period, useNaN:useNaN) { - if (this._data.Count > 0) { base.Add(this._data); } - } - - public override void Add((DateTime t, double v) TValue, bool update) - { - int _lag = (int)((_p-1) * 0.5); - _lag = (_data.Count-_lag < 0) ? 0 : _data.Count-_lag; - - double _zl = TValue.v + (TValue.v - _data[_lag].v); - - var ret = (TValue.t, (base.Count==0 && base._NaN) ? double.NaN : _zl ); - base.Add(ret, update); - - } +namespace QuanTAlib; +using System; + +/* +ZL: Zero Lag + Data is de-lagged by removing the data from “lag” days ago, thus removing + (or attempting to) the cumulative effect of the moving average. + +Calculation: + Lag = (Period-1)/2 + ZL = Data + (Data - Data(Lag days ago) ) + +Sources: + https://mudrex.com/blog/zero-lag-ema-trading-strategy/ + + */ + +public class ZL_Series : Single_TSeries_Indicator +{ + public ZL_Series(TSeries source, int period, bool useNaN = false) : base(source, period:period, useNaN:useNaN) { + if (this._data.Count > 0) { base.Add(this._data); } + } + + public override void Add((DateTime t, double v) TValue, bool update) + { + int _lag = (int)((_p-1) * 0.5); + _lag = (_data.Count-_lag < 0) ? 0 : _data.Count-_lag; + + double _zl = TValue.v + (TValue.v - _data[_lag].v); + + var ret = (TValue.t, (base.Count==0 && base._NaN) ? double.NaN : _zl ); + base.Add(ret, update); + + } } \ No newline at end of file diff --git a/Source/QuanTAlib.csproj b/Source/QuanTAlib.csproj index 92cac419..cf665210 100644 --- a/Source/QuanTAlib.csproj +++ b/Source/QuanTAlib.csproj @@ -13,7 +13,7 @@ readme.md net7.0;net6.0;net48;netcoreapp3.1;netstandard2.1 disable - 10.0 + preview disable true en-US diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 5edf051d..ac4a1d2a 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -10,6 +10,22 @@ AnyCPU;x64 + + 1701;1702;MSB3270 + + + + 1701;1702;MSB3270 + + + + 1701;1702;MSB3270 + + + + 1701;1702;MSB3270 + + all @@ -26,8 +42,8 @@ - - + + From f4364ca7c466a6105a97178b6350a123b4df2876 Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Sat, 23 Apr 2022 11:23:09 -0700 Subject: [PATCH 3/4] KAMA --- Quantower/Indicators/KAMA_chart.cs | 52 +++++++++++++++++++++++++++++ Source/Indicators/KAMA_Series.cs | 53 ++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 Quantower/Indicators/KAMA_chart.cs create mode 100644 Source/Indicators/KAMA_Series.cs diff --git a/Quantower/Indicators/KAMA_chart.cs b/Quantower/Indicators/KAMA_chart.cs new file mode 100644 index 00000000..3e497191 --- /dev/null +++ b/Quantower/Indicators/KAMA_chart.cs @@ -0,0 +1,52 @@ +using System.Diagnostics; +using System.Drawing; +using TradingPlatform.BusinessLayer; +namespace QuanTAlib; + +public class KAMA_chart : Indicator +{ + #region Parameters + + [InputParameter("Smoothing period", 0, 1, 999, 1, 1)] + private int Period = 10; + + [InputParameter("Data source", 1, variants: new object[] + { "Open", 0, "High", 1, "Low", 2, "Close", 3, "HL2", 4, "OC2", 5, + "OHL3", 6, "HLC3", 7, "OHLC4", 8, "Weighted (HLCC4)", 9 })] + private int DataSource = 3; + + #endregion Parameters + + private readonly TBars bars = new(); + + /////// + private KAMA_Series indicator; + /////// + + public KAMA_chart() + { + this.SeparateWindow = false; + this.Name = "KAMA - Kaufman's Adaptive Moving Average"; + this.Description = "Kaufman's Adaptive Moving Average description"; + this.AddLineSeries("KAMA", Color.RoyalBlue, 3, LineStyle.Solid); + } + + protected override void OnInit() + { + this.ShortName = + "KAMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); + Debug.WriteLine($"KAMA on-init. indicator.Count: {indicator.Count}"); + } + + protected override void OnUpdate(UpdateArgs args) + { + bool update = !(args.Reason == UpdateReason.NewBar || + args.Reason == UpdateReason.HistoricalBar); + this.bars.Add(this.Time(), this.GetPrice(PriceType.Open), + this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), + this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); + double result = this.indicator[this.indicator.Count - 1].v; + this.SetValue(result); + } +} diff --git a/Source/Indicators/KAMA_Series.cs b/Source/Indicators/KAMA_Series.cs new file mode 100644 index 00000000..ed7ebc7b --- /dev/null +++ b/Source/Indicators/KAMA_Series.cs @@ -0,0 +1,53 @@ +namespace QuanTAlib; +using System; + +/* +KAMA: Kaufman's Adaptive Moving Average + Created in 1988 by American quantitative finance theorist Perry J. Kaufman and is known as + Kaufman's Adaptive Moving Average (KAMA). Even though the method was developed as early as 1972, + it was not until the popular book titled "Trading Systems and Methods" that it was made widely + available to the public. Unlike other conventional moving averages systems, the Kaufman's Adaptive + Moving Average, considers market volatility apart from price fluctuations. + + KAMAi = KAMAi - 1 + SC * ( price - KAMAi-1 ) + +Sources: + https://www.tutorialspoint.com/kaufman-s-adaptive-moving-average-kama-formula-and-how-does-it-work + https://corporatefinanceinstitute.com/resources/knowledge/trading-investing/kaufmans-adaptive-moving-average-kama/ + https://www.technicalindicators.net/indicators-technical-analysis/152-kama-kaufman-adaptive-moving-average + +Remark: + If useNaN:true argument is provided, KAMA starts calculating values from [period] bar onwards. + Without useNaN argument (default setting), KAMA starts calculating values from bar 1 - and yields + slightly different results for the first 50 bars - and then converges with the other one. + + */ + +public class KAMA_Series : Single_TSeries_Indicator +{ + private static double _scFast, _scSlow; + public KAMA_Series(TSeries source, int period, int fast = 2, int slow= 30, bool useNaN = false) : base(source, period, useNaN) { + _scFast = 2.0 / (fast+1); + _scSlow = 2.0 / (slow+1); + if (base._data.Count > 0) { base.Add(base._data); } + } + public override void Add((System.DateTime t, double v) TValue, bool update) { + //if (update) { } else { } + double _change = Math.Abs( TValue.v - _data[(this.Count>_p)?this.Count-_p : 0].v); + double _sumpv = 0; + double _kama = TValue.v; + for (int i = (this.Count-_p+1>0)?this.Count-_p+1:0; i <= this.Count; i++) { + _sumpv += Math.Abs(_data[(i>0)?i:0].v- _data[(i>1)?i-1:0].v); + } + if (_sumpv != 0) { + double _er = _change/_sumpv; + double _sc = (_er * (_scFast - _scSlow)) + _scSlow; + double _prevKama = (this.Count > 0) ? this[this.Count-1].v : TValue.v; + if (double.IsNaN(_prevKama)) { _prevKama = TValue.v; } + _kama = (_prevKama + (_sc * _sc * (TValue.v - _prevKama))); + } + + var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _kama); + base.Add(result, update); + } +} \ No newline at end of file From 6dde26051148b67edba2eda7801c678fcb9a0533 Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Sat, 23 Apr 2022 12:41:49 -0700 Subject: [PATCH 4/4] build build build build --- .DS_Store | Bin 6148 -> 0 bytes .github/workflows/build.yml | 73 ++++++++++++++ .github/workflows/main_automation.yml | 136 ++++++++++++++++++++++++-- .github/workflows/publish.yml | 54 ++++++++++ 4 files changed, 253 insertions(+), 10 deletions(-) delete mode 100644 .DS_Store create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/publish.yml diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 0596783036f602d9926401cae85d01e7a90154a8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5T0$TO(;SR3OxqA7Ob@t#Y?F50W_iqm736^!I&*+Y7V84v%Zi|;`2DO zyA?|-coMNQF#FBUPnP`>cCr8Gy)mLW#p!ciQJvu5*Ml**Nj&8k(kYSyj)Aag$pvdOp` zq}MdNkTMSEb`V}h!@TcopU5N&qGXt=f@mw>$0G%(ixR_m0o|kMUC?Uo@QpzdR*d2IugK#)_Ri`)Lx(sMXQ$s&o*ZMjn{~W?+$l zvYtBB|4+Za|1TEtj2U1C{uKkF((`*=+>+_7OPix!>!RMFl2Bfu@v{UC)rv8fT5%m! a3Hn_!5Iuv1M)aWYkAR|q2WH?`8TbH3&P|E{ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..d7babda3 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,73 @@ +name: Build +on: + workflow_dispatch: + +jobs: + build: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Install .NET 7.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: | + 7.0.x + 5.0.x + include-prerelease: true + + - name: Install JDK11 for Sonar Scanner + uses: actions/setup-java@v1 + with: + java-version: 1.11 + + - name: Install JetBrains + run: dotnet tool install JetBrains.dotCover.GlobalTool --global + - name: Install Sonar Scanner + run: dotnet tool install dotnet-sonarscanner --global + - name: Install dotnet-coverage + run: dotnet tool install dotnet-coverage --global + - name: Install CodeCov + run: dotnet tool install --global Codecov.Tool + + - name: Sonar start + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + #run: dotnet sonarscanner begin /o:"mihakralj" /k:"mihakralj_QuanTAlib" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths="./coverage.xml" + run: dotnet sonarscanner begin /o:"mihakralj" /k:"mihakralj_QuanTAlib" + /d:sonar.login="${{ secrets.SONAR_TOKEN }}" + /d:sonar.host.url="https://sonarcloud.io" + /d:sonar.cs.dotcover.reportsPaths=./coveragereport.html + + - name: Build Core DLL + run: dotnet build ./Source/QuanTAlib.csproj --verbosity normal --configuration Release --nologo + - name: Build Quantower DLL + run: dotnet build ./Quantower/Quantower.csproj --verbosity normal --configuration Release --nologo + + - name: dotnet Test + run: dotnet test ./Tests/Tests.csproj --verbosity normal --configuration Release --nologo + - name: DotCover Test XML + run: dotnet dotcover test ./Tests/Tests.csproj --verbosity normal --framework net7.0 --dcReportType=DetailedXML --dcoutput=./coveragereport.xml + - name: DotCover Test HTML + run: dotnet dotcover test ./Tests/Tests.csproj --verbosity normal --framework net7.0 --dcReportType=HTML --dcoutput=./coveragereport.html +# - name: dotnet-coverage +# run: dotnet-coverage collect 'dotnet test' -f xml -o './coverage.xml' + + - name: Sonar reporter + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" + + - name: CodeCov run + run: codecov -f ./coveragereport.xml -v -t ${{ secrets.CODECOV_TOKEN }} + + - name: Codacy coverage reporter + uses: codacy/codacy-coverage-reporter-action@v1 + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + coverage-reports: ./coveragereport.xml \ No newline at end of file diff --git a/.github/workflows/main_automation.yml b/.github/workflows/main_automation.yml index f424d9a0..26d3e2b0 100644 --- a/.github/workflows/main_automation.yml +++ b/.github/workflows/main_automation.yml @@ -1,13 +1,15 @@ -name: Main +name: Stage/build/test/release/publish on: workflow_dispatch: push: - branches: [ main ] + branches: + - '*' pull_request: - branches: [ main ] + branches: + - '*' jobs: - build: + build_test: runs-on: windows-latest steps: - name: Checkout @@ -48,12 +50,12 @@ jobs: /d:sonar.cs.dotcover.reportsPaths=./coveragereport.html - name: Build Core DLL - run: dotnet build ./Source/QuanTAlib.csproj --verbosity normal --configuration Release --nologo + run: dotnet build ./Source/QuanTAlib.csproj --verbosity normal --configuration Debug --nologo - name: Build Quantower DLL - run: dotnet build ./Quantower/Quantower.csproj --verbosity normal --configuration Release --nologo + run: dotnet build ./Quantower/Quantower.csproj --verbosity normal --configuration Debug --nologo - name: dotnet Test - run: dotnet test ./Tests/Tests.csproj --verbosity normal --configuration Release --nologo + run: dotnet test ./Tests/Tests.csproj --verbosity normal --configuration Debug --nologo - name: DotCover Test XML run: dotnet dotcover test ./Tests/Tests.csproj --verbosity normal --framework net7.0 --dcReportType=DetailedXML --dcoutput=./coveragereport.xml - name: DotCover Test HTML @@ -76,13 +78,127 @@ jobs: project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} coverage-reports: ./coveragereport.xml + release_publish: + runs-on: windows-latest + needs: [build_test] + if: ${{ github.ref == 'refs/heads/main' }} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Install .NET 7.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: | + 7.0.x + 5.0.x + include-prerelease: true + + - name: Build Core DLL + run: dotnet build ./Source/QuanTAlib.csproj --configuration Release --nologo + - name: Build Quantower DLL + run: dotnet build ./Quantower/Quantower.csproj --configuration Release --nologo + + - name: Release + uses: marvinpinto/action-automatic-releases@latest + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "latest" + prerelease: true + title: "Latest Build" + files: /Quantower/Settings/Scripts/Indicators/QuanTAlib/*.dll + + - name: Push package to github + run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' + --api-key ${{ secrets.GITHUB_TOKEN }} + --source https://nuget.pkg.github.com/mihakralj/index.json + --skip-duplicate + + - name: Push package to nuget.org + run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' + --api-key ${{ secrets.NUGET_DEPLOY_KEY_QUANTLIB }} + --source https://api.nuget.org/v3/index.json + --skip-duplicate + + +# build: +# runs-on: windows-latest +# steps: +# - name: Checkout +# uses: actions/checkout@v2 +# with: +# fetch-depth: 0 + +# - name: Install .NET 7.0 +# uses: actions/setup-dotnet@v1 +# with: +# dotnet-version: | +# 7.0.x +# 5.0.x +# include-prerelease: true + +# - name: Install JDK11 for Sonar Scanner +# uses: actions/setup-java@v1 +# with: +# java-version: 1.11 + +# - name: Install JetBrains +# run: dotnet tool install JetBrains.dotCover.GlobalTool --global +# - name: Install Sonar Scanner +# run: dotnet tool install dotnet-sonarscanner --global +# - name: Install dotnet-coverage +# run: dotnet tool install dotnet-coverage --global +# - name: Install CodeCov +# run: dotnet tool install --global Codecov.Tool + +# - name: Sonar start +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} +# #run: dotnet sonarscanner begin /o:"mihakralj" /k:"mihakralj_QuanTAlib" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths="./coverage.xml" +# run: dotnet sonarscanner begin /o:"mihakralj" /k:"mihakralj_QuanTAlib" +# /d:sonar.login="${{ secrets.SONAR_TOKEN }}" +# /d:sonar.host.url="https://sonarcloud.io" +# /d:sonar.cs.dotcover.reportsPaths=./coveragereport.html + +# - name: Build Core DLL +# run: dotnet build ./Source/QuanTAlib.csproj --verbosity normal --configuration Release --nologo +# - name: Build Quantower DLL +# run: dotnet build ./Quantower/Quantower.csproj --verbosity normal --configuration Release --nologo + +# - name: dotnet Test +# run: dotnet test ./Tests/Tests.csproj --verbosity normal --configuration Release --nologo +# - name: DotCover Test XML +# run: dotnet dotcover test ./Tests/Tests.csproj --verbosity normal --framework net7.0 --dcReportType=DetailedXML --dcoutput=./coveragereport.xml +# - name: DotCover Test HTML +# run: dotnet dotcover test ./Tests/Tests.csproj --verbosity normal --framework net7.0 --dcReportType=HTML --dcoutput=./coveragereport.html +# # - name: dotnet-coverage +# # run: dotnet-coverage collect 'dotnet test' -f xml -o './coverage.xml' + +# - name: Sonar reporter +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} +# run: dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" + +# - name: CodeCov run +# run: codecov -f ./coveragereport.xml -v -t ${{ secrets.CODECOV_TOKEN }} + +# - name: Codacy coverage reporter +# uses: codacy/codacy-coverage-reporter-action@v1 +# with: +# project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} +# coverage-reports: ./coveragereport.xml + # - name: Zip DLLs # uses: thedoctor0/zip-release@master # with: # type: 'zip' # directory: \Quantower\Settings\Scripts\Indicators\QuanTAlib # filename: QL_Quantower.zip -# + # - name: Release # uses: marvinpinto/action-automatic-releases@latest # with: @@ -91,13 +207,13 @@ jobs: # prerelease: true # title: "Pre-release Build" # files: /Quantower/Settings/Scripts/Indicators/QuanTAlib/*.zip -# + # - name: Push package to nuget.org # run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' # --api-key ${{ secrets.NUGET_DEPLOY_KEY_QUANTLIB }} # --source https://api.nuget.org/v3/index.json # --skip-duplicate -# + # - name: Push package to github # run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' # --api-key ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..e986e214 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,54 @@ +name: Publish +on: + workflow_dispatch: + +jobs: + publish: + runs-on: windows-latest + needs: build + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Install .NET 7.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: | + 7.0.x + 5.0.x + include-prerelease: true + + - name: Build Core DLL + run: dotnet build ./Source/QuanTAlib.csproj --verbosity normal --configuration Release --nologo + - name: Build Quantower DLL + run: dotnet build ./Quantower/Quantower.csproj --verbosity normal --configuration Release --nologo + + - name: Zip DLLs + uses: thedoctor0/zip-release@master + with: + type: 'zip' + directory: \Quantower\Settings\Scripts\Indicators\QuanTAlib + filename: QL_Quantower.zip + + - name: Release + uses: marvinpinto/action-automatic-releases@latest + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "latest" + prerelease: true + title: "Pre-release Build" + files: /Quantower/Settings/Scripts/Indicators/QuanTAlib/*.zip + + - name: Push package to nuget.org + run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' + --api-key ${{ secrets.NUGET_DEPLOY_KEY_QUANTLIB }} + --source https://api.nuget.org/v3/index.json + --skip-duplicate + + - name: Push package to github + run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' + --api-key ${{ secrets.GITHUB_TOKEN }} + --source https://nuget.pkg.github.com/mihakralj/index.json + --skip-duplicate \ No newline at end of file