mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-16 17:48:05 +00:00
Momentum
charts for Quantower
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using TradingPlatform.BusinessLayer;
|
||||
|
||||
namespace QuanTAlib;
|
||||
|
||||
public class FlowIndicator : Indicator, IWatchlistIndicator
|
||||
{
|
||||
protected string? SourceName;
|
||||
public static int MinHistoryDepths => 2;
|
||||
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
||||
|
||||
public FlowIndicator()
|
||||
{
|
||||
Name = "Flow Visualization";
|
||||
SeparateWindow = false;
|
||||
}
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
// placeholder
|
||||
}
|
||||
|
||||
protected override void OnUpdate(UpdateArgs args)
|
||||
{
|
||||
// placeholder
|
||||
}
|
||||
|
||||
#pragma warning disable CA1416 // Validate platform compatibility
|
||||
|
||||
public override void OnPaintChart(PaintChartEventArgs args)
|
||||
{
|
||||
base.OnPaintChart(args);
|
||||
Graphics gr = args.Graphics;
|
||||
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
var mainWindow = this.CurrentChart.Windows[args.WindowIndex];
|
||||
var converter = mainWindow.CoordinatesConverter;
|
||||
var clientRect = mainWindow.ClientRectangle;
|
||||
gr.SetClip(clientRect);
|
||||
DateTime leftTime = new[] { converter.GetTime(clientRect.Left), this.HistoricalData.Time(this!.Count - 1) }.Max();
|
||||
DateTime rightTime = new[] { converter.GetTime(clientRect.Right), this.HistoricalData.Time(0) }.Min();
|
||||
|
||||
int leftIndex = (int)this.HistoricalData.GetIndexByTime(leftTime.Ticks) + 1;
|
||||
int rightIndex = (int)this.HistoricalData.GetIndexByTime(rightTime.Ticks);
|
||||
int width = this.CurrentChart.BarsWidth;
|
||||
|
||||
for (int i = rightIndex; i < leftIndex; i++)
|
||||
{
|
||||
int barX1 = (int)converter.GetChartX(this.HistoricalData.Time(i));
|
||||
int barY1 = (int)converter.GetChartY(this.HistoricalData.Open(i));
|
||||
int barYHigh = (int)converter.GetChartY(this.HistoricalData.High(i));
|
||||
int barYLow = (int)converter.GetChartY(this.HistoricalData.Low(i));
|
||||
int barX2 = barX1 + width;
|
||||
int barY2 = (int)converter.GetChartY(this.HistoricalData.Close(i));
|
||||
using (Brush transparentBrush = new SolidBrush(Color.FromArgb(250, 70, 70, 70)))
|
||||
{
|
||||
gr.FillRectangle(transparentBrush, barX1, barYHigh - 1, CurrentChart.BarsWidth, Math.Abs(barYLow - barYHigh) + 2);
|
||||
}
|
||||
using (Brush circ = new SolidBrush(Color.FromArgb(100, 255, 255, 0)))
|
||||
{
|
||||
int size = 3;
|
||||
gr.FillEllipse(circ, barX1 - size, barY1 - size, 2 * size, 2 * size);
|
||||
gr.FillEllipse(circ, barX2 - size, barY2 - size, 2 * size, 2 * size);
|
||||
}
|
||||
using (Pen defaultPen = new(Color.Yellow, 3))
|
||||
{
|
||||
defaultPen.StartCap = LineCap.Round;
|
||||
defaultPen.EndCap = LineCap.Round;
|
||||
gr.DrawLine(defaultPen, barX1, barY1, barX2, barY2);
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
int barX0 = (int)converter.GetChartX(this.HistoricalData.Time(i - 1));
|
||||
int barY0 = (int)converter.GetChartY(this.HistoricalData.Open(i - 1));
|
||||
using (Pen dottedPen = new(Color.Yellow, 1))
|
||||
{
|
||||
dottedPen.DashStyle = DashStyle.Dot;
|
||||
gr.DrawLine(dottedPen, barX2, barY2, barX0, barY0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System.Drawing;
|
||||
using TradingPlatform.BusinessLayer;
|
||||
|
||||
namespace QuanTAlib;
|
||||
|
||||
public class TestIndicator : Indicator, IWatchlistIndicator
|
||||
{
|
||||
[InputParameter("Period", sortIndex: 1, 1, 2000, 1, 0)]
|
||||
public int Period { get; set; } = 10;
|
||||
|
||||
[InputParameter("Data source", sortIndex: 20, variants: [
|
||||
"Open", SourceType.Open,
|
||||
"High", SourceType.High,
|
||||
"Low", SourceType.Low,
|
||||
"Close", SourceType.Close,
|
||||
"HL/2 (Median)", SourceType.HL2,
|
||||
"OC/2 (Midpoint)", SourceType.OC2,
|
||||
"OHL/3 (Mean)", SourceType.OHL3,
|
||||
"HLC/3 (Typical)", SourceType.HLC3,
|
||||
"OHLC/4 (Average)", SourceType.OHLC4,
|
||||
"HLCC/4 (Weighted)", SourceType.HLCC4
|
||||
])]
|
||||
public SourceType Source { get; set; } = SourceType.Close;
|
||||
|
||||
[InputParameter("Show cold values", sortIndex: 21)]
|
||||
public bool ShowColdValues { get; set; } = true;
|
||||
|
||||
private Sma? ma;
|
||||
protected LineSeries? Series;
|
||||
public int MinHistoryDepths { get; set; }
|
||||
int IWatchlistIndicator.MinHistoryDepths => 0; //QuanTAlib indicators generate value immediately
|
||||
|
||||
|
||||
public TestIndicator()
|
||||
{
|
||||
OnBackGround = true;
|
||||
SeparateWindow = false;
|
||||
Name = "TEST";
|
||||
Description = "test and test and test and more test.";
|
||||
Series = new(name: $"{Name}", color: IndicatorExtensions.Volatility, width: 2, style: LineStyle.Solid);
|
||||
AddLineSeries(Series);
|
||||
}
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
ma = new Sma(Period);
|
||||
base.OnInit();
|
||||
}
|
||||
protected override void OnUpdate(UpdateArgs args)
|
||||
{
|
||||
TValue input = this.GetInputValue(args, Source);
|
||||
TValue result = ma!.Calc(input);
|
||||
|
||||
Series!.SetMarker(0, Color.Transparent); //OnPaintChart draws the line, hidden here
|
||||
Series!.SetValue(result);
|
||||
}
|
||||
|
||||
public override void OnPaintChart(PaintChartEventArgs args)
|
||||
{
|
||||
base.OnPaintChart(args);
|
||||
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, ShowColdValues, tension: 0.2);
|
||||
this.DrawText(args, Description);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>Experiments</AssemblyName>
|
||||
<AlgoType>Indicator</AlgoType>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\*.cs" />
|
||||
<Compile Include="*.cs" />
|
||||
<Compile Include="..\..\lib\**\*.cs" Exclude="..\..\lib\bin\**;..\..\lib\obj\**" />
|
||||
<Reference Include="TradingPlatform.BusinessLayer">
|
||||
<HintPath>..\..\.github\TradingPlatform.BusinessLayer.dll</HintPath>
|
||||
</Reference>
|
||||
<None Include="..\..\.github\TradingPlatform.BusinessLayer.xml">
|
||||
<Link>TradingPlatform.BusinessLayer.xml</Link>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyCustomContent" AfterTargets="AfterBuild"
|
||||
Condition="'$(IsLocalBuild)' == 'true' AND $([MSBuild]::IsOSPlatform('Windows'))">
|
||||
<Copy SourceFiles="$(OutputPath)\Experiments.dll" DestinationFolder="$(QuantowerRoot)\Settings\Scripts\Indicators\QuanTAlib\Experiments" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user