From 69fae888d55a939d3f8531a4f1286c953fdb85fe Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Mon, 3 Apr 2023 09:44:57 -0700 Subject: [PATCH] ABOVE_Series --- Calculations/Basics/ABOVE_Series.cs | 15 +++++++++++---- Calculations/Calculations.csproj | 2 +- Calculations/Feeds/Alphavantage_Feed.cs | 5 ++--- Calculations/Feeds/Yahoo_Feed.cs | 3 +-- Indicators/Basics/QuanTAlib_Indicator.cs | 17 ++++++++++++++++- Indicators/Charts/JMA_chart.cs | 9 +++++---- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Calculations/Basics/ABOVE_Series.cs b/Calculations/Basics/ABOVE_Series.cs index 93fb6457..cd7e4b45 100644 --- a/Calculations/Basics/ABOVE_Series.cs +++ b/Calculations/Basics/ABOVE_Series.cs @@ -10,7 +10,8 @@ Remarks: */ public class OVER_Series : Pair_TSeries_Indicator { - public TSeries Cross = new(); + public TSeries Cross { get; set; } = new(); + private double _previous = double.NaN; public OVER_Series(TSeries d1, TSeries d2) : base(d1, d2) { if (base._d1.Count > 0 && base._d2.Count > 0) { for (int i = 0; i < base._d1.Count; i++) { this.Add(base._d1[i], base._d2[i], false); } } @@ -23,13 +24,18 @@ public class OVER_Series : Pair_TSeries_Indicator { } public override void Add((System.DateTime t, double v) TValue1, (System.DateTime t, double v) TValue2, bool update) { - (System.DateTime t, double v) over = ((TValue1.t > TValue2.t) ? TValue1.t : TValue2.t, TValue1.v > TValue2.v ? 1 : TValue1.v < TValue2.v ? -1 : 0); + + double val = TValue1.v > TValue2.v ? 1 : -1; + val = TValue1.v == TValue2.v ? 0 : val; + (System.DateTime t, double v) over = ((TValue1.t > TValue2.t) ? TValue1.t : TValue2.t, TValue1.v > TValue2.v ? 1 : val); if (update) { this.Cross[^1] = over; } else { this.Cross.Add(over); } + val = (this._previous < over.v) ? 1 : -1; (System.DateTime t, double v) result = ((TValue1.t > TValue2.t) ? TValue1.t : TValue2.t, - ((_previous == over.v) || (_previous != 0) || Double.IsNaN(_previous)) ? 0 : (_previous < over.v) ? 1 : -1); - _previous = over.v; + ((this._previous == over.v) || Double.IsNaN(this._previous) || (this._previous == 0)) ? 0 : val); + + this._previous = over.v; if (update) { base[^1] = result; } else { base.Add(result); } @@ -37,3 +43,4 @@ public class OVER_Series : Pair_TSeries_Indicator { } } + diff --git a/Calculations/Calculations.csproj b/Calculations/Calculations.csproj index cc0f6e01..ae442495 100644 --- a/Calculations/Calculations.csproj +++ b/Calculations/Calculations.csproj @@ -2,7 +2,7 @@ QuanTAlib - 0.1.30 + 0.1.31 Library of TA Calculations, Charts and Strategies for Quantower Quantitative Technical Analysis Library in C# for Quantower git diff --git a/Calculations/Feeds/Alphavantage_Feed.cs b/Calculations/Feeds/Alphavantage_Feed.cs index a5c52eba..5c9fc35f 100644 --- a/Calculations/Feeds/Alphavantage_Feed.cs +++ b/Calculations/Feeds/Alphavantage_Feed.cs @@ -10,7 +10,7 @@ Alphavantage - Free API to collect 100 recent daily quotes. It requires a (free) APIkey: unique Alphavantage API key - +*/ public class Alphavantage_Feed : TBars { public enum Interval { Month, Week, Day, Hour, Min30, Min15, Min5, Min1} @@ -52,5 +52,4 @@ public class Alphavantage_Feed : TBars } return (date, o, h, l, c, v); } -} -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/Calculations/Feeds/Yahoo_Feed.cs b/Calculations/Feeds/Yahoo_Feed.cs index b904fbac..5b9029a1 100644 --- a/Calculations/Feeds/Yahoo_Feed.cs +++ b/Calculations/Feeds/Yahoo_Feed.cs @@ -11,7 +11,7 @@ Yahoo Finance - Free API feed to collect daily market quotes Yahoo_Feed ticker = new("MSFT", 20) - +*/ public class Yahoo_Feed : TBars { public Yahoo_Feed(string Symbol = "IBM", int Period = 252) { @@ -46,4 +46,3 @@ public class Yahoo_Feed : TBars } } } -*/ \ No newline at end of file diff --git a/Indicators/Basics/QuanTAlib_Indicator.cs b/Indicators/Basics/QuanTAlib_Indicator.cs index ea2644a6..483ca3c5 100644 --- a/Indicators/Basics/QuanTAlib_Indicator.cs +++ b/Indicators/Basics/QuanTAlib_Indicator.cs @@ -6,15 +6,30 @@ using TradingPlatform.BusinessLayer.Chart; namespace QuanTAlib; -public class QuanTAlib_Indicator : Indicator { +public abstract class QuanTAlib_Indicator : Indicator { protected TBars bars; protected IChartWindow mainWindow; protected Graphics graphics; protected int firstOnScreenBarIndex, lastOnScreenBarIndex; + protected HistoricalData History; + protected int HistPeriod; protected override void OnInit() { base.OnInit(); bars = new(); + var dur1 = this.HistoricalData.FromTime; + var dur = this.HistoricalData.Period.Duration.TotalSeconds * (HistPeriod*4) ; //seconds of two periods + + this.History = this.Symbol.GetHistory(period: this.HistoricalData.Period, fromTime: HistoricalData.FromTime); + + for (int i = this.History.Count-1; i >= 0; i--) { + + var rec = this.History[i, SeekOriginHistory.Begin]; + + bars.Add(rec.TimeLeft, rec[PriceType.Open], + rec[PriceType.High], rec[PriceType.Low], + rec[PriceType.Close], rec[PriceType.Volume]); + } } protected override void OnUpdate(UpdateArgs args) { diff --git a/Indicators/Charts/JMA_chart.cs b/Indicators/Charts/JMA_chart.cs index 340c2287..aba04927 100644 --- a/Indicators/Charts/JMA_chart.cs +++ b/Indicators/Charts/JMA_chart.cs @@ -14,7 +14,7 @@ public class JMA_chart : QuanTAlib_Indicator { private int DataSource = 3; [InputParameter("Smoothing period", 1, 1, 999, 1, 1)] - private int Period = 10; + private int Period = 9; [InputParameter("Volatility short", 2, 3, 50, 1, 1)] private int Vshort = 10; @@ -28,7 +28,7 @@ public class JMA_chart : QuanTAlib_Indicator { #endregion Parameters /////// - private JMA_Series indicator; + private EMA_Series indicator; /////// public JMA_chart() :base() { @@ -36,14 +36,15 @@ public class JMA_chart : QuanTAlib_Indicator { Description = "Jurik Moving Average description"; AddLineSeries(lineName: "JMA", lineColor: Color.Yellow, lineWidth: 3,lineStyle: LineStyle.Solid); SeparateWindow = false; + HistPeriod = Period; } protected override void OnInit() { base.OnInit(); indicator = new(source: bars.Select(DataSource), period: Period, - phase: Jphase, vshort: Vshort, vlong: Vlong, - useNaN: false); + // phase: Jphase, vshort: Vshort, vlong: Vlong, + useNaN: true); } protected override void OnUpdate(UpdateArgs args) {