Skip to content

Commit

Permalink
wpf chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliuser11 committed Dec 3, 2024
1 parent 82dba8e commit eca7dc0
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 16 deletions.
8 changes: 7 additions & 1 deletion Financial_Candlestick_Patterns.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion GraphCreator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ private void LoadData(object sender, EventArgs e)

private List<ZigZagObject> GetGraphData(string patternName)
{
return _fiboTester.GetGraphData(patternName);
var points = _fiboTester.GetData(patternName).Result;
return points;

}

protected override void Dispose(bool disposing)
Expand Down
51 changes: 37 additions & 14 deletions GraphMaker/FiboTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,25 @@ namespace GraphMaker
public interface IFiboTester
{
void ShowOnGraph(List<OhlcvObject> dataOhlcv, string patternName);
List<ZigZagObject> GetGraphData(string patternName);
Task<List<ZigZagObject>> GetData(string patternName);
Task<List<ZigZagObject>> GetPoints(string patternName);
//List<ZigZagObject> GetGraphData(List<ZigZagObject> list);
List<ZigZagObject> GetDataFromJson(string patternName, string json);
}

public class FiboTester : IFiboTester
{
IFibonacci _fibonacci;

public async Task<List<ZigZagObject>> 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<List<OhlcvObject>>(json).Select(x => new OhlcvObject()
Expand Down Expand Up @@ -110,12 +106,39 @@ static void GetGraph(List<ZigZagObject> points, string patternName)

}

public List<ZigZagObject> GetGraphData(string patternName)
public async Task<List<ZigZagObject>> GetData(string patternName)
{
var signalList = GetPoints(patternName);
List<ZigZagObject> points = signalList.Result;
return points;
var signalList = await GetPoints(patternName);
return signalList;
}

//public List<ZigZagObject> GetGraphData(List<ZigZagObject> list)
//{
// var signalList = taskList.Result;
// return signalList;
//}

public List<ZigZagObject> GetDataFromJson(string patternName, string json)
{
var dataOhlcv = JsonConvert.DeserializeObject<List<OhlcvObject>>(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<ZigZagObject> GetGraphData(List<ZigZagObject> list)
//{
// throw new NotImplementedException();
//}
}
}

Expand Down
11 changes: 11 additions & 0 deletions WPFGraphMaker/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Application x:Class="WPFGraphMaker.App"
xmlns:ScottPlot="clr-namespace:ScottPlot.WPF;assembly=ScottPlot.WPF"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFGraphMaker"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>

</Application>
14 changes: 14 additions & 0 deletions WPFGraphMaker/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;

namespace WPFGraphMaker
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

}
10 changes: 10 additions & 0 deletions WPFGraphMaker/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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)
)]
15 changes: 15 additions & 0 deletions WPFGraphMaker/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Window x:Class="WPFGraphMaker.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ScottPlot="clr-namespace:ScottPlot.WPF;assembly=ScottPlot.WPF"
mc:Ignorable="d"
Title="GraphWindow" Height="450" Width="800">

<Grid>
<ScottPlot:WpfPlot x:Name="WpfPlot1" />

</Grid>

</Window>
103 changes: 103 additions & 0 deletions WPFGraphMaker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -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<ZigZagObject> points = GetGraphData(patternName, json);
ViewGraph(points);

}

private void ViewGraph(List<ZigZagObject> points)
{

var numbers = new List<int>();
var newList = new List<double>();

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<ZigZagObject> GetGraphData(string patternName, string json)
{
return _fiboTester.GetDataFromJson(patternName, json);
}
}
}
20 changes: 20 additions & 0 deletions WPFGraphMaker/WPFGraphMaker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ScottPlot.WPF" Version="5.0.46" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Candlestick_Patterns\Candlestick_Patterns.csproj" />
<ProjectReference Include="..\GraphMaker\GraphMaker.csproj" />
</ItemGroup>

</Project>

0 comments on commit eca7dc0

Please sign in to comment.