Tables

Modified on Fri, 04 Aug 2023 at 01:56 PM

Below is an example of the indicator, which displays the data in the table form (Cluster Statistic analog)

public class ClusterStatisticSample : Indicator
    {
        public ClusterStatisticSample()
        {
            EnableCustomDrawing = true;
            SubscribeToDrawingEvents(DrawingLayouts.LatestBar);
            Panel = IndicatorDataProvider.NewPanel;
            DenyToChangePanel = true;
            DataSeries[0].IsHidden = true;
        }
 
        protected override void OnCalculate(int bar, decimal value)
        {
 
        }
 
        protected override void OnRender(RenderContext context, DrawingLayouts layout)
        {
            var rowHeight = Container.Region.Height / 3;
            var drawText = ChartInfo.PriceChartContainer.BarsWidth > 50;
            var font = new RenderFont("Roboto", 13);
 
            Rectangle rectangle;
 
            for (int bar = FirstVisibleBarNumber; bar <= LastVisibleBarNumber; bar++)
            {
                var candle = GetCandle(bar);
                var x = ChartInfo.GetXByBar(bar);
                var y = Container.Region.Y;
 
                rectangle = new Rectangle(x, y, (int)ChartInfo.PriceChartContainer.BarsWidth, rowHeight);
                context.FillRectangle(Color.LightBlue, rectangle);
                if (drawText)
                    context.DrawString(candle.Volume.ToString(), font, Color.Black, rectangle);
 
                rectangle.Y += rowHeight;
                context.FillRectangle(Color.IndianRed, rectangle);
                if (drawText)
                    context.DrawString(candle.Bid.ToString(), font, Color.Black, rectangle);
 
                rectangle.Y += rowHeight;
                context.FillRectangle(Color.Lime, rectangle);
                if (drawText)
                    context.DrawString(candle.Ask.ToString(), font, Color.Black, rectangle);
 
            }
 
            #region draw headers
 
            rectangle = new Rectangle(0, Container.Region.Y, 100, rowHeight);
            context.FillRectangle(Color.Gray, rectangle);
            context.DrawString("Volume", font, Color.Black, rectangle);
 
            rectangle.Y += rowHeight;
            context.FillRectangle(Color.Gray, rectangle);
            context.DrawString("Bid", font, Color.Black, rectangle);
 
            rectangle.Y += rowHeight;
            context.FillRectangle(Color.Gray, rectangle);
            context.DrawString("Ask", font, Color.Black, rectangle);
 
            #endregion
        }
    }

 


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article