mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-16 09:38:05 +00:00
Merge branch 'dev'
This commit is contained in:
@@ -3,23 +3,35 @@ namespace QuanTAlib;
|
||||
|
||||
public class AfirmaIndicator : IndicatorBase
|
||||
{
|
||||
[InputParameter("Period", sortIndex: 1, 1, 2000, 1, 0)]
|
||||
public int Period { get; set; } = 10;
|
||||
[InputParameter("Taps (number of weights)", sortIndex: 1, 1, 2000, 1, 0)]
|
||||
public int Taps { get; set; } = 6;
|
||||
|
||||
[InputParameter("Periods for lowpass cutoff", sortIndex: 2, 1, 2000, 1, 0)]
|
||||
public int Periods { get; set; } = 6;
|
||||
|
||||
|
||||
|
||||
[InputParameter("Window Type", sortIndex: 3, variants: [
|
||||
"Rectangular", Afirma.WindowType.Rectangular,
|
||||
"Hanning", Afirma.WindowType.Hanning1,
|
||||
"Hamming", Afirma.WindowType.Hanning2,
|
||||
"Blackman", Afirma.WindowType.Blackman,
|
||||
"Blackman-Harris", Afirma.WindowType.BlackmanHarris
|
||||
])]
|
||||
public Afirma.WindowType Window { get; set; } = Afirma.WindowType.Hanning1;
|
||||
|
||||
[InputParameter("Alpha", sortIndex: 2, 0.01, 0.99, 0.01, 2)]
|
||||
public double Alpha { get; set; } = 0.1;
|
||||
private Afirma? ma;
|
||||
protected override AbstractBase QuanTAlib => ma!;
|
||||
public override string ShortName => $"AFIRMA {Period} : {SourceName}";
|
||||
public override string ShortName => $"AFIRMA {Taps}:{Periods}:{Window} : {SourceName}";
|
||||
|
||||
public AfirmaIndicator()
|
||||
{
|
||||
Name = "AFIRMA - Adaptive Filtering Integrated Recursive Moving Average";
|
||||
Description = "Adaptive Filtering Integrated Recursive Moving Average";
|
||||
Name = "AFIRMA - Adaptive Finite Impulse Response Moving Average";
|
||||
Description = "Adaptive Finite Impulse Response Moving Average with ARMA component";
|
||||
}
|
||||
|
||||
protected override void InitIndicator()
|
||||
{
|
||||
ma = new Afirma(period: Period, alpha: Alpha);
|
||||
ma = new Afirma(periods: Periods, taps: Taps, window: Window);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.DotNet.Interactive.Formatting" Version="1.0.0-beta.21459.1" />
|
||||
<Compile Include="..\..\lib\**\*.cs" Exclude="..\..\lib\obj\**">
|
||||
<Link>lib\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||
</Compile>
|
||||
@@ -19,6 +18,9 @@
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\*.cs">
|
||||
<Link>%(Filename)%(Extension)</Link>
|
||||
</Compile>
|
||||
<Reference Include="TradingPlatform.BusinessLayer">
|
||||
<HintPath>..\..\.github\TradingPlatform.BusinessLayer.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.DotNet.Interactive.Formatting" Version="1.0.0-beta.21459.1" />
|
||||
<Compile Include="..\..\lib\**\*.cs" Exclude="..\..\lib\obj\**">
|
||||
<Link>lib\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||
</Compile>
|
||||
@@ -19,6 +18,9 @@
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\*.cs">
|
||||
<Link>%(Filename)%(Extension)</Link>
|
||||
</Compile>
|
||||
<Reference Include="TradingPlatform.BusinessLayer">
|
||||
<HintPath>..\..\.github\TradingPlatform.BusinessLayer.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<AlgoType>Indicator</AlgoType>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
<IsLocalBuild Condition="'$(GITHUB_ACTIONS)' == ''">true</IsLocalBuild>
|
||||
<UpdateAssemblyInfo>true</UpdateAssemblyInfo>
|
||||
<GenerateGitVersionInformation>true</GenerateGitVersionInformation>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
|
||||
<Compile Include="..\..\lib\**\*.cs" Exclude="..\..\lib\obj\**">
|
||||
<Link>lib\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyCustomContent" AfterTargets="AfterBuild" Condition="'$(IsLocalBuild)' == 'true'">
|
||||
<Copy SourceFiles="$(OutputPath)\Volatility.dll" DestinationFolder="$(QuantowerRoot)\Settings\Scripts\Indicators\QuanTAlib\Volatility" />
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\*.cs">
|
||||
<Link>%(Filename)%(Extension)</Link>
|
||||
</Compile>
|
||||
<Reference Include="TradingPlatform.BusinessLayer">
|
||||
<HintPath>..\..\.github\TradingPlatform.BusinessLayer.dll</HintPath>
|
||||
</Reference>
|
||||
<None Include="..\..\.github\TradingPlatform.BusinessLayer.xml">
|
||||
<Link>TradingPlatform.BusinessLayer.xml</Link>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -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"
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user