mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-17 18:18:04 +00:00
Momentum
charts for Quantower
This commit is contained in:
@@ -47,7 +47,7 @@ public class AtrIndicator : Indicator, IWatchlistIndicator
|
||||
public override void OnPaintChart(PaintChartEventArgs args)
|
||||
{
|
||||
base.OnPaintChart(args);
|
||||
this.PaintHLine(args, 0.05, new Pen(Color.DarkRed, width: 2));
|
||||
this.PaintHLine(args, 0.05, new Pen(color: IndicatorExtensions.Volatility, width: 2));
|
||||
this.PaintSmoothCurve(args, AtrSeries!, atr!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class CmoIndicator : Indicator, IWatchlistIndicator
|
||||
Description = "Measures the momentum of price changes using the difference between the sum of recent gains and the sum of recent losses.";
|
||||
SeparateWindow = true;
|
||||
SourceName = Source.ToString();
|
||||
CmoSeries = new($"CMO {Periods}", Color.Blue, 2, LineStyle.Solid);
|
||||
CmoSeries = new($"CMO {Periods}", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
|
||||
AddLineSeries(CmoSeries);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class CviIndicator : Indicator, IWatchlistIndicator
|
||||
Description = "Measures the volatility of a financial instrument by comparing the spread between the high and low prices.";
|
||||
SeparateWindow = true;
|
||||
|
||||
CviSeries = new($"CVI {Periods}", Color.Blue, 2, LineStyle.Solid);
|
||||
CviSeries = new($"CVI {Periods}", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
|
||||
AddLineSeries(CviSeries);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class CviIndicator : Indicator, IWatchlistIndicator
|
||||
public override void OnPaintChart(PaintChartEventArgs args)
|
||||
{
|
||||
base.OnPaintChart(args);
|
||||
this.PaintHLine(args, 0.05, new Pen(Color.DarkRed, width: 2));
|
||||
this.PaintHLine(args, 0.05, new Pen(color: IndicatorExtensions.Volatility, width: 2));
|
||||
this.PaintSmoothCurve(args, CviSeries!, cvi!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class HistoricalIndicator : Indicator, IWatchlistIndicator
|
||||
Description = "Measures price fluctuations over time, indicating market volatility based on past price movements.";
|
||||
SeparateWindow = true;
|
||||
|
||||
HvSeries = new("HV", Color.Blue, 2, LineStyle.Solid);
|
||||
HvSeries = new("HV", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
|
||||
AddLineSeries(HvSeries);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ public class JbandsIndicator : Indicator, IWatchlistIndicator
|
||||
Description = "Upper and Lower Bands.";
|
||||
SeparateWindow = false;
|
||||
|
||||
UbSeries = new("UB", Color.Blue, 2, LineStyle.Solid);
|
||||
LbSeries = new("LB", Color.Red, 2, LineStyle.Solid);
|
||||
UbSeries = new("UB", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
|
||||
LbSeries = new("LB", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
|
||||
AddLineSeries(UbSeries);
|
||||
AddLineSeries(LbSeries);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class JvoltyIndicator : Indicator, IWatchlistIndicator
|
||||
Description = "Measures market volatility according to Mark Jurik.";
|
||||
SeparateWindow = true;
|
||||
|
||||
JvoltySeries = new("JVOLTY", Color.Blue, 2, LineStyle.Solid);
|
||||
JvoltySeries = new("JVOLTY", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
|
||||
AddLineSeries(JvoltySeries);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class RealizedIndicator : Indicator, IWatchlistIndicator
|
||||
Description = "Measures actual price volatility over a specific period, useful for risk assessment and forecasting.";
|
||||
SeparateWindow = true;
|
||||
|
||||
RvSeries = new("RV", Color.Blue, 2, LineStyle.Solid);
|
||||
RvSeries = new("RV", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
|
||||
AddLineSeries(RvSeries);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
using System.Drawing;
|
||||
using TradingPlatform.BusinessLayer;
|
||||
|
||||
namespace QuanTAlib;
|
||||
|
||||
public class RsiIndicator : Indicator, IWatchlistIndicator
|
||||
{
|
||||
[InputParameter("Periods", sortIndex: 1, 1, 2000, 1, 0)]
|
||||
public int Periods { get; set; } = 14;
|
||||
|
||||
[InputParameter("Data source", sortIndex: 5, 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 Rsi? rsi;
|
||||
protected string? SourceName;
|
||||
protected LineSeries? RsiSeries;
|
||||
public int MinHistoryDepths => Periods + 1;
|
||||
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
||||
|
||||
public RsiIndicator()
|
||||
{
|
||||
Name = "RSI - Relative Strength Index";
|
||||
Description = "Measures the speed and magnitude of recent price changes to evaluate overbought or oversold conditions.";
|
||||
SeparateWindow = true;
|
||||
SourceName = Source.ToString();
|
||||
RsiSeries = new($"RSI {Periods}", Color.Blue, 2, LineStyle.Solid);
|
||||
AddLineSeries(RsiSeries);
|
||||
}
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
rsi = new Rsi(Periods);
|
||||
base.OnInit();
|
||||
}
|
||||
|
||||
protected override void OnUpdate(UpdateArgs args)
|
||||
{
|
||||
TValue input = this.GetInputValue(args, Source);
|
||||
rsi!.Calc(input);
|
||||
|
||||
RsiSeries!.SetValue(rsi.Value);
|
||||
RsiSeries!.SetMarker(0, Color.Transparent);
|
||||
}
|
||||
|
||||
public override string ShortName => $"RSI ({Periods}:{SourceName})";
|
||||
|
||||
#pragma warning disable CA1416 // Validate platform compatibility
|
||||
public override void OnPaintChart(PaintChartEventArgs args)
|
||||
{
|
||||
base.OnPaintChart(args);
|
||||
this.PaintSmoothCurve(args, RsiSeries!, rsi!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
using System.Drawing;
|
||||
using TradingPlatform.BusinessLayer;
|
||||
|
||||
namespace QuanTAlib;
|
||||
|
||||
public class RsxIndicator : Indicator, IWatchlistIndicator
|
||||
{
|
||||
[InputParameter("Rsi Period", sortIndex: 1, 1, 2000, 1, 0)]
|
||||
public int Period { get; set; } = 14;
|
||||
|
||||
[InputParameter("Data source", sortIndex: 5, 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 Rsx? rsx;
|
||||
protected string? SourceName;
|
||||
protected LineSeries? RsxSeries;
|
||||
public int MinHistoryDepths => Period + 1;
|
||||
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
||||
|
||||
public RsxIndicator()
|
||||
{
|
||||
Name = "RSX - Jurik Trend Strengt Index";
|
||||
Description = "Measures the speed and magnitude of recent price changes to evaluate overbought or oversold conditions.";
|
||||
SeparateWindow = true;
|
||||
SourceName = Source.ToString();
|
||||
RsxSeries = new($"RSX {Period}", Color.Blue, 2, LineStyle.Solid);
|
||||
AddLineSeries(RsxSeries);
|
||||
}
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
rsx = new(Period);
|
||||
base.OnInit();
|
||||
}
|
||||
|
||||
protected override void OnUpdate(UpdateArgs args)
|
||||
{
|
||||
TValue input = this.GetInputValue(args, Source);
|
||||
rsx!.Calc(input);
|
||||
|
||||
RsxSeries!.SetValue(rsx.Value);
|
||||
RsxSeries!.SetMarker(0, Color.Transparent);
|
||||
}
|
||||
|
||||
public override string ShortName => $"RSX ({Period}:{SourceName})";
|
||||
|
||||
#pragma warning disable CA1416 // Validate platform compatibility
|
||||
public override void OnPaintChart(PaintChartEventArgs args)
|
||||
{
|
||||
base.OnPaintChart(args);
|
||||
this.PaintSmoothCurve(args, RsxSeries!, rsx!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class RviIndicator : Indicator, IWatchlistIndicator
|
||||
Description = "Measures the direction of volatility, helping to identify overbought or oversold conditions in price.";
|
||||
SeparateWindow = true;
|
||||
|
||||
RviSeries = new("RVI", Color.Blue, 2, LineStyle.Solid);
|
||||
RviSeries = new("RVI", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
|
||||
AddLineSeries(RviSeries);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
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: Color.Yellow, 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user