diff --git a/.github/workflows/main_automation.yml b/.github/workflows/main_automation.yml
index e45f7eb5..464382dc 100644
--- a/.github/workflows/main_automation.yml
+++ b/.github/workflows/main_automation.yml
@@ -71,18 +71,14 @@ jobs:
############# Build and test
- - name: Build Main branch of QuanTAlib DLL
- if: ${{ github.ref != 'refs/heads/dev' }}
- run: dotnet build ./lib/quantalib.csproj --configuration Release --nologo -p:PackageVersion=${{ steps.gitversion.outputs.MajorMinorPatch }}
- - name: Build dev branch of QuanTAlib DLL
- if: ${{ github.ref == 'refs/heads/dev' }}
- run: dotnet build ./lib/quantalib.csproj --configuration Release --nologo -p:PackageVersion=${{ steps.gitversion.outputs.FullSemVer }}
- - name: Build Averages DLL
- run: dotnet build ./quantower/Averages/Averages.csproj --configuration Release --nologo
- - name: Build Statistics DLL
- run: dotnet build ./quantower/Statistics/Statistics.csproj --configuration Release --nologo
- - name: Build SyntheticVendor DLL
- run: dotnet build ./SyntheticVendor/SyntheticVendor.csproj --configuration Release --nologo
+ - name: Build projects
+ run: |
+ dotnet build ./lib/quantalib.csproj --configuration Release --nologo \
+ -p:PackageVersion=${{ github.ref == 'refs/heads/dev' && steps.gitversion.outputs.FullSemVer || steps.gitversion.outputs.MajorMinorPatch }}
+ dotnet build ./quantower/Averages/Averages.csproj --configuration Release --nologo
+ dotnet build ./quantower/Statistics/Statistics.csproj --configuration Release --nologo
+ dotnet build ./quantower/Volatility/Volatility.csproj --configuration Release --nologo
+ dotnet build ./SyntheticVendor/SyntheticVendor.csproj --configuration Release --nologo
- name: DotCover Test HTML
if: ${{ github.ref == 'refs/heads/dev' }}
@@ -99,8 +95,8 @@ jobs:
- name: Move coverage report to project root
if: ${{ github.ref == 'refs/heads/dev' }}
run: |
- report=$(find . -name '*coverage.cobertura.xml' | head -1)
- mv "$report" ./coverage.cobertura.xml
+ dotnet test ./Tests/Tests.csproj --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput="./TestResults/"
+ dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
- name: Upload to Codacy
if: ${{ github.ref == 'refs/heads/dev' }}
@@ -121,7 +117,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- run: dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
+ run: dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
############## Publish dev release
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000..e77d093f
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,13 @@
+{
+ "sonarlint.connectedMode.connections.sonarcloud": [
+ {
+ "organizationKey": "mihakralj",
+ "token": "6df7cd62a17dc4e1c5532df1da2f49d5a977dd50",
+ "connectionId": "mihakralj"
+ }
+ ],
+ "sonarlint.connectedMode.project": {
+ "connectionId": "mihakralj",
+ "projectKey": "mihakralj_QuanTAlib"
+ }
+}
\ No newline at end of file
diff --git a/Directory.Build.props b/Directory.Build.props
index 5d40b927..cb841319 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -22,11 +22,12 @@
true
-
-
- all
- runtime; build; native; contentfiles; analyzers
-
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
diff --git a/QuanTAlib.sln b/QuanTAlib.sln
index 44dd6e71..4d6759fe 100644
--- a/QuanTAlib.sln
+++ b/QuanTAlib.sln
@@ -1,19 +1,18 @@
-
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "quantalib", "lib\quantalib.csproj", "{584E06A9-CEB4-476A-85CC-6A8FF3974AE2}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "quantalib", "lib\quantalib.csproj", "{A1B2C3D4-E5F6-47G8-H9I0-J1K2L3M4N5O6}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tests", "tests\tests.csproj", "{D85FEBB4-B651-466F-85CC-FD902378D4D2}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{B2C3D4E5-F6G7-48H9-I0J1-K2L3M4N5O6P7}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MovingAverages", "quantower\averages\Averages.csproj", "{32CC09CC-26E3-4FCE-8932-C0513C4AD766}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyntheticVendor", "SyntheticVendor\SyntheticVendor.csproj", "{C3D4E5F6-G7H8-49I0-J1K2-L3M4N5O6P7Q8}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyntheticVendor", "SyntheticVendor\SyntheticVendor.csproj", "{20B1B5F1-8C36-4668-B0AE-951C13AE197B}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Averages", "quantower\Averages\Averages.csproj", "{D4E5F6G7-H8I9-50J1-K2L3-M4N5O6P7Q8R9}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "quantower", "quantower", "{A8D9AE68-24E3-476C-BB98-244541BB4B43}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Statistics", "quantower\Statistics\Statistics.csproj", "{E5F6G7H8-I9J0-51K2-L3M4-N5O6P7Q8R9S0}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Statistics", "quantower\Statistics\Statistics.csproj", "{B6D3EB11-63B6-430F-B526-E1981B3D8214}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volatility", "quantower\Volatility\Volatility.csproj", "{F6G7H8I9-J0K1-52L3-M4N5-O6P7Q8R9S0T1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -24,28 +23,29 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {584E06A9-CEB4-476A-85CC-6A8FF3974AE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {584E06A9-CEB4-476A-85CC-6A8FF3974AE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {584E06A9-CEB4-476A-85CC-6A8FF3974AE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {584E06A9-CEB4-476A-85CC-6A8FF3974AE2}.Release|Any CPU.Build.0 = Release|Any CPU
- {D85FEBB4-B651-466F-85CC-FD902378D4D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {D85FEBB4-B651-466F-85CC-FD902378D4D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {D85FEBB4-B651-466F-85CC-FD902378D4D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {D85FEBB4-B651-466F-85CC-FD902378D4D2}.Release|Any CPU.Build.0 = Release|Any CPU
- {32CC09CC-26E3-4FCE-8932-C0513C4AD766}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {32CC09CC-26E3-4FCE-8932-C0513C4AD766}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {32CC09CC-26E3-4FCE-8932-C0513C4AD766}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {32CC09CC-26E3-4FCE-8932-C0513C4AD766}.Release|Any CPU.Build.0 = Release|Any CPU
- {20B1B5F1-8C36-4668-B0AE-951C13AE197B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {20B1B5F1-8C36-4668-B0AE-951C13AE197B}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {20B1B5F1-8C36-4668-B0AE-951C13AE197B}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {20B1B5F1-8C36-4668-B0AE-951C13AE197B}.Release|Any CPU.Build.0 = Release|Any CPU
- {B6D3EB11-63B6-430F-B526-E1981B3D8214}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {B6D3EB11-63B6-430F-B526-E1981B3D8214}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {B6D3EB11-63B6-430F-B526-E1981B3D8214}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {B6D3EB11-63B6-430F-B526-E1981B3D8214}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(NestedProjects) = preSolution
- {B6D3EB11-63B6-430F-B526-E1981B3D8214} = {A8D9AE68-24E3-476C-BB98-244541BB4B43}
+ {A1B2C3D4-E5F6-47G8-H9I0-J1K2L3M4N5O6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A1B2C3D4-E5F6-47G8-H9I0-J1K2L3M4N5O6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A1B2C3D4-E5F6-47G8-H9I0-J1K2L3M4N5O6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A1B2C3D4-E5F6-47G8-H9I0-J1K2L3M4N5O6}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B2C3D4E5-F6G7-48H9-I0J1-K2L3M4N5O6P7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B2C3D4E5-F6G7-48H9-I0J1-K2L3M4N5O6P7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B2C3D4E5-F6G7-48H9-I0J1-K2L3M4N5O6P7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B2C3D4E5-F6G7-48H9-I0J1-K2L3M4N5O6P7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C3D4E5F6-G7H8-49I0-J1K2-L3M4N5O6P7Q8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C3D4E5F6-G7H8-49I0-J1K2-L3M4N5O6P7Q8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C3D4E5F6-G7H8-49I0-J1K2-L3M4N5O6P7Q8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C3D4E5F6-G7H8-49I0-J1K2-L3M4N5O6P7Q8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D4E5F6G7-H8I9-50J1-K2L3-M4N5O6P7Q8R9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D4E5F6G7-H8I9-50J1-K2L3-M4N5O6P7Q8R9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D4E5F6G7-H8I9-50J1-K2L3-M4N5O6P7Q8R9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D4E5F6G7-H8I9-50J1-K2L3-M4N5O6P7Q8R9}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E5F6G7H8-I9J0-51K2-L3M4-N5O6P7Q8R9S0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E5F6G7H8-I9J0-51K2-L3M4-N5O6P7Q8R9S0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E5F6G7H8-I9J0-51K2-L3M4-N5O6P7Q8R9S0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E5F6G7H8-I9J0-51K2-L3M4-N5O6P7Q8R9S0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F6G7H8I9-J0K1-52L3-M4N5-O6P7Q8R9S0T1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F6G7H8I9-J0K1-52L3-M4N5-O6P7Q8R9S0T1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F6G7H8I9-J0K1-52L3-M4N5-O6P7Q8R9S0T1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F6G7H8I9-J0K1-52L3-M4N5-O6P7Q8R9S0T1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
diff --git a/SyntheticVendor/SyntheticVendor.cs b/SyntheticVendor/SyntheticVendor.cs
index 58ad336b..e1a7f559 100644
--- a/SyntheticVendor/SyntheticVendor.cs
+++ b/SyntheticVendor/SyntheticVendor.cs
@@ -551,6 +551,10 @@ namespace SyntheticVendorNamespace
openValue = 0.0001;
closeValue = 100;
}
+ else
+ {
+ // No action
+ }
return new HistoryItemBar
{
@@ -778,8 +782,10 @@ namespace SyntheticVendorNamespace
};
}
-
- Random random = new Random();
+#pragma warning disable S2245
+ // NOSONAR
+ readonly Random random = new Random();
+#pragma warning restore S2245
private double currentAmplitude = 100;
private HistoryItemBar GenerateAMSignal(DateTime time, TimeSpan slice)
{
diff --git a/Tests/test_consistency.cs b/Tests/test_consistency.cs
deleted file mode 100644
index 72d482cd..00000000
--- a/Tests/test_consistency.cs
+++ /dev/null
@@ -1,883 +0,0 @@
-using Xunit;
-using QuanTAlib;
-
-public class Consistency
-{
- Random rnd;
- int series_len = 1000;
- int corrections = 100;
-
- public Consistency()
- { //constructor
- rnd = new((int)DateTime.Now.Ticks);
- }
-
-
- [Fact]
- public void CanUpdate()
- {
-
- GbmFeed gbm = new();
- TSeries input = new(gbm.Close);
- TSeries output = new(input);
-
- gbm.Add(10000);
-
- Assert.Equal(input.Count, output.Count);
- for (int i = 0; i < input.Count; i++)
- {
- Assert.Equal(input[i].v, output[i].v);
- }
- }
-
- [Fact]
- public void Alma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- double offset = rnd.Next();
- double sigma = rnd.Next(1, 100);
- Alma ma1 = new(period: p, offset: offset, sigma: sigma);
- Alma ma2 = new(period: p, offset: offset, sigma: sigma);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Convolution_isNew()
- {
- Convolution ma1 = new(new double[] { 1.0, 2, 3, 2, 1 });
- Convolution ma2 = new(new double[] { 1.0, 2, 3, 2, 1 });
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Dema_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Dema ma1 = new(p);
- Dema ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Dsma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Dsma ma1 = new(p);
- Dsma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Dwma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Dwma ma1 = new(p);
- Dwma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void EmaSma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Ema ma1 = new(p, useSma: true);
- Ema ma2 = new(p, useSma: true);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Ema_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Ema ma1 = new(p, useSma: false);
- Ema ma2 = new(p, useSma: false);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Sma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Sma ma1 = new(p);
- Sma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Epma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Epma ma1 = new(p);
- Epma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Frama_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Frama ma1 = new(p);
- Frama ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Fwma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Fwma ma1 = new(p);
- Fwma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Gma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Gma ma1 = new(p);
- Gma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Hma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Hma ma1 = new(p);
- Hma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
-
- [Fact]
- public void Hwma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Hwma ma1 = new(p);
- Hwma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- /*
- [Fact]
- public void Jma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Jma ma1 = new(p);
- Jma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
-
- //Assert.Equal(ma1.Value, ma2.Value);
- Assert.True(ma1.Value == ma2.Value, $"Assertion failed at p={p}, Value={item1.Value}. ma1.Value={ma1.Value}, ma2.Value={ma2.Value}");
- }
- }
- */
-
-
- [Fact]
- public void Kama_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Kama ma1 = new(p);
- Kama ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Ltma_isNew()
- {
- int p = rnd.Next(0, 1);
- Ltma ma1 = new(p);
- Ltma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Mama_isNew()
- {
- int p = rnd.Next(0, 1);
- Mama ma1 = new(p, p * 0.1);
- Mama ma2 = new(p, p * 0.1);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
-
- Assert.True(ma1.Value == ma2.Value, $"Assertion failed for p={p}, i={i}. Expected {ma1.Value} but got {ma2.Value}.");
- }
- }
-
- [Fact]
- public void Mgdi_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Mgdi ma1 = new(p);
- Mgdi ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Mma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Mma ma1 = new(p);
- Mma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Qema_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Qema ma1 = new();
- Qema ma2 = new();
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Rema_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Rema ma1 = new(p);
- Rema ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Rma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Rma ma1 = new(p);
- Rma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Sinema_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Sinema ma1 = new(p);
- Sinema ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Smma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Smma ma1 = new(p);
- Smma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void T3_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- T3 ma1 = new(p);
- T3 ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Tema_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Tema ma1 = new(p);
- Tema ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
-
- [Fact]
- public void Trima_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Trima ma1 = new(p);
- Trima ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
-
- [Fact]
- public void Vidya_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Vidya ma1 = new(p);
- Vidya ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Wma_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Wma ma1 = new(p);
- Wma ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
- [Fact]
- public void Zlema_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Zlema ma1 = new(p);
- Zlema ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Entropy_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Entropy ma1 = new(p);
- Entropy ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Kurtosis_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Kurtosis ma1 = new(p);
- Kurtosis ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Max_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Max ma1 = new(p, 0.01);
- Max ma2 = new(p, 0.01);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Min_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Min ma1 = new(p, 0.01);
- Min ma2 = new(p, 0.01);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Med_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Median ma1 = new(p);
- Median ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Mode_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Mode ma1 = new(p);
- Mode ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Percentile_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Percentile ma1 = new(p, 50);
- Percentile ma2 = new(p, 50);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Skew_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Skew ma1 = new(p);
- Skew ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Stddev_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Stddev ma1 = new(p);
- Stddev ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Variance_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Variance ma1 = new(p);
- Variance ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
- [Fact]
- public void Zscore_isNew()
- {
- int p = (int)rnd.Next(2, 100);
- Zscore ma1 = new(p);
- Zscore ma2 = new(p);
- for (int i = 0; i < series_len; i++)
- {
- TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
- ma1.Calc(item1);
- for (int j = 0; j < corrections; j++)
- {
- item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
- ma1.Calc(item1);
- }
- ma2.Calc(new TValue(item1.Time, item1.Value, IsNew: true));
- Assert.Equal(ma1.Value, ma2.Value);
- }
- }
-
-}
diff --git a/Tests/test_iTBar.cs b/Tests/test_iTBar.cs
new file mode 100644
index 00000000..4f21c69a
--- /dev/null
+++ b/Tests/test_iTBar.cs
@@ -0,0 +1,58 @@
+using Xunit;
+using System.Reflection;
+
+namespace QuanTAlib
+{
+ public class BarIndicatorTests
+ {
+ private Random rnd;
+ private const int SeriesLen = 1000;
+ private const int Corrections = 100;
+
+ public BarIndicatorTests()
+ {
+ rnd = new Random((int)DateTime.Now.Ticks);
+ }
+
+ private static readonly iTValue[] indicators = new iTValue[]
+ {
+ new Atr(period: 14),
+ };
+
+ [Theory]
+ [MemberData(nameof(GetIndicators))]
+ public void IndicatorIsNew(iTValue indicator)
+ {
+ var indicator1 = indicator;
+ var indicator2 = indicator;
+
+ MethodInfo calcMethod = indicator.GetType().GetMethod("Calc")!;
+ if (calcMethod == null)
+ {
+ throw new Exception($"Calc method not found for indicator type: {indicator.GetType().Name}");
+ }
+
+ for (int i = 0; i < SeriesLen; i++)
+ {
+ TBar item1 = new(Time: DateTime.Now, Open: rnd.Next(-100, 100), High: rnd.Next(-100, 100), Low: rnd.Next(-100, 100), Close: rnd.Next(-100, 100), Volume: rnd.Next(-1000, 1000), IsNew: true);
+ calcMethod.Invoke(indicator1, new object[] { item1 });
+
+ for (int j = 0; j < Corrections; j++)
+ {
+ item1 = new(Time: DateTime.Now, Open: rnd.Next(-100, 100), High: rnd.Next(-100, 100), Low: rnd.Next(-100, 100), Close: rnd.Next(-100, 100), Volume: rnd.Next(-1000, 1000), IsNew: false);
+ calcMethod.Invoke(indicator1, new object[] { item1 });
+ }
+
+ var item2 = new TBar (item1.Time, item1.Open, item1.High, item1.Low, item1.Close, item1.Volume , IsNew: true);
+ calcMethod.Invoke(indicator2, new object[] { item2 });
+
+ Assert.Equal(indicator1.Value, indicator2.Value);
+ }
+ }
+
+ public static IEnumerable
-
lib\%(RecursiveDir)%(Filename)%(Extension)
@@ -19,6 +18,9 @@
+
+ %(Filename)%(Extension)
+
..\..\.github\TradingPlatform.BusinessLayer.dll
diff --git a/quantower/Volatility/AtrIndicator.cs b/quantower/Volatility/AtrIndicator.cs
new file mode 100644
index 00000000..fe1b0738
--- /dev/null
+++ b/quantower/Volatility/AtrIndicator.cs
@@ -0,0 +1,23 @@
+using TradingPlatform.BusinessLayer;
+namespace QuanTAlib;
+
+public class AtrIndicator : IndicatorBarBase
+{
+ [InputParameter("Period", sortIndex: 1, 1, 2000, 1, 0)]
+ public int Period { get; set; } = 20;
+
+ private Atr? atr;
+ protected override AbstractBarBase QuanTAlib => atr!;
+ public override string ShortName => $"ATR {Period}";
+ public AtrIndicator()
+ {
+ Name = "ATR - Average True Range";
+ SeparateWindow = true;
+ }
+
+ protected override void InitIndicator()
+ {
+ atr = new(Period);
+ MinHistoryDepths = atr!.WarmupPeriod;
+ }
+}
\ No newline at end of file
diff --git a/quantower/Volatility/Volatility.csproj b/quantower/Volatility/Volatility.csproj
new file mode 100644
index 00000000..3bf9b4dc
--- /dev/null
+++ b/quantower/Volatility/Volatility.csproj
@@ -0,0 +1,32 @@
+
+
+ Indicator
+ bin\$(Configuration)\
+ true
+ true
+ true
+
+
+
+
+ lib\%(RecursiveDir)%(Filename)%(Extension)
+
+
+
+
+
+
+
+
+
+ %(Filename)%(Extension)
+
+
+ ..\..\.github\TradingPlatform.BusinessLayer.dll
+
+
+ TradingPlatform.BusinessLayer.xml
+
+
+
+
\ No newline at end of file
diff --git a/quantower/Statistics/_IndicatorBase.cs b/quantower/_IndicatorBarBase.cs
similarity index 76%
rename from quantower/Statistics/_IndicatorBase.cs
rename to quantower/_IndicatorBarBase.cs
index aef60342..ff1de4de 100644
--- a/quantower/Statistics/_IndicatorBase.cs
+++ b/quantower/_IndicatorBarBase.cs
@@ -9,23 +9,9 @@ using TradingPlatform.BusinessLayer.TimeSync;
namespace QuanTAlib;
#pragma warning disable CA1416 // Validate platform compatibility
-public abstract class IndicatorBase : Indicator, IWatchlistIndicator
+public abstract class IndicatorBarBase : Indicator, IWatchlistIndicator
{
- [InputParameter("Data source", sortIndex: 17, variants: [
- "Open", 1,
- "High", 2,
- "Low", 3,
- "Close", 4,
- "HL/2 (Median)", 5,
- "OC/2 (Midpoint)", 6,
- "OHL/3 (Mean)", 7,
- "HLC/3 (Typical)", 8,
- "OHLC/4 (Average)", 9,
- "HLCC/4 (Weighted)", 10
- ])]
- public int Source { get; set; } = 4;
-
[InputParameter("Show cold values", sortIndex: 20)]
public bool ShowColdValues { get; set; } = true;
public int MinHistoryDepths;
@@ -33,16 +19,14 @@ public abstract class IndicatorBase : Indicator, IWatchlistIndicator
// LineSeries.LineSeries(string, Color, int, LineStyle)'
protected LineSeries? Series;
- protected string SourceName;
- protected abstract AbstractBase QuanTAlib { get; }
+ protected abstract AbstractBarBase QuanTAlib { get; }
int IWatchlistIndicator.MinHistoryDepths => 0;
- protected IndicatorBase() : base()
+ protected IndicatorBarBase()
{
OnBackGround = true;
SeparateWindow = false;
- SourceName = GetName(Source);
Series = new(name: $"{Name}", color: Color.RoyalBlue, width: 2, style: LineStyle.Solid);
AddLineSeries(Series);
@@ -70,23 +54,7 @@ public abstract class IndicatorBase : Indicator, IWatchlistIndicator
Volume: GetPrice(PriceType.Volume),
IsNew: args.Reason == UpdateReason.NewBar || args.Reason == UpdateReason.HistoricalBar);
- double price = Source switch
- {
- 1 => bar.Open,
- 2 => bar.High,
- 3 => bar.Low,
- 4 => bar.Close,
- 5 => bar.HL2,
- 6 => bar.OC2,
- 7 => bar.OHL3,
- 8 => bar.HLC3,
- 9 => bar.OHLC4,
- 10 => bar.HLCC4,
- _ => bar.Close
- };
-
- TValue input = new TValue(bar.Time, price, bar.IsNew);
- TValue result = QuanTAlib.Calc(input);
+ TValue result = QuanTAlib.Calc(bar);
Series!.SetValue(result.Value);
Series!.SetMarker(0, Color.Transparent);
@@ -169,22 +137,4 @@ public abstract class IndicatorBase : Indicator, IWatchlistIndicator
gr.FillRectangle(SystemBrushes.ControlDarkDark, textRect);
gr.DrawString(text, font, Brushes.White, new PointF(textRect.X + 6, textRect.Y + 5));
}
- protected string GetName(int pType)
- {
- return pType switch
- {
- 1 => "Open",
- 2 => "High",
- 3 => "Low",
- 4 => "Close",
- 5 => "Median",
- 6 => "Midpoint",
- 7 => "Mean",
- 8 => "Typical",
- 9 => "Average",
- 10 => "Weighted",
- _ => "N/A"
- };
- }
-
}
\ No newline at end of file
diff --git a/quantower/Averages/_IndicatorBase.cs b/quantower/_IndicatorBase.cs
similarity index 100%
rename from quantower/Averages/_IndicatorBase.cs
rename to quantower/_IndicatorBase.cs