internal void FromDataBar(DataBar db) { this.SetAllNull(); using (OpenXmlReader oxr = OpenXmlReader.Create(db)) { int i = 0; while (oxr.Read()) { if (oxr.ElementType == typeof(ConditionalFormatValueObject)) { if (i == 0) { this.Cfvo1.FromConditionalFormatValueObject((ConditionalFormatValueObject)oxr.LoadCurrentElement()); ++i; } else if (i == 1) { this.Cfvo2.FromConditionalFormatValueObject((ConditionalFormatValueObject)oxr.LoadCurrentElement()); ++i; } } else if (oxr.ElementType == typeof(Color)) { this.Color.FromSpreadsheetColor((Color)oxr.LoadCurrentElement()); } } } if (db.MinLength != null) this.MinLength = db.MinLength.Value; if (db.MaxLength != null) this.MaxLength = db.MaxLength.Value; if (db.ShowValue != null) this.ShowValue = db.ShowValue.Value; }
/// <summary> /// Special constructor allows to build a quote from data bar. /// </summary> /// <param name="bar"></param> public Quote(DataBar bar, decimal spread) { _ask = bar.Close; _bid = bar.Close - spread; _volume = bar.Volume; _time = bar.DateTime; _low = null; _high = null; _open = null; }
internal DataBar ToDataBar() { DataBar db = new DataBar(); if (this.MinLength != 10) db.MinLength = this.MinLength; if (this.MaxLength != 90) db.MaxLength = this.MaxLength; if (!this.ShowValue) db.ShowValue = this.ShowValue; db.Append(this.Cfvo1.ToConditionalFormatValueObject()); db.Append(this.Cfvo2.ToConditionalFormatValueObject()); db.Append(this.Color.ToSpreadsheetColor()); return db; }
public Drawing(List <int> Numbers, Rectangle CanvasRc, Graphics g) { gfx = g; CanvasRectangle = new Rectangle(CanvasRc.X, CanvasRc.Y, CanvasRc.Width, CanvasRc.Height); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; int Xpos = 20; for (int index = 0; index < Numbers.Count; index++) { Rectangle rc = new Rectangle(Xpos, (CanvasRectangle.Height / 2) - Numbers[index], 40, Numbers[index] + 120); DataBar bar = new DataBar(); bar.val = Numbers[index]; bar.coordinates = rc; Bars[index] = bar; Xpos += 45; } }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); var dataBar = new DataBar { ShowValue = !cf.ShowBarOnly }; var conditionalFormatValueObject1 = GetConditionalFormatValueObjectByIndex(cf, 1, ConditionalFormatValueObjectValues.Min); var conditionalFormatValueObject2 = GetConditionalFormatValueObjectByIndex(cf, 2, ConditionalFormatValueObjectValues.Max); var color = new Color(); switch (cf.Colors[1].ColorType) { case XLColorType.Color: color.Rgb = cf.Colors[1].Color.ToHex(); break; case XLColorType.Theme: color.Theme = System.Convert.ToUInt32(cf.Colors[1].ThemeColor); break; case XLColorType.Indexed: color.Indexed = System.Convert.ToUInt32(cf.Colors[1].Indexed); break; } dataBar.Append(conditionalFormatValueObject1); dataBar.Append(conditionalFormatValueObject2); dataBar.Append(color); conditionalFormattingRule.Append(dataBar); var conditionalFormattingRuleExtensionList = new ConditionalFormattingRuleExtensionList(); conditionalFormattingRuleExtensionList.Append(BuildRuleExtension(cf)); conditionalFormattingRule.Append(conditionalFormattingRuleExtensionList); return(conditionalFormattingRule); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = new ConditionalFormattingRule { Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; var dataBar = new DataBar {ShowValue = !cf.ShowBarOnly}; var conditionalFormatValueObject1 = new ConditionalFormatValueObject { Type = cf.ContentTypes[1].ToOpenXml()}; if (cf.Values.Count >= 1) conditionalFormatValueObject1.Val = cf.Values[1].Value; var conditionalFormatValueObject2 = new ConditionalFormatValueObject { Type = cf.ContentTypes[2].ToOpenXml()}; if (cf.Values.Count >= 2) conditionalFormatValueObject2.Val = cf.Values[2].Value; var color = new Color { Rgb = cf.Colors[1].Color.ToHex() }; dataBar.Append(conditionalFormatValueObject1); dataBar.Append(conditionalFormatValueObject2); dataBar.Append(color); conditionalFormattingRule.Append(dataBar); return conditionalFormattingRule; }
public static void Run() { //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Output directory string outputDir = RunExamples.Get_OutputDirectory(); // Create workbook object from source excel file Workbook workbook = new Workbook(sourceDir + "sampleGenerateDatabarImage.xlsx"); // Access first worksheet Worksheet worksheet = workbook.Worksheets[0]; // Access the cell which contains conditional formatting databar Cell cell = worksheet.Cells["C1"]; // Create and get the conditional formatting of the worksheet int idx = worksheet.ConditionalFormattings.Add(); FormatConditionCollection fcc = worksheet.ConditionalFormattings[idx]; fcc.AddCondition(FormatConditionType.DataBar); fcc.AddArea(CellArea.CreateCellArea("C1", "C4")); // Access the conditional formatting databar DataBar dbar = fcc[0].DataBar; // Create image or print options ImageOrPrintOptions opts = new ImageOrPrintOptions(); opts.ImageFormat = ImageFormat.Png; // Get the image bytes of the databar byte[] imgBytes = dbar.ToImage(cell, opts); // Write image bytes on the disk File.WriteAllBytes(outputDir + "outputGenerateDatabarImage.png", imgBytes); Console.WriteLine("GenerateDatabarImage executed successfully."); }
public ISecurity Execute(IList <double> openList, IList <double> closeList, IList <double> highList, IList <double> lowList, IList <double> volumeList) { if (openList == null) { throw new ArgumentNullException(nameof(openList)); } if (closeList == null) { throw new ArgumentNullException(nameof(closeList)); } if (highList == null) { throw new ArgumentNullException(nameof(highList)); } if (lowList == null) { throw new ArgumentNullException(nameof(lowList)); } if (volumeList == null) { throw new ArgumentNullException(nameof(volumeList)); } var security = Context.Runtime.Securities.First(); var securityBars = security.Bars; var count = Math.Min(openList.Count, Math.Min(closeList.Count, Math.Min(highList.Count, Math.Min(lowList.Count, Math.Min(volumeList.Count, securityBars.Count))))); var bars = new IDataBar[count]; for (var i = 0; i < count; i++) { bars[i] = new DataBar(securityBars[i].Date, openList[i], highList[i], lowList[i], closeList[i], volumeList[i]); } return(new Security(bars, VariableName, security)); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = new ConditionalFormattingRule { Type = cf.ConditionalFormatType.ToOpenXml(), Priority = priority }; var dataBar = new DataBar { ShowValue = !cf.ShowBarOnly }; var conditionalFormatValueObject1 = new ConditionalFormatValueObject { Type = cf.ContentTypes[1].ToOpenXml() }; if (cf.Values.Count >= 1) { conditionalFormatValueObject1.Val = cf.Values[1].Value; } var conditionalFormatValueObject2 = new ConditionalFormatValueObject { Type = cf.ContentTypes[2].ToOpenXml() }; if (cf.Values.Count >= 2) { conditionalFormatValueObject2.Val = cf.Values[2].Value; } var color = new Color { Rgb = cf.Colors[1].Color.ToHex() }; dataBar.Append(conditionalFormatValueObject1); dataBar.Append(conditionalFormatValueObject2); dataBar.Append(color); conditionalFormattingRule.Append(dataBar); return(conditionalFormattingRule); }
internal SLConditionalFormattingRule2010 Clone() { var cfr = new SLConditionalFormattingRule2010(); cfr.Formulas = new List <Formula>(); for (var i = 0; i < Formulas.Count; ++i) { cfr.Formulas.Add((Formula)Formulas[i].CloneNode(true)); } cfr.HasColorScale = HasColorScale; cfr.ColorScale = ColorScale.Clone(); cfr.HasDataBar = HasDataBar; cfr.DataBar = DataBar.Clone(); cfr.HasIconSet = HasIconSet; cfr.IconSet = IconSet.Clone(); cfr.HasDifferentialType = HasDifferentialType; cfr.DifferentialType = DifferentialType.Clone(); cfr.Type = Type; cfr.Priority = Priority; cfr.StopIfTrue = StopIfTrue; cfr.AboveAverage = AboveAverage; cfr.Percent = Percent; cfr.Bottom = Bottom; cfr.HasOperator = HasOperator; cfr.Operator = Operator; cfr.Text = Text; cfr.HasTimePeriod = HasTimePeriod; cfr.TimePeriod = TimePeriod; cfr.Rank = Rank; cfr.StandardDeviation = StandardDeviation; cfr.EqualAverage = EqualAverage; cfr.ActivePresent = ActivePresent; cfr.Id = Id; return(cfr); }
public void WriteConditionalFormattingDataBar(DataBar dataBar, out CT_DataBar cfDataBar) { if (dataBar == null) { cfDataBar = null; return; } List <CT_Cfvo> ct_cfvo_list = new List <CT_Cfvo>(); foreach (var ct_cfvo in dataBar.CFVOList) { ct_cfvo_list.Add(new CT_Cfvo { val = ct_cfvo.Value, type = (ST_CfvoType)ct_cfvo.Type //1-1 }); } cfDataBar = new CT_DataBar { cfvo = ct_cfvo_list.ToArray(), color = ConvertColor(dataBar.Color) }; }
public static void Run() { // ExStart:GenerateDatabarImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create workbook object from source excel file Workbook workbook = new Workbook(dataDir + "source.xlsx"); // Access first worksheet Worksheet worksheet = workbook.Worksheets[0]; // Access the cell which contains conditional formatting databar Cell cell = worksheet.Cells["C1"]; // Create and get the conditional formatting of the worksheet int idx = worksheet.ConditionalFormattings.Add(); FormatConditionCollection fcc = worksheet.ConditionalFormattings[idx]; fcc.AddCondition(FormatConditionType.DataBar); // Access the conditional formatting databar DataBar dbar = fcc[0].DataBar; // Create image or print options ImageOrPrintOptions opts = new ImageOrPrintOptions(); opts.ImageFormat = ImageFormat.Png; // Get the image bytes of the databar byte[] imgBytes = dbar.ToImage(cell, opts); // Write image bytes on the disk File.WriteAllBytes(dataDir + "databar_out.png", imgBytes); // ExEnd:GenerateDatabarImage }
public List <DataBar> GetHistory(string forexPair, TimeSpan period, DateTime lowerBound, DateTime upperBound) { bool keepIterating = true; FXCore.IMarketRateEnumAut japaneseCandlestick; List <DataBar> candlestickHistoryList = new List <DataBar>(); candlestickHistoryList = new List <DataBar>(); lock (this) { while (keepIterating) { japaneseCandlestick = (FXCore.IMarketRateEnumAut)_manager.Desk.GetPriceHistory(forexPair, GetPeriodId(period), lowerBound, upperBound, -1, false, true); foreach (FXCore.IMarketRateAut marketRate in japaneseCandlestick) { DataBar dataBar = new DataBar(marketRate.StartDate, new decimal(marketRate.AskOpen), new decimal(marketRate.AskHigh), new decimal(marketRate.AskLow), new decimal(marketRate.AskClose), 0); candlestickHistoryList.Add(dataBar); lowerBound = marketRate.StartDate; } Thread.Sleep(100); int i = japaneseCandlestick.Size; keepIterating = i > 1 && upperBound.CompareTo(lowerBound) >= 0; lowerBound.AddTicks(1); } } return(candlestickHistoryList); }
void DrawOrders(GraphicsWrapper g, int index, PointF drawingPoint, float itemWidth, float itemMargin, List<Order> openingOrders, List<Order> closingOrders, DataBar orderBarData, float lastBarX) { // Width is same as items in real coordinates. float actualImageHeight = _imageDown.Height / Math.Abs(g.DrawingSpaceTransformClone.Elements[3]); float yToXScaling = Math.Abs(g.DrawingSpaceTransformClone.Elements[0] / g.DrawingSpaceTransformClone.Elements[3]); PointF updatedImageDrawingPoint = drawingPoint; foreach (Order order in openingOrders) { DrawOrder(g, ref updatedImageDrawingPoint, order, itemWidth, itemMargin, yToXScaling, orderBarData, lastBarX, true); } foreach (Order order in closingOrders) { DrawOrder(g, ref updatedImageDrawingPoint, order, itemWidth, itemMargin, yToXScaling, orderBarData, lastBarX, false); } }
void DrawOrder(GraphicsWrapper g, ref PointF updatedImageDrawingPoint, Order order, float itemWidth, float itemMargin, float yToXScaling, DataBar orderBarData, float lastBarX, bool drawOpening) { Image image = _imageUp; Brush brush = Brushes.Green; Pen dashedPen = _buyDashedPen; Pen pen = Pens.GreenYellow; if (order.IsBuy == false) { image = _imageDown; brush = Brushes.Red; pen = Pens.Red; dashedPen = _sellDashedPen; } if (drawOpening == false) { image = _imageCross; } if (order.OpenPrice.HasValue == false) { SystemMonitor.OperationError("Order with no open price assigned for drawing.", TracerItem.PriorityEnum.Low); return; } float price = (float)order.OpenPrice.Value; if (drawOpening == false) { if (order.ClosePrice.HasValue == false) { return; } price = (float)order.ClosePrice.Value; } if (drawOpening && _showPendingOrdersTracing && (order is ActiveOrder && order.State == OrderStateEnum.Executed) && _dataProvider.Quotes.Bid.HasValue && _dataProvider.Quotes.Ask.HasValue) {// Open orders tracking line. PointF point1 = new PointF(updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + price); float sellPrice = (float)_dataProvider.Quotes.Bid; if (order.IsBuy == false) { sellPrice = (float)_dataProvider.Quotes.Ask; } PointF point2 = new PointF(lastBarX - itemWidth / 2f, updatedImageDrawingPoint.Y + sellPrice); g.DrawLine(dashedPen, point1, point2); } //if (drawOpening && _showClosedOrdersTracing && order.IsOpen == false) //{// Closed order tracking. // Close order tracing is implemented in main draw function. //} if (_showOrderSpot) { PointF basePoint = new PointF(updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + price); float height = (yToXScaling * itemWidth); if (order.IsBuy == false) { height = -height; } if (drawOpening) { g.FillPolygon(brush, new PointF[] { basePoint, new PointF(basePoint.X + itemWidth, basePoint.Y), new PointF(basePoint.X + (itemWidth / 2f), basePoint.Y + height) }); g.DrawPolygon(Pens.White, new PointF[] { basePoint, new PointF(basePoint.X + itemWidth, basePoint.Y), new PointF(basePoint.X + (itemWidth / 2f), basePoint.Y + height) }); float drawToLeft = (float)(1.5 * itemWidth); float drawToRight = (float)(2.5 * itemWidth); // Take profit level. if (order.TakeProfit.HasValue && order.TakeProfit.Value != 0) { g.DrawLine(pen, updatedImageDrawingPoint.X - drawToLeft, updatedImageDrawingPoint.Y + (float)order.TakeProfit, updatedImageDrawingPoint.X + drawToRight, updatedImageDrawingPoint.Y + (float)order.TakeProfit); g.DrawLine(pen, updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.TakeProfit, updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.TakeProfit - height); } // Stop loss level. if (order.StopLoss.HasValue && order.StopLoss.Value != 0) { g.DrawLine(pen, updatedImageDrawingPoint.X - drawToLeft, updatedImageDrawingPoint.Y + (float)order.StopLoss, updatedImageDrawingPoint.X + drawToRight, updatedImageDrawingPoint.Y + (float)order.StopLoss); g.DrawLine(pen, updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.StopLoss, updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.StopLoss + height); } } else { g.DrawRectangle(Pens.White, basePoint.X, basePoint.Y, itemWidth, yToXScaling * itemWidth); } } float imageHeight = 2 * (yToXScaling * itemWidth); if (_showOrderArrow) { float x = updatedImageDrawingPoint.X - (itemWidth / 2f); float y = updatedImageDrawingPoint.Y + (float)orderBarData.Low - (yToXScaling * itemWidth); float width = 2 * itemWidth; float height = -imageHeight; GraphicsWrapper.NormalizedRectangle(ref x, ref y, ref width, ref height); RectangleF rectange = new RectangleF(x, y, width, height); // Draw up image. g.DrawImage(image, rectange.X, rectange.Y, rectange.Width, rectange.Height); if (order == _selectedOrder) {// This is selected order. g.DrawRectangle(Pens.White, rectange); } _ordersArrows[order] = rectange; updatedImageDrawingPoint.Y -= 1.2f * imageHeight; } }
public double[] GetValuesAsDouble(DataBar.DataValueEnum valueEnum) { return GetValuesAsDouble(valueEnum, 0, int.MaxValue); }
public double[] GetValuesAsDouble(DataBar.DataValueEnum valueEnum, int startingIndex, int indexCount) { double[] result; lock (this) { int count = indexCount; if (count == 0) { count = _dataBars.Count - startingIndex; GeneralHelper.Verify(count >= 0, "Invalid starting index."); } result = new double[Math.Min(count, _dataBars.Count)]; for (int i = startingIndex; i < startingIndex + count && i < _dataBars.Count; i++) { result[i - startingIndex] = (double)_dataBars[i].GetValue(valueEnum); } } return result; }
/// <summary> /// Enter locked. /// </summary> void DrawBar(GraphicsWrapper g, ref PointF startingPoint, DataBar barData, float itemWidth, float itemMargin, int itemUnitification) { float xMiddle = startingPoint.X + itemWidth / 2; float xHalfWidth = itemWidth / 2; Pen pen = _risingBarPen; if (barData.IsRising == false) { pen = _fallingBarPen; } if (pen == null) { return; } float yDisplacement = startingPoint.Y; g.DrawLine(pen, xMiddle, yDisplacement + (float)barData.Low, xMiddle, yDisplacement + (float)barData.High); g.DrawLine(pen, xMiddle, yDisplacement + (float)barData.Open, xMiddle - xHalfWidth, yDisplacement + (float)barData.Open); g.DrawLine(pen, xMiddle, yDisplacement + (float)barData.Close, xMiddle + xHalfWidth, yDisplacement + (float)barData.Close); }
/// <summary> /// Helper, initialize a single TaLib indicator. /// </summary> Indicator InitializeTaLibIndicator(MethodInfo methodInfo, string indicatorName, bool? isTradeable, bool? isScaledToQuotes, float? rangeMinimum, float? rangeMaximum, DataBar.DataValueEnum? inRealSource, DataBar.DataValueEnum? inReal1Source, params object[] inputParameters) { lock (this) { MethodInfo lookBackCountMethodInfo = null; foreach (MethodInfo info in typeof(TicTacTec.TA.Library.Core).GetMethods()) { if (info.Name == methodInfo.Name + "Lookback") { lookBackCountMethodInfo = info; break; } } if (lookBackCountMethodInfo == null) { SystemMonitor.Error("Failed to find indicator [" + methodInfo.Name + "] look back method."); return null; } GenericTALibIndicator indicator = GenericTALibIndicator.CreateInstance(methodInfo, lookBackCountMethodInfo, indicatorName, isTradeable, isScaledToQuotes); if (indicator == null) { SystemMonitor.Error("Creating indicator [" + indicator.Name + "] failed."); return null; } string[] names = new string[inputParameters.Length]; for (int i = 0; i < inputParameters.Length; i++) { names[i] = "Parameter." + inputParameters[i].GetType().Name + "." + i.ToString(); } SystemMonitor.CheckThrow(indicator.SetInitialParameters(inputParameters, names)); _indicatorsGroups[IndicatorGroup.TaLib].Add(indicator.Name, indicator); indicator.RealInputArraySource = inRealSource; indicator.Real1InputArraySource = inReal1Source; indicator.RangeMinimum = rangeMinimum; indicator.RangeMaximum = rangeMaximum; return indicator; } }
internal ConditionalFormattingRule ToConditionalFormattingRule() { var cfr = new ConditionalFormattingRule(); cfr.Type = Type; if (FormatId != null) { cfr.FormatId = FormatId.Value; } cfr.Priority = Priority; if (StopIfTrue) { cfr.StopIfTrue = StopIfTrue; } if (!AboveAverage) { cfr.AboveAverage = AboveAverage; } if (Percent) { cfr.Percent = Percent; } if (Bottom) { cfr.Bottom = Bottom; } if (HasOperator) { cfr.Operator = Operator; } if ((Text != null) && (Text.Length > 0)) { cfr.Text = Text; } if (HasTimePeriod) { cfr.TimePeriod = TimePeriod; } if (Rank != null) { cfr.Rank = Rank.Value; } if (StdDev != null) { cfr.StdDev = StdDev.Value; } if (EqualAverage) { cfr.EqualAverage = EqualAverage; } foreach (var f in Formulas) { cfr.Append((Formula)f.CloneNode(true)); } if (HasColorScale) { cfr.Append(ColorScale.ToColorScale()); } if (HasDataBar) { cfr.Append(DataBar.ToDataBar()); } if (HasIconSet) { cfr.Append(IconSet.ToIconSet()); } if (Extensions.Count > 0) { var extlist = new ConditionalFormattingRuleExtensionList(); foreach (var ext in Extensions) { extlist.Append((ConditionalFormattingRuleExtension)ext.CloneNode(true)); } cfr.Append(extlist); } return(cfr); }
/// <summary> /// Create a dataDelivery bar based on quote. /// </summary> /// <param name="quote"></param> /// <returns></returns> public DataBar UpdateCurrentBar(DataBar currentBar, Quote quote) { if (quote.Bid.HasValue == false || quote.Ask.HasValue == false) { return currentBar; } currentBar.Low = Math.Min(quote.Bid.Value, currentBar.Low); currentBar.High = Math.Max(quote.Bid.Value, currentBar.High); currentBar.Close = quote.Bid.Value; if (quote.Volume.HasValue) { currentBar.Volume = quote.Volume.Value; } return currentBar; }
public DataBar? BarFromQuote(DataBar? previousBar, DateTime time, Quote quote) { if ((quote.IsFullySet == false && previousBar.HasValue == false) || (quote.Ask.HasValue == false || quote.Bid.HasValue == false)) {// We need at least previous bar if quote is not fully set. return null; } decimal open = quote.Open.HasValue ? quote.Open.Value : previousBar.Value.Close; decimal close = quote.Bid.Value; DataBar result = new DataBar(time, open, Math.Max(open, close), Math.Min(open, close), close, 0); return result; }
/// <summary> /// /// </summary> public List<DataBar> GetHistory(string forexPair, string period, DateTime lowerBound, DateTime upperBound) { bool keepIterating = true; List<DataBar> candlestickHistoryList = new List<DataBar>(); GeneralHelper.DefaultDelegate delegateInstance = delegate() { TradeDeskAut desk = _desk; if (desk == null) { return; } FXCore.IMarketRateEnumAut japaneseCandlestick; while (keepIterating) { japaneseCandlestick = (FXCore.IMarketRateEnumAut)desk.GetPriceHistoryUTC(forexPair, period, lowerBound, upperBound, -1, false, true); foreach (FXCore.IMarketRateAut marketRate in japaneseCandlestick) { DataBar dataBar = new DataBar(marketRate.StartDate, new decimal(marketRate.AskOpen), new decimal(marketRate.AskHigh), new decimal(marketRate.AskLow), new decimal(marketRate.AskClose), 0); candlestickHistoryList.Add(dataBar); lowerBound = marketRate.StartDate; } Thread.Sleep(100); int i = japaneseCandlestick.Size; keepIterating = i > 1 && upperBound.CompareTo(lowerBound) >= 0; lowerBound.AddTicks(1); } }; BackgroundMessageLoopOperator messageLoopOperator = _messageLoopOperator; if (messageLoopOperator != null) { messageLoopOperator.Invoke(delegateInstance, TimeSpan.FromSeconds(60)); } return candlestickHistoryList; }
internal X14.ConditionalFormattingRule ToConditionalFormattingRule() { var cfr = new X14.ConditionalFormattingRule(); if (Type != null) { cfr.Type = Type.Value; } if (Priority != null) { cfr.Priority = Priority.Value; } if (StopIfTrue) { cfr.StopIfTrue = StopIfTrue; } if (!AboveAverage) { cfr.AboveAverage = AboveAverage; } if (Percent) { cfr.Percent = Percent; } if (Bottom) { cfr.Bottom = Bottom; } if (HasOperator) { cfr.Operator = Operator; } if ((Text != null) && (Text.Length > 0)) { cfr.Text = Text; } if (HasTimePeriod) { cfr.TimePeriod = TimePeriod; } if (Rank != null) { cfr.Rank = Rank.Value; } if (StandardDeviation != null) { cfr.StandardDeviation = StandardDeviation.Value; } if (EqualAverage) { cfr.EqualAverage = EqualAverage; } if (ActivePresent) { cfr.ActivePresent = ActivePresent; } if (Id != null) { cfr.Id = Id; } foreach (var f in Formulas) { cfr.Append((Formula)f.CloneNode(true)); } if (HasColorScale) { cfr.Append(ColorScale.ToColorScale()); } if (HasDataBar) { cfr.Append(DataBar.ToDataBar(Priority != null)); } if (HasIconSet) { cfr.Append(IconSet.ToIconSet()); } if (HasDifferentialType) { cfr.Append(DifferentialType.ToDifferentialType()); } return(cfr); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); var dataBar = new DataBar { ShowValue = !cf.ShowBarOnly }; var conditionalFormatValueObject1 = new ConditionalFormatValueObject { Type = cf.ContentTypes[1].ToOpenXml() }; if (cf.Values.Any() && cf.Values[1]?.Value != null) { conditionalFormatValueObject1.Val = cf.Values[1].Value; } var conditionalFormatValueObject2 = new ConditionalFormatValueObject { Type = cf.ContentTypes[2].ToOpenXml() }; if (cf.Values.Count >= 2 && cf.Values[2]?.Value != null) { conditionalFormatValueObject2.Val = cf.Values[2].Value; } var color = new Color(); switch (cf.Colors[1].ColorType) { case XLColorType.Color: color.Rgb = cf.Colors[1].Color.ToHex(); break; case XLColorType.Theme: color.Theme = System.Convert.ToUInt32(cf.Colors[1].ThemeColor); break; case XLColorType.Indexed: color.Indexed = System.Convert.ToUInt32(cf.Colors[1].Indexed); break; } dataBar.Append(conditionalFormatValueObject1); dataBar.Append(conditionalFormatValueObject2); dataBar.Append(color); conditionalFormattingRule.Append(dataBar); if (cf.Colors.Count > 1) { ConditionalFormattingRuleExtensionList conditionalFormattingRuleExtensionList = new ConditionalFormattingRuleExtensionList(); ConditionalFormattingRuleExtension conditionalFormattingRuleExtension = new ConditionalFormattingRuleExtension { Uri = "{B025F937-C7B1-47D3-B67F-A62EFF666E3E}" }; conditionalFormattingRuleExtension.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); DocumentFormat.OpenXml.Office2010.Excel.Id id = new DocumentFormat.OpenXml.Office2010.Excel.Id { Text = (cf as XLConditionalFormat).Id.WrapInBraces() }; conditionalFormattingRuleExtension.Append(id); conditionalFormattingRuleExtensionList.Append(conditionalFormattingRuleExtension); conditionalFormattingRule.Append(conditionalFormattingRuleExtensionList); } return(conditionalFormattingRule); }
public decimal[] GetValues(DataBar.DataValueEnum valueEnum) { return GetValues(valueEnum, 0, int.MaxValue); }
internal DataBar ToDataBar() { DataBar db = new DataBar(); if (this.MinLength != 10) { db.MinLength = this.MinLength; } if (this.MaxLength != 90) { db.MaxLength = this.MaxLength; } if (!this.ShowValue) { db.ShowValue = this.ShowValue; } SLConditionalFormatValueObject cfvo; cfvo = new SLConditionalFormatValueObject(); cfvo.Type = ConditionalFormatValueObjectValues.Min; switch (this.MinimumType) { case SLConditionalFormatAutoMinMaxValues.Automatic: cfvo.Type = ConditionalFormatValueObjectValues.Min; cfvo.Val = string.Empty; break; case SLConditionalFormatAutoMinMaxValues.Formula: cfvo.Type = ConditionalFormatValueObjectValues.Formula; cfvo.Val = this.MinimumValue; break; case SLConditionalFormatAutoMinMaxValues.Number: cfvo.Type = ConditionalFormatValueObjectValues.Number; cfvo.Val = this.MinimumValue; break; case SLConditionalFormatAutoMinMaxValues.Percent: cfvo.Type = ConditionalFormatValueObjectValues.Percent; cfvo.Val = this.MinimumValue; break; case SLConditionalFormatAutoMinMaxValues.Percentile: cfvo.Type = ConditionalFormatValueObjectValues.Percentile; cfvo.Val = this.MinimumValue; break; case SLConditionalFormatAutoMinMaxValues.Value: cfvo.Type = ConditionalFormatValueObjectValues.Min; cfvo.Val = string.Empty; break; } db.Append(cfvo.ToConditionalFormatValueObject()); cfvo = new SLConditionalFormatValueObject(); cfvo.Type = ConditionalFormatValueObjectValues.Max; switch (this.MaximumType) { case SLConditionalFormatAutoMinMaxValues.Automatic: cfvo.Type = ConditionalFormatValueObjectValues.Max; cfvo.Val = string.Empty; break; case SLConditionalFormatAutoMinMaxValues.Formula: cfvo.Type = ConditionalFormatValueObjectValues.Formula; cfvo.Val = this.MaximumValue; break; case SLConditionalFormatAutoMinMaxValues.Number: cfvo.Type = ConditionalFormatValueObjectValues.Number; cfvo.Val = this.MaximumValue; break; case SLConditionalFormatAutoMinMaxValues.Percent: cfvo.Type = ConditionalFormatValueObjectValues.Percent; cfvo.Val = this.MaximumValue; break; case SLConditionalFormatAutoMinMaxValues.Percentile: cfvo.Type = ConditionalFormatValueObjectValues.Percentile; cfvo.Val = this.MaximumValue; break; case SLConditionalFormatAutoMinMaxValues.Value: cfvo.Type = ConditionalFormatValueObjectValues.Max; cfvo.Val = string.Empty; break; } db.Append(cfvo.ToConditionalFormatValueObject()); db.Append(this.Color.ToSpreadsheetColor()); return(db); }
public ConditionalFormattingRule Convert(IXLConditionalFormat cf, XLWorkbook.SaveContext context) { ConditionalFormattingRule conditionalFormattingRule = new ConditionalFormattingRule() { Type = DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatValues.DataBar, Id = (cf as XLConditionalFormat).Id.WrapInBraces() }; DataBar dataBar = new DataBar() { MinLength = 0, MaxLength = 100, Gradient = true, ShowValue = !cf.ShowBarOnly }; var cfMinType = cf.ContentTypes.TryGetValue(1, out var contentType1) ? Convert(contentType1.ToOpenXml()) : ConditionalFormattingValueObjectTypeValues.AutoMin; var cfMin = new ConditionalFormattingValueObject { Type = cfMinType }; if (cf.Values.Any() && cf.Values[1]?.Value != null) { cfMin.Type = ConditionalFormattingValueObjectTypeValues.Numeric; cfMin.Append(new Formula() { Text = cf.Values[1].Value }); } var cfMaxType = cf.ContentTypes.TryGetValue(2, out var contentType2) ? Convert(contentType2.ToOpenXml()) : ConditionalFormattingValueObjectTypeValues.AutoMax; var cfMax = new ConditionalFormattingValueObject { Type = cfMaxType }; if (cf.Values.Count >= 2 && cf.Values[2]?.Value != null) { cfMax.Type = ConditionalFormattingValueObjectTypeValues.Numeric; cfMax.Append(new Formula() { Text = cf.Values[2].Value }); } var barAxisColor = new BarAxisColor { Rgb = XLColor.Black.Color.ToHex() }; var negativeFillColor = new NegativeFillColor { Rgb = cf.Colors[1].Color.ToHex() }; if (cf.Colors.Count == 2) { negativeFillColor = new NegativeFillColor { Rgb = cf.Colors[2].Color.ToHex() }; } dataBar.Append(cfMin); dataBar.Append(cfMax); dataBar.Append(negativeFillColor); dataBar.Append(barAxisColor); conditionalFormattingRule.Append(dataBar); return(conditionalFormattingRule); }
/// <summary> /// Enter locked. /// </summary> void DrawCandleStick(GraphicsWrapper g, ref PointF startingPoint, DataBar barData, float itemWidth, float itemMargin, int itemUnitification) { if (barData.IsRising) { if (_risingBarFill != null) { g.FillRectangle(_risingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight); } if (_risingBarPen != null) { if (itemWidth > 4) { g.DrawRectangle(_risingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight); } else { g.FillRectangle(Brushes.Green, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight); } // Draw a horizontal line for 0 height bars. if (barData.AbsoluteBodyHeight == 0) { g.DrawLine(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, startingPoint.X + itemWidth, startingPoint.Y + (float)barData.Close); } // Lower shadow g.DrawLine(_risingBarPen, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Low, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Open); // Upper shadow g.DrawLine(_risingBarPen, startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + (float)barData.High), startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + (float)barData.Close)); } } else { if (_fallingBarFill != null) { g.FillRectangle(_fallingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Close, itemWidth, (float)barData.AbsoluteBodyHeight); } if (_fallingBarPen != null) { if (itemWidth >= 4) {// Only if an item is clearly visible, show the border, otherwise, hide to improve. overal visibility. // Showing this border adds nice detail on close zooming, but not useful otherwise. g.DrawRectangle(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, itemWidth, (float)barData.AbsoluteBodyHeight); } // Draw a horizontal line for 0 height bars. if (barData.AbsoluteBodyHeight == 0) { g.DrawLine(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, startingPoint.X + itemWidth, startingPoint.Y + (float)barData.Close); } // Lower shadow g.DrawLine(_fallingBarPen, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Low, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Close); // Upper shadow g.DrawLine(_fallingBarPen, startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + (float)barData.High), startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + (float)barData.Open)); } } }
/// <summary> /// Helper, generate a new random data bar. /// </summary> DataBar GenerateNextRandomBar() { DataBar result; if (_history.Count == 0) { decimal startPrice = 0.9m; result = new DataBar() { DateTime = _dateTime, Close = startPrice, Open = startPrice - 0.005m, High = startPrice + 0.005m, Low = startPrice - 0.012m, Volume = 12 }; } else { _dateTime = _dateTime.Add(_period); decimal movement = Math.Round(GeneralHelper.Random(-0.01m, 0.01m), 4); decimal open = LastBar.Close; decimal close = open + movement; decimal high = Math.Max(open, close) + Math.Round(GeneralHelper.Random(0, 0.005m), 4); decimal low = Math.Min(open, close) + Math.Round(GeneralHelper.Random(-0.005m, 0), 4); decimal volume = GeneralHelper.Random(1, 20); result = new DataBar(_dateTime, open, high, low, close, volume); } _history.Add(result); return result; }
public List<DataBar> GetHistory(string forexPair, TimeSpan period, DateTime lowerBound, DateTime upperBound) { bool keepIterating = true; FXCore.IMarketRateEnumAut japaneseCandlestick; List<DataBar> candlestickHistoryList = new List<DataBar>(); candlestickHistoryList = new List<DataBar>(); lock (this) { while (keepIterating) { japaneseCandlestick = (FXCore.IMarketRateEnumAut)_manager.Desk.GetPriceHistory(forexPair, GetPeriodId(period), lowerBound, upperBound, -1, false, true); foreach (FXCore.IMarketRateAut marketRate in japaneseCandlestick) { DataBar dataBar = new DataBar(marketRate.StartDate, new decimal(marketRate.AskOpen), new decimal(marketRate.AskHigh), new decimal(marketRate.AskLow), new decimal(marketRate.AskClose), 0); candlestickHistoryList.Add(dataBar); lowerBound = marketRate.StartDate; } Thread.Sleep(100); int i = japaneseCandlestick.Size; keepIterating = i > 1 && upperBound.CompareTo(lowerBound) >= 0; lowerBound.AddTicks(1); } } return candlestickHistoryList; }