diff --git a/Financial_Candlestick_Patterns.sln b/Financial_Candlestick_Patterns.sln index a2ae507..3a302f0 100644 --- a/Financial_Candlestick_Patterns.sln +++ b/Financial_Candlestick_Patterns.sln @@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples_Formations", "Exam EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples_Patterns", "Examples_Patterns\Examples_Patterns.csproj", "{23135CD8-163D-4C86-8017-1036D76F5C0D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphCreator", "GraphCreator\GraphCreator.csproj", "{D100D9CC-005D-4220-AEA2-63D008FA8A28}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphCreator", "GraphCreator\GraphCreator.csproj", "{D100D9CC-005D-4220-AEA2-63D008FA8A28}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPFGraphMaker", "WPFGraphMaker\WPFGraphMaker.csproj", "{98BBF6A3-A2CF-4A72-8D59-7C3D12F2F5EE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -45,6 +47,10 @@ Global {D100D9CC-005D-4220-AEA2-63D008FA8A28}.Debug|Any CPU.Build.0 = Debug|Any CPU {D100D9CC-005D-4220-AEA2-63D008FA8A28}.Release|Any CPU.ActiveCfg = Release|Any CPU {D100D9CC-005D-4220-AEA2-63D008FA8A28}.Release|Any CPU.Build.0 = Release|Any CPU + {98BBF6A3-A2CF-4A72-8D59-7C3D12F2F5EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {98BBF6A3-A2CF-4A72-8D59-7C3D12F2F5EE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {98BBF6A3-A2CF-4A72-8D59-7C3D12F2F5EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {98BBF6A3-A2CF-4A72-8D59-7C3D12F2F5EE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/GraphCreator/Program.cs b/GraphCreator/Program.cs index 9e7a1e7..6aefc55 100644 --- a/GraphCreator/Program.cs +++ b/GraphCreator/Program.cs @@ -64,7 +64,9 @@ private void LoadData(object sender, EventArgs e) private List GetGraphData(string patternName) { - return _fiboTester.GetGraphData(patternName); + var points = _fiboTester.GetData(patternName).Result; + return points; + } protected override void Dispose(bool disposing) diff --git a/GraphMaker/FiboTester.cs b/GraphMaker/FiboTester.cs index 46d3072..76007bb 100644 --- a/GraphMaker/FiboTester.cs +++ b/GraphMaker/FiboTester.cs @@ -7,29 +7,25 @@ namespace GraphMaker public interface IFiboTester { void ShowOnGraph(List dataOhlcv, string patternName); - List GetGraphData(string patternName); + Task> GetData(string patternName); Task> GetPoints(string patternName); + //List GetGraphData(List list); + List GetDataFromJson(string patternName, string json); } public class FiboTester : IFiboTester { IFibonacci _fibonacci; + public async Task> GetPoints(string patternName) { string json = string.Empty; - ISignals _signals = new Signals(); - IFiboTester _fiboTester = new FiboTester(); - IFibonacci _fibonacci; - var client = new HttpClient(); var url = "https://gist.githubusercontent.com/przemyslawbak/c90528453d512a8d85ad2deea5cf6ad2/raw/aapl_us_d.csv"; - using (HttpResponseMessage response = await client.GetAsync(url)) + using (var httpClient = new HttpClient()) { - using (HttpContent content = response.Content) - { - json = content.ReadAsStringAsync().Result; - } + json = await httpClient.GetStringAsync(url); } var dataOhlcv = JsonConvert.DeserializeObject>(json).Select(x => new OhlcvObject() @@ -110,12 +106,39 @@ static void GetGraph(List points, string patternName) } - public List GetGraphData(string patternName) + public async Task> GetData(string patternName) { - var signalList = GetPoints(patternName); - List points = signalList.Result; - return points; + var signalList = await GetPoints(patternName); + return signalList; } + + //public List GetGraphData(List list) + //{ + // var signalList = taskList.Result; + // return signalList; + //} + + public List GetDataFromJson(string patternName, string json) + { + var dataOhlcv = JsonConvert.DeserializeObject>(json).Select(x => new OhlcvObject() + { + Open = x.Open, + High = x.High, + Low = x.Low, + Close = x.Close, + Volume = x.Volume, + }).Reverse().ToList(); + + + _fibonacci = new Fibonacci(dataOhlcv); + var signalList = _fibonacci.GetFibonacciSignalsList(patternName); + return signalList; + } + + //public List GetGraphData(List list) + //{ + // throw new NotImplementedException(); + //} } } diff --git a/WPFGraphMaker/App.xaml b/WPFGraphMaker/App.xaml new file mode 100644 index 0000000..3d8d17a --- /dev/null +++ b/WPFGraphMaker/App.xaml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/WPFGraphMaker/App.xaml.cs b/WPFGraphMaker/App.xaml.cs new file mode 100644 index 0000000..b6bc04b --- /dev/null +++ b/WPFGraphMaker/App.xaml.cs @@ -0,0 +1,14 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace WPFGraphMaker +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } + +} diff --git a/WPFGraphMaker/AssemblyInfo.cs b/WPFGraphMaker/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/WPFGraphMaker/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/WPFGraphMaker/MainWindow.xaml b/WPFGraphMaker/MainWindow.xaml new file mode 100644 index 0000000..b8585db --- /dev/null +++ b/WPFGraphMaker/MainWindow.xaml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file diff --git a/WPFGraphMaker/MainWindow.xaml.cs b/WPFGraphMaker/MainWindow.xaml.cs new file mode 100644 index 0000000..e833fff --- /dev/null +++ b/WPFGraphMaker/MainWindow.xaml.cs @@ -0,0 +1,103 @@ +using Candlestick_Patterns; +using GraphMaker; +using ScottPlot; +using ScottPlot.Plottables; +using ScottPlot.WPF; +using System.Net.Http; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Media; + +namespace WPFGraphMaker +{ + public partial class MainWindow : Window + { + private readonly IFiboTester _fiboTester = new FiboTester(); + public MainWindow() + { + InitializeComponent(); + Loaded += MyLoadedRoutedEventHandler; + WpfPlot1.Refresh(); + + } + + private async void MyLoadedRoutedEventHandler(object sender, RoutedEventArgs e) + { + var url = "https://gist.githubusercontent.com/przemyslawbak/c90528453d512a8d85ad2deea5cf6ad2/raw/aapl_us_d.csv"; + + HttpClient client = new HttpClient(); + HttpResponseMessage response = await client.GetAsync(url); + response.EnsureSuccessStatusCode(); + string json = await response.Content.ReadAsStringAsync(); + + var patternName = "BullishButterfly"; + List points = GetGraphData(patternName, json); + ViewGraph(points); + + } + + private void ViewGraph(List points) + { + + var numbers = new List(); + var newList = new List(); + + for (int i = 0; i < points.Count; i++) + { + numbers.Add(i); + } + + var pointsPlot = points.Select(x => x.Close).ToArray(); + var signals = points.Select(x => x.Signal).ToArray(); + + foreach (var a in numbers) + { + newList.Add(a); + } + + var numbersArray = numbers.ToArray(); + var myScatter = WpfPlot1.Plot.Add.Scatter(numbersArray, pointsPlot); + + ScottPlot.Palettes.Category20 palette = new(); + for (int i = 0; i < points.Count; i++) + { + var item = points[i]; + if (item.Signal == true) + { + var mp = WpfPlot1.Plot.Add.Marker(i, (double)item.Close); + mp.MarkerShape = MarkerShape.OpenDiamond; + + mp.MarkerStyle.FillColor = palette.GetColor(8); + mp.MarkerStyle.Size = 1.5F; + mp.MarkerStyle.OutlineColor = palette.GetColor(8); + mp.MarkerStyle.OutlineWidth = 2; + mp.MarkerStyle.LineWidth = 2f; + mp.MarkerStyle.LineColor = palette.GetColor(10); + } + } + + myScatter.Color = ScottPlot.Colors.Green; + myScatter.LineWidth = 1; + myScatter.MarkerSize = 1.2F; + myScatter.MarkerShape = MarkerShape.OpenSquare; + myScatter.LinePattern = LinePattern.Solid; + WpfPlot1.Plot.Axes.AutoScale(); + + WpfPlot1.Refresh(); + + //double[] dataX = { 1, 2, 3, 4, 5 }; + //double[] dataY = { 1, 4, 9, 16, 25 }; + //WpfPlot1.Plot.Add.Scatter(dataX, dataY); + ////WpfPlot1.Plot.Axes.SetLimits(0, 5000, 0, 250); + //WpfPlot1.Plot.Axes.AutoScale(); + //WpfPlot1.Refresh(); + + } + + private List GetGraphData(string patternName, string json) + { + return _fiboTester.GetDataFromJson(patternName, json); + } + } +} \ No newline at end of file diff --git a/WPFGraphMaker/WPFGraphMaker.csproj b/WPFGraphMaker/WPFGraphMaker.csproj new file mode 100644 index 0000000..340877a --- /dev/null +++ b/WPFGraphMaker/WPFGraphMaker.csproj @@ -0,0 +1,20 @@ + + + + WinExe + net8.0-windows + enable + enable + true + + + + + + + + + + + +