Files
Million/Million Prototype/Form1.cs

899 lines
35 KiB
C#

using Million.Data;
using Million.Manager;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using DocumentFormat.OpenXml;
using DevExpress.XtraCharts;
using static Million.CommonProperty;
using Million.IndicatorConditionSetup;
using System.Drawing;
using Million.SubForm;
namespace Million_Prototype
{
public partial class Form1 : Form
{
//public static string accessKey = "4jfMUL3lpwJ5GQSszm3rPp5M47tD8ssfIGew2dDb";
//public static string secretKey = "iAasVxQt8CyADjzXaAZiF5VZXTZPdElJOP4m97Bz";
//UpbitAPI uApi = new UpbitAPI(accessKey,secretKey);
Stopwatch sw = new Stopwatch();
public Form1()
{
InitializeComponent();
var startDate = new DateTime(2022, 1, 1, 0, 0, 0);
var endDate = new DateTime(2022, 1, 2, 0, 0, 0);
var tableList = UpbitApi.GetMarketDatas(); //전체 목록
var market = tableList.FirstOrDefault(t => t.CodeFullName == "KRW-BTC");
var datas = IndicatorSetupManager.GetCalculateCandleData(new List<IndicatorCoditionSetup>(), startDate, endDate, market);
//ChartViewerForm chartViewerForm = new ChartViewerForm();
//chartViewerForm.setting(datas[MCandleTimeType.M1]);
//chartViewerForm.Show();
}
/// <summary>
/// 1. 데이터 저장
/// 2. 조건식 검색
/// 3. 도출
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
sw.Restart();
var data = UpbitApi.GetMarketDatas(); //전체 목록
var krwList = data.FindAll(x => x.Payment.Contains("KRW")); //한화 목록
List<CandleDataList> dataList = new List<CandleDataList>();
setCandleDataList(dataList, krwList);
//최초 데이터 전체 저장
//4시간, 1분
var dateTime = DateTime.Now;
//4시간 가져오기
foreach (var krw in dataList)
{
krw.CandleDataLists_Im = UpbitApi.GetCandleStics(krw.ConGoodsData.CodeFullName, MCandleTimeType.H4, dateTime);
}
/*
//1분 가져오기
foreach (var krw in dataList)
{
var startDateTime = dateTime;
var endDateTime = krw.CandleDataLists_4H.Last().DateTime;
do
{
krw.CandleDataLists_Im.AddRange(uApi.GetCandleStics(krw.ConGoodsData.CodeFullName, MCandleTimeType.M1, dateTime));
dateTime = krw.CandleDataLists_Im.Last().DateTime;
}
while (endDateTime < dateTime);
}*/
//볼린저 계산
//일목균형표 계산
var test = krwList.Select(t => t.CodeFullName).ToList();
//var 현재가 = uApi.GetOrderBookList(test);GetTickerList
var 현재가 = UpbitApi.GetTickerList(test);
foreach (var krw in krwList)
{
//candledataList.Add(uApi.GetCandleStics(krw.CodeFullName, Million.CommonProperty.MCandleTimeType.D1, DateTime.Now, 50));
}
sw.Stop();
listBox1.Items.Add("시간 : " + sw.ElapsedMilliseconds);
현재가.ToString();
}
public void setCandleDataList(List<CandleDataList> dataList, List<MarketData> marketDataList)
{
foreach (var marketData in marketDataList)
{
dataList.Add(new CandleDataList()
{
ConGoodsData = marketData,
});
}
}
//DB데이터 불러오기
private void button2_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
var dataList = new Dictionary<MCandleTimeType, List<CandleDataList>>();
var candleTypeList = new List<MCandleTimeType>();
candleTypeList.Add(MCandleTimeType.M1);
candleTypeList.Add(MCandleTimeType.H1);
RealtimeDataSettingManager realTimeMsg = null;
int firstFlag = 0;
for (; ; )
{
if (firstFlag == 0)
{
realTimeMsg = new RealtimeDataSettingManager(null, PaymentType.KRW);
dataList = realTimeMsg.GetRealTimeCandleData(candleTypeList, 200);
firstFlag = 1;
}
else
{
if (firstFlag == 1)
{
dataList = realTimeMsg.ProcessRecentlyCandleDatas(dataList, candleTypeList);
if (DateTime.Now.Second == 0)
{
realTimeMsg.EndRealTimeTicker();
realTimeMsg.StartGetRealTimeTicker(null);
}
}
}
}
}
private void button4_Click(object sender, EventArgs e)
{
//DbServiceFunctions.GetMarketTable_FromDB("Upbit");
//var tableList = CommonProperty.selectedMarketOfPlaceList;
//var resultList = new List<SearchResult>();
//var errorResultList = new List<SearchResult>();
//var win = 0;
//var lose = 0;
//foreach (var marketData in tableList)
//{
// var buyCandleList = new List<CandleDataList>();
// var sellList = new List<CandleData>();
// if (marketData != null)
// {
// //사는 로직
// var candleDataH1 = new CandleDataList();
// var candleDataM1 = new CandleDataList();
// var splitDataM = new List<List<CandleData>>();
// var splitData = ValidationCheckManager.GetValidationCandleDatas(marketData, ref splitDataM, ref candleDataH1, ref candleDataM1, new DateTime(2022, 1, 1), DateTime.Now);
// var buyData = new CandleDataList();
// buyData.ConGoodsData = marketData;
// buyData.CandleDataLists_Im = new List<CandleData>();
// foreach (var split in splitData)
// {
// var overData = split.FindAll(x => (int)x.IndicatorDic["Bol401"].overStatus >= -2 && x.IndicatorDic["Bol401"].overStatus != OverStatus.None
// && ((IchimokData)x.IndicatorDic["Ich"]).value < x.StartValue && ((IchimokData)x.IndicatorDic["Ich"]).value2 < x.StartValue);
// buyData = BuyLogicManager.GetBuyLogicByBol401Upper(overData, candleDataM1);
// if (buyData.CandleDataLists_Im != null && buyData.CandleDataLists_Im.Count > 0)
// buyCandleList.Add(buyData);
// }
// //파는 로직
// foreach (var item in splitDataM)
// {
// var sell1 = SellLogicManager.GetSellLogicOverUnderIch(item);
// var sell2 = SellLogicManager.GetSellLogicOVerUnderBol(item, 40, 1);
// var sell3 = SellLogicManager.GetSellLogicOVerUnderBol(item, 40, 2);
// sell1.AddRange(sell2);
// sell1.AddRange(sell3);
// var dateTimeList = sell1.Select(t => t.DateTime).Distinct().ToList();
// foreach (var date in dateTimeList)
// {
// sellList.Add(sell1.FirstOrDefault(t => t.DateTime == date));
// }
// }
// var result = new SearchResult();
// var sellData = new CandleData();
// //Result 계산
// foreach (var item in buyCandleList)
// {
// result.BuyList.ConGoodsData = marketData;
// if (item.CandleDataLists_Im.Count > 0)
// {
// sellData = sellList.FirstOrDefault(t => t.DateTime > item.CandleDataLists_Im[0].DateTime);
// if (sellData == null) continue;
// foreach (var buy in item.CandleDataLists_Im)
// {
// if (buy.DateTime < sellData.DateTime)
// {
// result.BuyList.CandleDataLists_Im.Add(buy);
// }
// else
// {
// var sDate = result.BuyList.CandleDataLists_Im[0].DateTime;
// var eDate = sellData.DateTime;
// //Result Data Setting
// result.TermCandleDataList = candleDataM1.CandleDataLists_Im.Where(x => x.DateTime >= sDate && x.DateTime <= eDate).ToList();
// result.CodeFullName = result.BuyList.ConGoodsData.CodeFullName;
// result.StartDate = sDate;
// result.EndDate = eDate;
// result.SellData = sellData;
// var sellLogicKeys = result.SellData.SellLogicFlag.Keys;
// double sellValue = 0;
// #region 파는 값 계산(파는 로직 중 제일 높은 값)
// var key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.IchMok);
// if (result.SellData.SellLogicFlag.ContainsKey(key))
// {
// if (sellValue < ((IchimokData)result.SellData.IndicatorDic["Ich"]).GetOverValue())
// {
// sellValue = ((IchimokData)result.SellData.IndicatorDic["Ich"]).GetOverValue();
// }
// }
// key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "401";
// if (result.SellData.SellLogicFlag.ContainsKey(key))
// {
// if (sellValue < result.SellData.IndicatorDic[key].overlapValue)
// {
// sellValue = result.SellData.IndicatorDic[key].overlapValue;
// }
// }
// key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "402";
// if (result.SellData.SellLogicFlag.ContainsKey(key))
// {
// if (sellValue < result.SellData.IndicatorDic[key].overlapValue)
// {
// sellValue = result.SellData.IndicatorDic[key].overlapValue;
// }
// }
// result.SellValue = sellValue;
// #endregion
// #region Rating 계산
// double totalVal = 0;
// foreach (var x in result.BuyList.CandleDataLists_Im)
// {
// var dateTime = x.DateTime.AddMinutes(x.DateTime.Minute * -1);
// var hCandle = candleDataH1.CandleDataLists_Im.FirstOrDefault(t => t.DateTime == dateTime);
// var buyValue = hCandle.IndicatorDic[Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "401"].overlapValue;
// var rate = ((sellValue - buyValue) / buyValue) * 100;
// result.BuyEarningRate.Add(rate);
// result.BuyValueList.Add(buyValue);
// if (rate >= 0) win++;
// else lose++;
// totalVal += rate;
// }
// result.TotalEarningRate = totalVal / result.BuyValueList.Count;
// #endregion
// var errorList = ValidationCheckManager.ValidateCandleDataList(result.TermCandleDataList, "", MCandleTimeType.M1);
// if (errorList.Count == 0)
// {
// result.SellData = sellData;
// resultList.Add(result);
// }
// else
// {
// result.SellData = sellData;
// errorResultList.Add(result);
// }
// result = new SearchResult();
// result.BuyList.CandleDataLists_Im.Add(buy);
// result.CodeFullName = result.BuyList.ConGoodsData.CodeFullName;
// sellData = sellList.FirstOrDefault(t => t.DateTime > buy.DateTime);
// }
// }
// }
// }
// //Sell 시점이 더 늦는 경우에 대한 처리(나중에 안에 있는 로직이랑 병합해서 한번에처리해야함
// if (result.BuyList.CandleDataLists_Im.Count > 0)
// {
// var sDate = result.BuyList.CandleDataLists_Im[0].DateTime;
// var eDate = sellData.DateTime;
// //Result Data Setting
// result.TermCandleDataList = candleDataM1.CandleDataLists_Im.Where(x => x.DateTime >= sDate && x.DateTime <= eDate).ToList();
// result.CodeFullName = result.BuyList.ConGoodsData.CodeFullName;
// result.StartDate = sDate;
// result.EndDate = eDate;
// result.SellData = sellData;
// var sellLogicKeys = result.SellData.SellLogicFlag.Keys;
// double sellValue = 0;
// #region 파는 값 계산(파는 로직 중 제일 높은 값)
// var key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.IchMok);
// if (result.SellData.SellLogicFlag.ContainsKey(key))
// {
// if (sellValue < ((IchimokData)result.SellData.IndicatorDic["Ich"]).GetOverValue())
// {
// sellValue = ((IchimokData)result.SellData.IndicatorDic["Ich"]).GetOverValue();
// }
// }
// key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "401";
// if (result.SellData.SellLogicFlag.ContainsKey(key))
// {
// if (sellValue < result.SellData.IndicatorDic[key].overlapValue)
// {
// sellValue = result.SellData.IndicatorDic[key].overlapValue;
// }
// }
// key = Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "402";
// if (result.SellData.SellLogicFlag.ContainsKey(key))
// {
// if (sellValue < result.SellData.IndicatorDic[key].overlapValue)
// {
// sellValue = result.SellData.IndicatorDic[key].overlapValue;
// }
// }
// result.SellValue = sellValue;
// #endregion
// #region Rating 계산
// double totalVal = 0;
// foreach (var x in result.BuyList.CandleDataLists_Im)
// {
// var dateTime = x.DateTime.AddMinutes(x.DateTime.Minute * -1);
// var hCandle = candleDataH1.CandleDataLists_Im.FirstOrDefault(t => t.DateTime == dateTime);
// var buyValue = hCandle.IndicatorDic[Enum.GetName(typeof(CommonProperty.SellLogicKeyList), CommonProperty.SellLogicKeyList.Bol) + "401"].overlapValue;
// var rate = ((sellValue - buyValue) / buyValue) * 100;
// result.BuyEarningRate.Add(rate);
// result.BuyValueList.Add(buyValue);
// if (rate >= 0) win++;
// else lose++;
// totalVal += rate;
// }
// result.TotalEarningRate = totalVal / result.BuyValueList.Count;
// #endregion
// var errorList = ValidationCheckManager.ValidateCandleDataList(result.TermCandleDataList, "", MCandleTimeType.M1);
// if (errorList.Count == 0)
// {
// result.SellData = sellData;
// resultList.Add(result);
// }
// else
// {
// result.SellData = sellData;
// errorResultList.Add(result);
// }
// }
// }
//}
//double total = 0;
//foreach (var item in resultList)
//{
// Console.WriteLine(item.CodeFullName);
// Console.WriteLine(item.TotalEarningRate);
// total += item.TotalEarningRate;
//}
//Console.WriteLine("Total 수익률 : " + total / resultList.Count);
//Console.WriteLine("Win : " + win);
//Console.WriteLine("Lose : " + lose);
//Console.WriteLine("승률 : " + win * 100 / (win + lose));
//resultList.ToString();
}
private void button5_Click(object sender, EventArgs e)
{
try
{
var ask_price = double.Parse(textBoxAskInput.Text);
textBoxAskOutput.Text = OrderbookManager.GetAskPrice(ask_price).ToString();
}
catch (Exception ex)
{
ex.ToString();
}
}
private void button6_Click(object sender, EventArgs e)
{
var s = new BolingerConditionSetup();
s.IndicatorType = IndicatorType.볼린저밴드;
s.MCandleTimeType = MCandleTimeType.D1;
s.Period = 30;
s.Squared = 2;
var d = new BolingerConditionSetup();
d.IndicatorType = IndicatorType.볼린저밴드;
d.MCandleTimeType = MCandleTimeType.D1;
d.Period = 30;
d.Squared = 1;
s.Equals(d).ToString();
}
/// <summary>
///
/// </summary>
/// <param name="aaa"></param>
/// <param name="select">true인 경우 큰값 가져옴</param>
/// <param name="bracket"></param>
/// <returns></returns>
public string exeStit(string aaa, bool select = true, bool bracket = true)
{
if (bracket)
{
if (aaa.First().CompareTo('(') == 0 && aaa.Last().CompareTo(')') == 0)
{
aaa = aaa.Substring(1, aaa.Length - 2);
}
}
aaa = aaa.Replace("&&", "&");
aaa = aaa.Replace("||", "|");
do
{
var orIndex = aaa.IndexOf('|');
var andIndex = aaa.IndexOf('&');
if (orIndex < 0 && andIndex < 0)
break;
orIndex = orIndex == -1 ? 100000 : orIndex;
andIndex = andIndex == -1 ? 100000 : andIndex;
var splitKey = orIndex > andIndex ? '&' : '|';
var splitOtherKey = orIndex < andIndex ? '&' : '|';
var splitStr1 = aaa.Split(splitKey).ToList();
var before = splitStr1[0];
var after = splitStr1[1].Split(splitOtherKey).First();
var selectOper = splitKey.CompareTo('&') == 0 ? select : !select;
var resultStr = "(" + before + (selectOper ? ">" : "<") + after + "?" + before + ":" + after + ")";
aaa = aaa.Replace(before + splitKey + after, resultStr);
} while (true);
return aaa;
}
private void button7_Click(object sender, EventArgs e)
{
try
{
InteratorScripter.ScriptExcute("true&&true");
List<char> keyList = new List<char>()
{
'(','&','|'
};
var sss = keyList.FirstOrDefault(x => x == '+');
var werwerewr = $"a a "+ " a";
werwerewr = werwerewr.Replace(" ", "");
//string qwer = "(1||2&&3)";
//exeStit(qwer);
var bb = 100 > 60 ? 100 : 60;
bb.ToString();
string aa = "(1 && 2)||(11 && (22 || 33))";
aa = "(111 && 112)||(11 &&12)||(22 || 33)";
//aa = "(99&&2&&3||4)||((111&&6)||7)";
aa = aa.Replace(" ", "");
Dictionary<string, bool> indicateFlagDic = new Dictionary<string, bool>()
{
{"111",true },
{"112",true },
{"11",false },
{"12",false },
{"22",true },
{"33",true },
};
Dictionary<string, double> conditionDic = new Dictionary<string, double>()
{
{"111",90 },
{"112",100 },
{"11",200 },
{"12",400 },
{"22",92 },
{"33",96 },
};
var result123123 = CalculateManager.GetConditionValue(aa, conditionDic, indicateFlagDic);
var index = aa.LastIndexOf('(');
Dictionary<string, string> substitution = new Dictionary<string, string>();
var count = 1;
//-1이면 못찾았다는 뜻
while (index != -1)
{
var countName = "S" + count.ToString();
var lastindex = aa.Substring(index + 1).IndexOf(')')+1;
var dd = aa.Substring(index , lastindex+1);
substitution.Add(countName, exeStit(dd));
aa = aa.Replace(dd, countName);
count++;
index = aa.LastIndexOf('(');
}
var ss123123 =substitution.Keys.FirstOrDefault(x => aa.Contains(x));
while(ss123123 != null)
{
aa = aa.Replace(ss123123, substitution[ss123123]);
ss123123 = substitution.Keys.FirstOrDefault(x => aa.Contains(x));
}
aa = exeStit(aa,true,false);
Dictionary<string, bool> aa1 = new Dictionary<string, bool>();
aa1["1"] = true;
aa1["22"] = true;
aa1["11"] = false;
aa1["2"] = true;
Dictionary<string, bool> aa2 = new Dictionary<string, bool>();
aa2["1"] = true;
aa2["2"] = true;
aa2["11"] = true;
aa2["22"] = true;
Dictionary<string, bool> aa3 = new Dictionary<string, bool>();
aa3["1"] = true;
aa3["2"] = true;
aa3["11"] = false;
aa3["22"] = true;
Dictionary<string, bool> aa4 = new Dictionary<string, bool>();
aa4["1"] = true;
aa4["2"] = true;
var returnvalue = aa1.Except(aa3).Any();
returnvalue = aa1.Except(aa2).Any();
returnvalue = aa1.Except(aa4).Any();
var ss123 = aa1.Except(aa3);
ss123 = aa1.Except(aa2);
ss123 = aa1.Except(aa4);
InteratorScripter ss = new InteratorScripter();
ss.regularExpressionString = aa;
ss.DicExcuteScript(aa1);
ss.DicExcuteScript(aa2);
ss.DicExcuteScript(aa3);
/*
var resultstring = InteratorScripter.ChangeScript(aa, aa1);
resultstring.ToString();
var test = CSharpScript.EvaluateAsync<bool>("(true && true)||(true && false)");
Console.WriteLine(test.Result);*/
}
catch (Exception ex)
{
ex.ToString();
}
}
private void button8_Click(object sender, EventArgs e)
{
Dictionary<string, bool> indicateFlagDic = new Dictionary<string, bool>()
{
{"111",true },
{"112",true },
{"11",false },
{"12",false },
{"22",true },
{"33",true },
};
Dictionary<string, double> conditionDic = new Dictionary<string, double>()
{
{"111",90 },
{"112",100 },
{"11",200 },
{"12",400 },
{"22",92 },
{"33",96 },
{"44",144 },
{"55",255 },
{"66",366 },
};
var conditionStr = "22|(33)";
conditionStr = "((11&22)|(33|44|55|66))";
List<char> keyList = new List<char>()
{
'(',')','&','|'
};
List<char> keyList2 = new List<char>()
{
'&','|'
};
var keyCount = 0;
foreach (var key in keyList)
{
keyCount += conditionStr.Split(key).Count() - 1;
}
//22|(33)
//22|(33|44|55|66)
var splitStr = conditionStr;
while (keyCount != 0)
{
var substitutionStr = splitStr;
var noIterChecker = true;
var indexDic = new Dictionary<char, int>();
//괄호가 있다면
if (splitStr.Split('(').Count() > 1)
{
var index = splitStr.LastIndexOf('(');
var lastindex = splitStr.Substring(index + 1).IndexOf(')') + 1;
substitutionStr = splitStr.Substring(index+1, lastindex-1);
}
foreach (var key in keyList2)
{
var temp = substitutionStr.IndexOf(key);
if (temp != -1)
noIterChecker = false;
indexDic.Add(key, substitutionStr.IndexOf(key));
}
var sortIndex = indexDic.OrderBy(x => x.Value);
//괄호는 있지만 연산자는 없을때 처리
if (noIterChecker)
{
splitStr = splitStr.Replace("(" + substitutionStr + ")", substitutionStr);
keyCount = 0;
foreach (var key in keyList)
{
keyCount += splitStr.Split(key).Count() - 1;
}
continue;
}
List<char> tKey = new List<char>();
foreach (var item in sortIndex)
{
if (item.Value != -1)
{
tKey.Add(item.Key);
}
}
var beforeStr = "";
var afterStr = "";
if (tKey.Count() >= 2)
{
var strList = substitutionStr.Split(tKey[0]);
beforeStr = strList.First();
afterStr = strList[1].Split(tKey[1]).First();
}
else if (tKey.Count() == 1)
{
var strList = substitutionStr.Split(tKey[0]);
beforeStr = strList[0];
afterStr = strList[1];
}
if (tKey[0] == '&')
{
splitStr = splitStr.Replace(beforeStr + "&" + afterStr, conditionDic[beforeStr] > conditionDic[afterStr] ? beforeStr : afterStr);
keyCount = 0;
foreach (var key in keyList)
{
keyCount += splitStr.Split(key).Count() - 1;
}
}
else if (tKey[0] == '|')
{
splitStr = splitStr.Replace(beforeStr + "|" + afterStr, conditionDic[beforeStr] < conditionDic[afterStr] ? beforeStr : afterStr);
keyCount = 0;
foreach (var key in keyList)
{
keyCount += splitStr.Split(key).Count() - 1;
}
}
}
splitStr.ToString();
}
private void button9_Click(object sender, EventArgs e)
{
List<double> asdf = new List<double>();
asdf.Add(0);
asdf.Add(1);
asdf.Add(2);
asdf.Add(3);
asdf.Add(4);
asdf.Add(5);
asdf.Add(6);
asdf.Add(7);
asdf.Add(8);
asdf.Add(9);
asdf.Add(10);
asdf.Add(11);
asdf.Add(12);
asdf.Add(13);
int period = 5;
List<double> asdf2 = new List<double>();
for (int i = 0;i < asdf.Count;i++)
{
asdf2.Add(asdf[i]);
if(i>period)
{
asdf2.RemoveAt(0);
}
}
}
private void button10_Click(object sender, EventArgs e)
{
//임의 데이터 생성
List<DataPoint> dataPoints = new List<DataPoint> {
new DataPoint(DateTime.Now.AddDays(-9), 24.00, 25.00, 25.00, 24.875),
new DataPoint(DateTime.Now.AddDays(-8), 23.625, 25.125, 24.00, 24.875),
new DataPoint(DateTime.Now.AddDays(-7), 26.25, 28.25, 26.75, 27.00),
new DataPoint(DateTime.Now.AddDays(-6), 26.50, 27.875, 26.875, 27.25),
new DataPoint(DateTime.Now.AddDays(-4), 25.75, 26.875, 26.75, 26.00),
new DataPoint(DateTime.Now.AddDays(-3), 25.75, 26.75, 26.125, 26.25),
new DataPoint(DateTime.Now.AddDays(-2), 25.75, 26.375, 26.375, 25.875),
new DataPoint(DateTime.Now.AddDays(-1), 24.875, 26.125, 26.00, 25.375),
new DataPoint(DateTime.Now.AddDays(0), 25.125, 26.00, 25.625, 25.75),
};
var datsd = DateTime.Now.AddDays(-9);
dataPoints = new List<DataPoint> {
new DataPoint(datsd, 24.00, 25.00, 25.00, 24.875),
new DataPoint(datsd.AddMinutes(1), 23.625, 25.125, 24.00, 24.875),
new DataPoint(datsd.AddMinutes(2), 26.25, 28.25, 26.75, 27.00),
//new DataPoint(datsd.AddMinutes(3), 26.50, 27.875, 26.875, 27.25),
//new DataPoint(datsd.AddMinutes(4), 25.75, 26.875, 26.75, 26.00),
new DataPoint(datsd.AddMinutes(5), 25.75, 26.75, 26.125, 26.25),
new DataPoint(datsd.AddMinutes(6), 25.75, 26.375, 26.375, 25.875),
new DataPoint(datsd.AddMinutes(7), 24.875, 26.125, 26.00, 25.375),
new DataPoint(datsd.AddMinutes(8), 25.125, 26.00, 25.625, 25.75),
};
var series1 = new Series("candle", ViewType.CandleStick);
series1.DataSource = dataPoints;
series1.SetFinancialDataMembers("Argument", "Low", "High", "Open", "Close");
series1.ArgumentScaleType = ScaleType.DateTime;
chartControl1.Series.Add(series1);
CandleStickSeriesView view = (CandleStickSeriesView)series1.View;
view.LineThickness = 2;
view.LevelLineLength = 0.25;
// Specify the series reduction options.
view.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue;
view.ReductionOptions.FillMode = CandleStickFillMode.AlwaysEmpty;
view.ReductionOptions.Level = StockLevel.Close;
view.ReductionOptions.Visible = true;
view.Color = Color.Blue;
view.ReductionOptions.Color = Color.Red;
// Access the chart's diagram.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
// Exclude empty ranges from the X-axis range
// to avoid gaps in the chart's data.
//diagram.AxisX.DateTimeScaleOptions.SkipRangesWithoutPoints = true;
// Hide the range without points at the beginning of the y-axis.
diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false;
diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Minute;
diagram.AxisX.DateTimeScaleOptions.MeasureUnitMultiplier = 3;
//diagram.AxisX.VisualRange.
}
}
public class DataPoint
{
public DateTime Argument { get; set; }
public double Low { get; set; }
public double High { get; set; }
public double Open { get; set; }
public double Close { get; set; }
public DataPoint(DateTime argument, double low, double high, double open, double close)
{
this.Argument = argument;
this.Low = low;
this.High = high;
this.Open = open;
this.Close = close;
}
}
}