public async Task SnapshotWithPriceHistoryInBaseCurrency() { YahooQuotes yahooQuotes = new YahooQuotesBuilder() .HistoryStarting(Instant.FromUtc(2020, 7, 15, 0, 0)) .WithCaching(snapshotDuration: Duration.FromMinutes(30), historyDuration: Duration.FromHours(6)) .Build(); Security security = await yahooQuotes .GetAsync("TSLA", HistoryFlags.PriceHistory, historyBase : "JPY=X") ?? throw new ArgumentException("Unknown symbol: TSLA."); Assert.Equal("Tesla, Inc.", security.ShortName); Assert.Equal("USD", security.Currency); Assert.Equal("America/New_York", security.ExchangeTimezone?.Id); PriceTick tick = security.PriceHistory.Value[0]; Assert.Equal(new LocalDate(2020, 7, 15), tick.Date); Assert.Equal(309.202, tick.Close); // in USD var instant = new LocalDateTime(2020, 7, 15, 16, 0, 0) .InZoneLeniently(security.ExchangeTimezone !).ToInstant(); ValueTick tickBase = security.PriceHistoryBase.Value[0]; Assert.Equal(instant, tickBase.Date); Assert.Equal(33139, tickBase.Value, 0); // in JPY }
public double GetRevenuePrice2() { double revenuePrice = 0; try { if (RevenueRate != 0) { if (Position == "2") { revenuePrice = PriceTick.GetDownPriceOfRate(ItemCode, HPrice, RevenueRate); } if (Position == "1") { revenuePrice = PriceTick.GetUpPriceOfRate(ItemCode, LPrice, RevenueRate); } } if (Position == "2" && revenuePrice < AvgPrice2) { revenuePrice = 0; } if (Position == "1" && revenuePrice > AvgPrice1) { revenuePrice = 0; } } catch (Exception) { } return(revenuePrice); }
private void calculateRevenueLosscutTick(string price) { this.Invoke(new MethodInvoker(() => { try { if (rule.RevenuePrice > 0) { double p = Convert.ToDouble(price); int tick = PriceTick.GetTickDiff(rule.ItemCode, rule.BuyPrice, p); if (rule.Position == "1" && rule.BuyPrice > p) { lblRevenueTick.Text = "+" + tick.ToString(); lblRevenueTick.ForeColor = Color.Red; } else if (rule.Position == "2" && rule.BuyPrice < p) { lblRevenueTick.Text = "+" + tick.ToString(); lblRevenueTick.ForeColor = Color.Red; } else { lblRevenueTick.Text = "-" + tick.ToString(); lblRevenueTick.ForeColor = Color.Blue; } } } catch (Exception) { } })); }
public void Summary(string itemCode, QuantumLineChart c) { var data2 = c.ChartData[c.ChartData.Count - 2]; var data1 = c.ChartData[c.ChartData.Count - 1]; Lib.Base.Enums.UpDownEnum upDown1 = Lib.Base.Enums.UpDownEnum.None; if (data2.T_QuantumAvg < data2.T_MassAvg && data1.T_QuantumAvg < data1.T_MassAvg) { upDown1 = UpDownEnum.StrongUp; } else if (data2.T_QuantumAvg < data2.T_MassAvg && data1.T_QuantumAvg >= data1.T_MassAvg) { upDown1 = UpDownEnum.WeakUp; } CandleSummary.Instance.UpdateSummaryTrend(itemCode, c.TimeInterval, "매수", upDown1); Lib.Base.Enums.UpDownEnum upDown2 = Lib.Base.Enums.UpDownEnum.None; if (data2.T_QuantumAvg > data2.T_MassAvg && data1.T_QuantumAvg > data1.T_MassAvg) { upDown1 = UpDownEnum.StrongDown; } else if (data2.T_QuantumAvg < data2.T_MassAvg && data1.T_QuantumAvg <= data1.T_MassAvg) { upDown1 = UpDownEnum.WeakDown; } CandleSummary.Instance.UpdateSummaryTrend(itemCode, c.TimeInterval, "매도", upDown2); int tick2 = PriceTick.GetTickDiff(itemCode, data2.MassPrice, data2.QuantumPrice); int tick1 = PriceTick.GetTickDiff(itemCode, data1.MassPrice, data1.QuantumPrice); CandleSummary.Instance.UpdateSummaryTrendOfStrength(itemCode, c.TimeInterval, "매수", tick2); CandleSummary.Instance.UpdateSummaryTrendOfStrength(itemCode, c.TimeInterval, "매도", tick2); }
private void tbAvgPrice1_KeyDown(object sender, KeyEventArgs e) { if (tbAvgPrice1.Text.Length == 0) { return; } int lossTick1 = 15; int lossTick2 = 30; int revenueTick = 60; if (e.KeyCode == Keys.Enter) { if (tbLossPrice1.Text == "0") { tbLossPrice1.Text = PriceTick.GetUpPriceOfTick(rule.ItemCode, rule.AvgPrice1, lossTick1).ToString(); } if (tbLossPrice2.Text == "0") { tbLossPrice2.Text = PriceTick.GetUpPriceOfTick(rule.ItemCode, rule.AvgPrice1, lossTick2).ToString(); } if (tbMinimumRevenue1.Text == "0") { tbMinimumRevenue1.Text = PriceTick.GetDownPriceOfTick(rule.ItemCode, rule.AvgPrice1, revenueTick).ToString(); } } }
public static string Calculator(string itemCode, string strategyType, string position, double buyPrice, double currrentPrice) { string revenuePrice = "0"; int revenueTick = 0; try { if (strategyType == "1") { revenueTick = Config.RevenueConfig.LOW_LIMIT_TICKS; } else if (strategyType == "2") { revenueTick = Config.RevenueConfig.MIDDLE_LIMIT_TICKS; } else if (strategyType == "3") { revenueTick = Config.RevenueConfig.HIGH_LIMIT_TICKS; } int roundNum = ItemCodeUtil.GetItemCodeRoundNum(itemCode); //매도 if (position == "1") { //손실 if (buyPrice < currrentPrice) { revenuePrice = Math.Round(PriceTick.GetDownPriceOfTick(itemCode, buyPrice, revenueTick), roundNum).ToString(); } //수익 else { revenuePrice = Math.Round(PriceTick.GetDownPriceOfTick(itemCode, buyPrice, revenueTick), roundNum).ToString(); } } //매수 else if (position == "2") { //손실 if (buyPrice > currrentPrice) { revenuePrice = Math.Round(PriceTick.GetUpPriceOfTick(itemCode, buyPrice, revenueTick), roundNum).ToString(); } //수익 else { revenuePrice = Math.Round(PriceTick.GetUpPriceOfTick(itemCode, buyPrice, revenueTick), roundNum).ToString(); } } } catch (Exception) { } return(revenuePrice); }
private void tbP1BuyPrice1_KeyDown(object sender, KeyEventArgs e) { if (tbP1BuyPrice1.Text.Length == 0) { return; } int lossTick1 = 10; int lossTick2 = 20; int revenueTick = 30; if (rdoSType1.Checked) { lossTick1 = 20; lossTick2 = 30; revenueTick = 50; } else if (rdoSType2.Checked) { lossTick1 = 5; lossTick2 = 10; revenueTick = 30; } else if (rdoSType3.Checked) { lossTick1 = 20; lossTick2 = 40; revenueTick = 100; } if (e.KeyCode == Keys.Enter) { if (tbP1BuyPrice2.Text == "0") { tbP1BuyPrice2.Text = PriceTick.GetDownPriceOfTick(rule.Item, rule.P1BuyPrice1[0], 5).ToString(); } if (tbP1BuyPrice3.Text == "0") { tbP1BuyPrice3.Text = PriceTick.GetDownPriceOfTick(rule.Item, rule.P1BuyPrice1[0], 10).ToString(); } if (tbP1LossPrice1.Text == "0") { tbP1LossPrice1.Text = PriceTick.GetUpPriceOfTick(rule.Item, rule.P1BuyPrice1[2], lossTick1).ToString(); } if (tbP1LossPrice2.Text == "0") { tbP1LossPrice2.Text = PriceTick.GetUpPriceOfTick(rule.Item, rule.P1BuyPrice1[2], lossTick2).ToString(); } if (tbMinimumRevenue1.Text == "0") { tbMinimumRevenue1.Text = PriceTick.GetDownPriceOfTick(rule.Item, rule.P1BuyPrice1[2], revenueTick).ToString(); } } }
public double GetLossPrice(double basePrice) { double lossPrice = 0; try { if (ruleInfo.LossPrice != "0") { lossPrice = Convert.ToDouble(ruleInfo.LossPrice); } else if (ruleInfo.LossTick != "0") { if (ruleInfo.Position == "매수") { lossPrice = PriceTick.GetDownPriceOfTick(ItemCode, basePrice, Convert.ToInt32(ruleInfo.LossTick)); } if (ruleInfo.Position == "매도") { lossPrice = PriceTick.GetUpPriceOfTick(ItemCode, basePrice, Convert.ToInt32(ruleInfo.LossTick)); } } else if (ruleInfo.LossRate != "0") { if (ruleInfo.Position == "매수") { lossPrice = PriceTick.GetDownPriceOfRate(ItemCode, basePrice, Convert.ToDouble(ruleInfo.LossRate)); } if (ruleInfo.Position == "매도") { lossPrice = PriceTick.GetUpPriceOfRate(ItemCode, basePrice, Convert.ToDouble(ruleInfo.LossRate)); } } if (ruleInfo.Position == "매수" && lossPrice <= CPrice) { lossPrice = 0; } if (ruleInfo.Position == "매도" && lossPrice >= CPrice) { lossPrice = 0; } } catch (Exception ex) { string err = ex.Message; } return(lossPrice); }
public double GetRevenuePrice(double basePrice) { double revenuePrice = 0; try { if (ruleInfo.RevenuePrice != "0") { revenuePrice = Convert.ToDouble(ruleInfo.RevenuePrice); } else if (ruleInfo.RevenueTick != "0") { if (ruleInfo.Position == "매수") { revenuePrice = PriceTick.GetDownPriceOfTick(ItemCode, HPrice, Convert.ToInt32(ruleInfo.RevenueTick)); } if (ruleInfo.Position == "매도") { revenuePrice = PriceTick.GetUpPriceOfTick(ItemCode, LPrice, Convert.ToInt32(ruleInfo.RevenueTick)); } } else if (ruleInfo.RevenueRate != "0") { if (ruleInfo.Position == "매수") { revenuePrice = PriceTick.GetDownPriceOfRate(ItemCode, HPrice, Convert.ToDouble(ruleInfo.RevenueRate)); } if (ruleInfo.Position == "매도") { revenuePrice = PriceTick.GetUpPriceOfRate(ItemCode, LPrice, Convert.ToDouble(ruleInfo.RevenueRate)); } } if (ruleInfo.Position == "매수" && revenuePrice <= basePrice) { revenuePrice = 0; } if (ruleInfo.Position == "매도" && revenuePrice >= basePrice) { revenuePrice = 0; } } catch (Exception ex) { string err = ex.Message; } return(revenuePrice); }
private void calculateRevenueTick(string price) { this.Invoke(new MethodInvoker(() => { try { tbRevenuePrice.Text = Cals.RevenueCalculater.Calculator(rule); if (rule.RevenuePrice > 0) { double p = Convert.ToDouble(price); int tick = PriceTick.GetTickDiff(rule.ItemCode, rule.RevenuePrice, p); tbRevenuePriceTick.Text = tick.ToString(); } } catch (Exception) { } })); }
public async Task SnapshotWithPriceHistory() { YahooQuotes yahooQuotes = new YahooQuotesBuilder() .HistoryStarting(Instant.FromUtc(2020, 1, 1, 0, 0)) .Build(); Security security = await yahooQuotes.GetAsync("MSFT", HistoryFlags.PriceHistory) ?? throw new ArgumentException("Unknown symbol: MSFT."); Assert.Equal("NasdaqGS", security.FullExchangeName); PriceTick[] priceHistory = security.PriceHistory.Value; PriceTick tick = priceHistory[0]; Assert.Equal(new LocalDate(2020, 1, 2), tick.Date); Assert.Equal(160.62, tick.Close); }
public double GetRevenuePrice2() { double revenuePrice = 0; try { if (RevenueRate != 0) { if (Position == "매수") revenuePrice = PriceTick.GetDownPriceOfRate(ItemCode, HPrice, RevenueRate); if (Position == "매도") revenuePrice = PriceTick.GetUpPriceOfRate(ItemCode, LPrice, RevenueRate); } if (Position == "매수" && revenuePrice < BuyPrice) revenuePrice = 0; if (Position == "매도" && revenuePrice > BuyPrice) revenuePrice = 0; } catch (Exception ) { } return revenuePrice; }
private void calculateLosscutTick(string price) { this.Invoke(new MethodInvoker(() => { try { if (IsAutoLosscutCal) { tbLosscutPrice.Text = Cals.LosscutCalculater.Calculator(rule); } if (rule.LosscutPrice > 0) { double p = Convert.ToDouble(price); int tick = PriceTick.GetTickDiff(rule.ItemCode, rule.LosscutPrice, p); tbLosscutPriceTick.Text = tick.ToString(); } } catch (Exception) { } })); }
public void SummaryPrice(double cPrice) { if (ChartData != null && ChartData.Count == 1) { this.Invoke(new Action(() => { double hPrice = Convert.ToDouble(lblH.Text); double lPrice = Convert.ToDouble(lblL.Text); double qhPrice = Convert.ToDouble(lblMH.Text); double qlPrice = Convert.ToDouble(lblML.Text); int hTick = PriceTick.GetTickDiff(ItemCode, hPrice, cPrice); int lTick = PriceTick.GetTickDiff(ItemCode, lPrice, cPrice); int qhTick = PriceTick.GetTickDiff(ItemCode, qhPrice, cPrice); int qlTick = PriceTick.GetTickDiff(ItemCode, qlPrice, cPrice); lblH.Text = $"{Math.Round(hPrice, RoundLength).ToString()}"; lblH.Visible = true; lblL.Text = $"{Math.Round(lPrice, RoundLength).ToString()}"; lblL.Visible = true; lblMH.Text = $"{Math.Round(qhPrice, RoundLength).ToString()}"; lblMH.Visible = true; lblML.Text = $"{Math.Round(qlPrice, RoundLength).ToString()}"; lblML.Visible = true; lblHTick.Text = $"{(hPrice > cPrice ? "+" : "-")}{hTick}"; lblHTick.Visible = true; lblLTick.Text = $"{(lPrice > cPrice ? "+" : "-")}{lTick}"; lblLTick.Visible = true; lblMHTick.Text = $"{(qhPrice > cPrice ? "+" : "-")}{qhTick}"; lblMHTick.Visible = true; lblMLTick.Text = $"{(qlPrice > cPrice ? "+" : "-")}{qlTick}"; lblMLTick.Visible = true; SetPriceLineAnnotation(cPrice); })); } }
private void btnCal_Click(object sender, EventArgs e) { double buyRate = Convert.ToDouble(tbBuyRate.Text); double revenueRate = Convert.ToDouble(tbRevenueRate.Text); double lossRate = Convert.ToDouble(tbLossRate.Text); string itemCode = tbItem.Text; string position = tbTimeType.Text; double basePrice = Convert.ToDouble(tbBasePrice.Text); double baseRevenueRate = 1.0; if (position == "매수") { tbBuyPrice.Text = PriceTick.GetDownPriceOfRate(itemCode, basePrice, buyRate).ToString(); tbBuyTick.Text = PriceTick.GetTickDiff(itemCode, basePrice, Convert.ToDouble(tbBuyPrice.Text)).ToString(); double hPrice = PriceTick.GetUpPriceOfRate(itemCode, basePrice, baseRevenueRate); tbRevenuePrice.Text = PriceTick.GetDownPriceOfRate(itemCode, hPrice, revenueRate).ToString(); tbRevenueTick.Text = PriceTick.GetTickDiff(itemCode, hPrice, Convert.ToDouble(tbRevenuePrice.Text)).ToString(); tbLossPrice.Text = PriceTick.GetDownPriceOfRate(itemCode, basePrice, lossRate).ToString(); tbLossTick.Text = PriceTick.GetTickDiff(itemCode, basePrice, Convert.ToDouble(tbLossPrice.Text)).ToString(); } if (position == "매도") { tbBuyPrice.Text = PriceTick.GetUpPriceOfRate(itemCode, basePrice, buyRate).ToString(); tbBuyTick.Text = PriceTick.GetTickDiff(itemCode, basePrice, Convert.ToDouble(tbBuyPrice.Text)).ToString(); double lPrice = PriceTick.GetDownPriceOfRate(itemCode, basePrice, baseRevenueRate); tbRevenuePrice.Text = PriceTick.GetUpPriceOfRate(itemCode, lPrice, revenueRate).ToString(); tbRevenueTick.Text = PriceTick.GetTickDiff(itemCode, lPrice, Convert.ToDouble(tbRevenuePrice.Text)).ToString(); tbLossPrice.Text = PriceTick.GetUpPriceOfRate(itemCode, basePrice, lossRate).ToString(); tbLossTick.Text = PriceTick.GetTickDiff(itemCode, basePrice, Convert.ToDouble(tbLossPrice.Text)).ToString(); } }
public double GetBuyPrice(double basePrice) { double buyPrice = 0; try { if (ruleInfo.BuyPrice != "0") { buyPrice = Convert.ToDouble(ruleInfo.BuyPrice); } else if (ruleInfo.BuyTick != "0") { if (ruleInfo.Position == "매수") { buyPrice = PriceTick.GetDownPriceOfTick(ItemCode, basePrice, Convert.ToInt32(ruleInfo.BuyTick)); } if (ruleInfo.Position == "매도") { buyPrice = PriceTick.GetUpPriceOfTick(ItemCode, basePrice, Convert.ToInt32(ruleInfo.BuyTick)); } } else if (ruleInfo.BuyRate != "0") { if (ruleInfo.Position == "매수") { buyPrice = PriceTick.GetDownPriceOfRate(ItemCode, basePrice, Convert.ToDouble(ruleInfo.BuyRate)); } if (ruleInfo.Position == "매도") { buyPrice = PriceTick.GetUpPriceOfRate(ItemCode, basePrice, Convert.ToDouble(ruleInfo.BuyRate)); } } } catch (Exception ex) { string err = ex.Message; } return(buyPrice); }
internal static PriceTick[] GetInstrumentPriceTick(Guid instrumentId) { using (SqlConnection sqlConnection = new SqlConnection(SettingManager.Default.ConnectionString)) { using (SqlCommand sqlCommand = new SqlCommand("Bursa.P_GetInstrumentPriceTick", sqlConnection)) { sqlCommand.CommandType = CommandType.StoredProcedure; SqlParameter sqlParameter = sqlCommand.Parameters.Add("@instrumentId", SqlDbType.UniqueIdentifier); sqlParameter.Value = instrumentId; sqlConnection.Open(); List<PriceTick> priceTickList = new List<PriceTick>(); using (SqlDataReader reader = sqlCommand.ExecuteReader()) { while (reader.Read()) { PriceTick priceTick = new PriceTick(); priceTick.PriceTickSetIndex = (string)reader["PriceTickSetIndex"]; priceTick.Sequence = (int)reader["Sequence"]; priceTick.MinimumPrice = null; if (reader["MinimumPrice"] != DBNull.Value) { priceTick.MinimumPrice = (double)(decimal)reader["MinimumPrice"]; } priceTick.Tick = (double)(decimal)reader["PriceTick"]; priceTickList.Add(priceTick); } } return priceTickList.ToArray(); } } }
public void NotifyClient(PriceTick tick) { //Do some action }
public override void View() { pnlScroll.Visible = IsAutoScrollX; if (ChartData == null) { return; } double maxPrice = 0.0; double minPrice = 0.0; int bDistance = -1; foreach (var item in ChartData) { int idx = chart.Series[0].Points.AddXY(item.DTime, item.HighPrice, item.LowPrice, item.OpenPrice, item.ClosePrice); chart.Series[1].Points.AddXY(item.DTime, item.T_MassAvg); chart.Series[2].Points.AddXY(item.DTime, item.T_QuantumAvg); chart.Series[3].Points.AddXY(item.DTime, item.T_QuantumHighAvg); chart.Series[4].Points.AddXY(item.DTime, item.T_QuantumLowAvg); //double d = Math.Round(Math.Abs(item.MassPrice - item.QuantumPrice), RoundLength); int d = PriceTick.GetTickDiff(ItemCode, item.MassPrice, item.QuantumPrice); chart.Series[5].Points.AddXY(item.DTime, d); if (bDistance != -1) { if (d > bDistance) { chart.Series[5].Points[idx].Color = Color.DarkRed; } else { chart.Series[5].Points[idx].Color = Color.DarkBlue; } } bDistance = d; var dataPoint = chart.Series[0].Points[idx]; } chart.Series[3].Enabled = chart.Series[4].Enabled = false; maxPrice = ChartData.Max(m => m.HighPrice); minPrice = ChartData.Min(m => m.LowPrice); double maxPrice2 = ChartData.Max(m => m.T_QuantumHighAvg); double minPrice2 = ChartData.Min(m => m.T_QuantumLowAvg); if (maxPrice < maxPrice2) { maxPrice = maxPrice2; } if (minPrice > minPrice2) { minPrice = minPrice2; } maxPrice2 = ChartData.Max(m => m.T_CloseAvg); minPrice2 = ChartData.Min(m => m.T_CloseAvg); if (maxPrice < maxPrice2) { maxPrice = maxPrice2; } if (minPrice > minPrice2) { minPrice = minPrice2; } maxPrice2 = ChartData.Max(m => m.T_QuantumAvg); minPrice2 = ChartData.Min(m => m.T_QuantumAvg); if (maxPrice < maxPrice2) { maxPrice = maxPrice2; } if (minPrice > minPrice2) { minPrice = minPrice2; } maxPrice = maxPrice + SpaceMaxMin; minPrice = minPrice - SpaceMaxMin; chart.ChartAreas[0].AxisY2.Maximum = maxPrice; chart.ChartAreas[0].AxisY2.Minimum = minPrice; chart.ChartAreas[0].AxisY.Maximum = 10000; chart.ChartAreas[0].AxisY.Minimum = 0; SetTrackBar(); SetScrollBar(); DisplayView(); IsLoaded = true; base.View(); }
public void Bind(A_HLOC hloc, int type = 0) { lblTime.Text = hloc.DTime.ToString("yyyy-MM-dd HH:mm"); Dictionary <string, float> abc = new Dictionary <string, float>(); abc.Add("시가", hloc.OpenPrice); abc.Add("고가", hloc.HighPrice); abc.Add("저가", hloc.LowPrice); abc.Add("종가", hloc.ClosePrice); abc.Add("중앙가", hloc.CenterPrice); abc.Add("중심가", hloc.MiddlePrice); abc.Add("양중앙가", hloc.QuantumCenterPrice); abc.Add("양중심가", hloc.QuantumMiddlePrice); abc.Add("양고가", hloc.QuantumHighPrice); abc.Add("양저가", hloc.QuantumLowPrice); abc.Add("양종가", hloc.QuantumPrice); abc.Add("질량가", hloc.MassPrice); double h1 = abc["양고가"] > abc["고가"] ? abc["양고가"] : abc["고가"]; double l1 = abc["양저가"] < abc["저가"] ? abc["양저가"] : abc["저가"]; lblMaxMin.Text = Math.Round(Math.Abs(h1 - l1), hloc.RoundLength).ToString() + " / " + PriceTick.GetTickDiff(hloc.ItemCode, h1, l1).ToString(); double h2 = abc["고가"]; double l2 = abc["저가"]; lblHighLow.Text = Math.Round(Math.Abs(h2 - l2), hloc.RoundLength).ToString() + " / " + PriceTick.GetTickDiff(hloc.ItemCode, h2, l2).ToString(); lblMiddle.Text = Math.Round(Math.Abs(abc["양중심가"] - abc["중심가"]), hloc.RoundLength).ToString() + " / " + PriceTick.GetTickDiff(hloc.ItemCode, abc["양중심가"], abc["중심가"]).ToString(); lblCenter.Text = Math.Round(Math.Abs(abc["양중앙가"] - abc["중앙가"]), hloc.RoundLength).ToString() + " / " + PriceTick.GetTickDiff(hloc.ItemCode, abc["양중앙가"], abc["중앙가"]).ToString(); lblMassClose.Text = Math.Round(Math.Abs(abc["질량가"] - abc["종가"]), hloc.RoundLength).ToString() + " / " + PriceTick.GetTickDiff(hloc.ItemCode, abc["질량가"], abc["종가"]).ToString(); lblMassQClose.Text = Math.Round(Math.Abs(abc["질량가"] - abc["양종가"]), hloc.RoundLength).ToString() + " / " + PriceTick.GetTickDiff(hloc.ItemCode, abc["질량가"], abc["양종가"]).ToString(); int idx = 0; foreach (var m in abc.OrderByDescending(t => t.Value)) { textBoxes[idx].ForeColor = labels[idx].ForeColor = SystemColors.ControlText; labels[idx].Text = m.Key; if (type == 0) { if (m.Key == "양종가" || m.Key == "양중앙가" || m.Key == "양중심가") { if (hloc.ClosePrice < hloc.QuantumPrice) { textBoxes[idx].ForeColor = labels[idx].ForeColor = Color.Red; } else if (hloc.ClosePrice > hloc.QuantumPrice) { textBoxes[idx].ForeColor = labels[idx].ForeColor = Color.Blue; } } } else if (type == 1) { string h = abc["양고가"] > abc["고가"] ? "양고가" : "고가"; string l = abc["양저가"] < abc["저가"] ? "양저가" : "저가"; if (m.Key == h || m.Key == l) { if (hloc.ClosePrice < hloc.QuantumPrice) { textBoxes[idx].ForeColor = labels[idx].ForeColor = Color.Red; } else if (hloc.ClosePrice > hloc.QuantumPrice) { textBoxes[idx].ForeColor = labels[idx].ForeColor = Color.Blue; } } } else if (type == 2) { if (m.Key == "양중앙가" || m.Key == "중앙가") { if (hloc.ClosePrice < hloc.QuantumPrice) { textBoxes[idx].ForeColor = labels[idx].ForeColor = Color.Red; } else if (hloc.ClosePrice > hloc.QuantumPrice) { textBoxes[idx].ForeColor = labels[idx].ForeColor = Color.Blue; } } } textBoxes[idx].Text = m.Value.ToString(); idx++; } }
public void GetSise(CurrentPrice price = null) { try { if (candle != null && price != null) { var nextTime = candle.DTime.AddMinutes(EnumUtil.GetIntervalValueToMinutes(ruleInfo.TimeType)); if (price.DTime < nextTime) { return; } } PurushaPrakriti pp = new PurushaPrakriti(); pp.Item = ruleInfo.Item; pp.Interval = (int)EnumUtil.GetTimeIntervalValue(ruleInfo.TimeType); pp.DisplayCount = 5; try { Entities entities = (Entities)pp.Collect(new Query("USP_PP_SIMPLE_LST")); List <PurushaPrakriti> list = entities.Cast <PurushaPrakriti>().ToList(); List <int> ticks = new List <int>(); foreach (var k in list.GetRange(1, 4)) { int tick = PriceTick.GetTickDiff(ItemCode , Convert.ToDouble(k.OpenVal) , Convert.ToDouble(k.CloseVal)); ticks.Add(tick); } int avgTick = Convert.ToInt32(ticks.Average()); if (avgTick < limitTicks) { avgTick = limitTicks; } var m = list[1]; if (candle != null) { if (candle.HighPrice > m.HighVal && candle.LowPrice < m.LowVal) { return; } int tick = PriceTick.GetTickDiff(ItemCode , Convert.ToDouble(candle.OpenPrice) , Convert.ToDouble(candle.ClosePrice)); if (tick < avgTick) { return; } } candle = new S_CandleItemData(ItemCode, m.OpenVal, m.HighVal, m.LowVal, m.CloseVal, m.Volume, m.DT); if (!ruleInfo.IsBuyDone) { InitRule(); } else { ruleInfo.IsCanRevenue = true; } } catch (Exception ex) { string err = ex.Message; } } catch (Exception) { } }
public override void View() { pnlScroll.Visible = IsAutoScrollX; if (ChartData == null) { return; } if (ChartDataSub == null) { return; } if (IsShowCandle) { chart.Series[3].Enabled = chart.Series[4].Enabled = false; } int bDistance = -1; T_QuantumItemData bItem = null; for (int i = 0; i < ChartData.Count; i++) { var item = ChartData[i]; int idx = chart.Series[0].Points.AddXY(item.DTime, item.HighPrice, item.LowPrice, item.OpenPrice, item.ClosePrice); item = ChartDataSub[i]; if (IsShowCandle) { chart.Series[1].Points.AddXY(item.DTime, item.T_MassAvg); chart.Series[2].Points.AddXY(item.DTime, item.T_QuantumAvg); } else { chart.Series[1].Points.AddXY(item.DTime, item.T_OpenAvg); chart.Series[2].Points.AddXY(item.DTime, item.T_CloseAvg); chart.Series[3].Points.AddXY(item.DTime, item.T_VikalaAvg); chart.Series[4].Points.AddXY(item.DTime, item.T_QuantumAvg); } int d = PriceTick.GetTickDiff(ItemCode, item.MassPrice, item.TotalCenterPrice); chart.Series[5].Points.AddXY(item.DTime, d); if (bDistance != -1) { if (d > bDistance) { chart.Series[5].Points[idx].Color = Color.DarkRed; } else { chart.Series[5].Points[idx].Color = Color.DarkBlue; } } if (d == 0 && bItem != null) { var p = chart.Series[5].Points[idx]; bool isSignal = false; if (item.T_MassAvg < item.T_QuantumAvg) { if (item.T_QuantumAvg < item.LowPrice) { isSignal = true; } if (item.T_MassAvg > item.HighPrice) { isSignal = true; } } if (item.T_MassAvg > item.T_QuantumAvg) { if (item.T_QuantumAvg > item.HighPrice) { isSignal = true; } if (item.T_MassAvg < item.LowPrice) { isSignal = true; } } if (isSignal) { p.Label = "↑"; } } bDistance = d; var dataPoint = chart.Series[0].Points[idx]; bItem = item; } //maxPrice = ChartData.Max(m => m.HighPrice); //minPrice = ChartData.Min(m => m.LowPrice); //double maxPrice2 = ChartData.Max(m => m.T_QuantumHighAvg); //double minPrice2 = ChartData.Min(m => m.T_QuantumLowAvg); //if (maxPrice < maxPrice2) maxPrice = maxPrice2; //if (minPrice > minPrice2) minPrice = minPrice2; //maxPrice2 = ChartData.Max(m => m.T_CloseAvg); //minPrice2 = ChartData.Min(m => m.T_CloseAvg); //if (maxPrice < maxPrice2) maxPrice = maxPrice2; //if (minPrice > minPrice2) minPrice = minPrice2; //maxPrice2 = ChartData.Max(m => m.T_QuantumAvg); //minPrice2 = ChartData.Min(m => m.T_QuantumAvg); //if (maxPrice < maxPrice2) maxPrice = maxPrice2; //if (minPrice > minPrice2) minPrice = minPrice2; //maxPrice = maxPrice + SpaceMaxMin; //minPrice = minPrice - SpaceMaxMin; //chart.ChartAreas[0].AxisY2.Maximum = maxPrice; //chart.ChartAreas[0].AxisY2.Minimum = minPrice; //chart.ChartAreas[0].AxisY.Maximum = 10000; //chart.ChartAreas[0].AxisY.Minimum = 0; SetTrackBar(); SetScrollBar(); DisplayView(); IsLoaded = true; base.View(); }
public override void View() { pnlScroll.Visible = IsAutoScrollX; if (ChartData == null) { return; } if (ChartDataSub == null) { return; } int bDistance = -1; for (int i = 0; i < ChartData.Count; i++) { var item = ChartData[i]; int idx = chart.Series[0].Points.AddXY(item.DTime, item.HighPrice, item.LowPrice, item.OpenPrice, item.ClosePrice); var itemAvg = ChartDataSub[i]; chart.Series[1].Points.AddXY(item.DTime, item.T_QuantumHighAvg + itemAvg.HeadLength + itemAvg.LegLength); chart.Series[2].Points.AddXY(item.DTime, item.T_QuantumLowAvg - itemAvg.HeadLength - itemAvg.LegLength); chart.Series[3].Points.AddXY(item.DTime, ((item.T_QuantumHighAvg + itemAvg.HeadLength + itemAvg.LegLength) + (item.T_QuantumLowAvg - itemAvg.HeadLength - itemAvg.LegLength)) / 2.0 ); int d = PriceTick.GetTickDiff(ItemCode, itemAvg.MassPrice, itemAvg.TotalCenterPrice); chart.Series[4].Points.AddXY(item.DTime, d); if (bDistance != -1) { if (d > bDistance) { chart.Series[4].Points[idx].Color = Color.DarkRed; } else { chart.Series[4].Points[idx].Color = Color.DarkBlue; } } if (d == 0) { if (itemAvg.T_HighAvg < itemAvg.LowPrice || itemAvg.T_LowAvg > item.HighPrice) { chart.Series[4].Points[idx].Label = "↑"; } } bDistance = d; { var dataPoint = chart.Series[0].Points[idx]; if (item.PlusMinusType == PlusMinusTypeEnum.양 && item.YinAndYang == PlusMinusTypeEnum.양) { SetDataPointColor(dataPoint, Color.Red, Color.Red, Color.Red, 2); } else if (item.PlusMinusType == PlusMinusTypeEnum.음 && item.YinAndYang == PlusMinusTypeEnum.양) { SetDataPointColor(dataPoint, Color.Blue, Color.Blue, Color.Blue, 2); } else if (item.PlusMinusType == PlusMinusTypeEnum.양) { SetDataPointColor(dataPoint, Color.Red, Color.Red, Color.White, 2); } else if (item.PlusMinusType == PlusMinusTypeEnum.음) { SetDataPointColor(dataPoint, Color.Blue, Color.Blue, Color.White, 2); } else { SetDataPointColor(dataPoint, Color.Black, Color.Black, Color.White, 2); } } } //maxPrice = ChartData.Max(m => m.HighPrice); //minPrice = ChartData.Min(m => m.LowPrice); //double maxPrice2 = ChartData.Max(m => m.T_QuantumHighAvg); //double minPrice2 = ChartData.Min(m => m.T_QuantumLowAvg); //if (maxPrice < maxPrice2) maxPrice = maxPrice2; //if (minPrice > minPrice2) minPrice = minPrice2; //maxPrice2 = ChartData.Max(m => m.T_CloseAvg); //minPrice2 = ChartData.Min(m => m.T_CloseAvg); //if (maxPrice < maxPrice2) maxPrice = maxPrice2; //if (minPrice > minPrice2) minPrice = minPrice2; //maxPrice2 = ChartData.Max(m => m.T_QuantumAvg); //minPrice2 = ChartData.Min(m => m.T_QuantumAvg); //if (maxPrice < maxPrice2) maxPrice = maxPrice2; //if (minPrice > minPrice2) minPrice = minPrice2; //maxPrice = maxPrice + SpaceMaxMin; //minPrice = minPrice - SpaceMaxMin; //chart.ChartAreas[0].AxisY2.Maximum = maxPrice; //chart.ChartAreas[0].AxisY2.Minimum = minPrice; //chart.ChartAreas[0].AxisY.Maximum = 10000; //chart.ChartAreas[0].AxisY.Minimum = 0; SetTrackBar(); SetScrollBar(); DisplayView(); IsLoaded = true; base.View(); }
/// <summary> /// /// </summary> /// <returns></returns> public static string Calculator(string itemCode, string strategyType, string position, double buyPrice, double currrentPrice, double highPrice, double lowPrice) { string losscutPrice = "0"; int losscutTick = 0; try { int roundNum = ItemCodeUtil.GetItemCodeRoundNum(itemCode); //매도 if (position == "1") { //손실 if (buyPrice < currrentPrice) { if (strategyType == "1") { losscutTick = Config.LosscutConfig.LOSS_LOW_LIMIT_TICKS; } else if (strategyType == "2") { losscutTick = Config.LosscutConfig.LOSS_MIDDLE_LIMIT_TICKS; } else if (strategyType == "3") { losscutTick = Config.LosscutConfig.LOSS_HIGH_LIMIT_TICKS; } losscutPrice = Math.Round(PriceTick.GetUpPriceOfTick(itemCode, buyPrice, losscutTick), roundNum).ToString(); } //수익 else { if (strategyType == "1") { losscutTick = Config.LosscutConfig.REVENUE_LOW_LIMIT_TICKS; } else if (strategyType == "2") { losscutTick = Config.LosscutConfig.REVENUE_MIDDLE_LIMIT_TICKS; } else if (strategyType == "3") { losscutTick = Config.LosscutConfig.REVENUE_HIGH_LIMIT_TICKS; } losscutPrice = Math.Round(PriceTick.GetUpPriceOfTick(itemCode, lowPrice, losscutTick), roundNum).ToString(); } } //매수 else if (position == "2") { //손실 if (buyPrice > currrentPrice) { if (strategyType == "1") { losscutTick = Config.LosscutConfig.LOSS_LOW_LIMIT_TICKS; } else if (strategyType == "2") { losscutTick = Config.LosscutConfig.LOSS_MIDDLE_LIMIT_TICKS; } else if (strategyType == "3") { losscutTick = Config.LosscutConfig.LOSS_HIGH_LIMIT_TICKS; } losscutPrice = Math.Round(PriceTick.GetDownPriceOfTick(itemCode, buyPrice, losscutTick), roundNum).ToString(); } //수익 else { if (strategyType == "1") { losscutTick = Config.LosscutConfig.REVENUE_LOW_LIMIT_TICKS; } else if (strategyType == "2") { losscutTick = Config.LosscutConfig.REVENUE_MIDDLE_LIMIT_TICKS; } else if (strategyType == "3") { losscutTick = Config.LosscutConfig.REVENUE_HIGH_LIMIT_TICKS; } losscutPrice = Math.Round(PriceTick.GetDownPriceOfTick(itemCode, highPrice, losscutTick), roundNum).ToString(); } } } catch (Exception) { } return(losscutPrice); }