QuickStart - ChartObjects

Spotware's avatar

Spotware since: 23 Sep 2013;

  15 Jan 2014, 11:49
QuickStart - ChartObjects
// ---------------------------------------------------------------------------------------
//
//    This code demonstrates use of ChartObjects
//    It shows the maximum of a DataSeries for a period.
//
// ---------------------------------------------------------------------------------------

using System;
using cAlgo.API;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class ChartObjectsSample : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Period", DefaultValue = 30, MinValue = 3)]
        public int Period { get; set; }

        [Parameter("Text Color", DefaultValue = "Yellow")]
        public string TextColor { get; set; }

        [Parameter("Line Color", DefaultValue = "White")]
        public string LineColor { get; set; }


        private Colors _colorText;
        private Colors _colorLine;

        protected override void Initialize()
        {
            // Parse color from string

            if (!Enum.TryParse(TextColor, out _colorText))
            {
                ChartObjects.DrawText("errorMsg1", "Invalid Color for Text", StaticPosition.TopLeft, Colors.Red); 
                _colorText = Colors.Yellow;
            }

            if (!Enum.TryParse(LineColor, out _colorLine))
            {                
                ChartObjects.DrawText("errorMsg2", "\nInvalid Color for Line", StaticPosition.TopLeft, Colors.Red);
                _colorLine = Colors.White;
            }
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar) return;

            ChartObjects.DrawVerticalLine("vLine", index - Period, _colorLine);

            int maxIndex=index;
            double max = Source[index];

            for (int i = index - Period; i <= index; i++)
            {
                if (max >= Source[i])
                    continue;
                                       
                max = Source[i];
                maxIndex = i;

            }

            var text = "max " + max.ToString("0.0000");
            var top = VerticalAlignment.Top;
            var center = HorizontalAlignment.Center;

            ChartObjects.DrawText("max", text, maxIndex, max, top, center, _colorText);       
            ChartObjects.DrawLine("line", maxIndex, max, index, 
                                       Source[index], _colorLine);
        }
    }
}
TRADERS FIRST™ Vote for your favorite features: https://ctrader.com/forum/suggestions
bellong's avatar

bellong since: 14 Jun 2013;

  07 Apr 2014, 15:50
RE: how to change default font text size ?

Spotware said:

// ---------------------------------------------------------------------------------------
//
//    This code demonstrates use of ChartObjects
//    It shows the maximum of a DataSeries for a period.
//
// ---------------------------------------------------------------------------------------

using System;
using cAlgo.API;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class ChartObjectsSample : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Period", DefaultValue = 30, MinValue = 3)]
        public int Period { get; set; }

        [Parameter("Text Color", DefaultValue = "Yellow")]
        public string TextColor { get; set; }

        [Parameter("Line Color", DefaultValue = "White")]
        public string LineColor { get; set; }


        private Colors _colorText;
        private Colors _colorLine;

        protected override void Initialize()
        {
            // Parse color from string

            if (!Enum.TryParse(TextColor, out _colorText))
            {
                ChartObjects.DrawText("errorMsg1", "Invalid Color for Text", StaticPosition.TopLeft, Colors.Red); 
                _colorText = Colors.Yellow;
            }

            if (!Enum.TryParse(LineColor, out _colorLine))
            {                
                ChartObjects.DrawText("errorMsg2", "\nInvalid Color for Line", StaticPosition.TopLeft, Colors.Red);
                _colorLine = Colors.White;
            }
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar) return;

            ChartObjects.DrawVerticalLine("vLine", index - Period, _colorLine);

            int maxIndex=index;
            double max = Source[index];

            for (int i = index - Period; i <= index; i++)
            {
                if (max >= Source[i])
                    continue;
                                       
                max = Source[i];
                maxIndex = i;

            }

            var text = "max " + max.ToString("0.0000");
            var top = VerticalAlignment.Top;
            var center = HorizontalAlignment.Center;

            ChartObjects.DrawText("max", text, maxIndex, max, top, center, _colorText);       
            ChartObjects.DrawLine("line", maxIndex, max, index, 
                                       Source[index], _colorLine);
        }
    }
}

I have uploaded the indicator "draw spread" from your repo; and try to set a bigger font text size for displaying the "spread".  But im not lucky with my tweaks: how to insert the font size parameter ?

Spotware's avatar

Spotware since: 23 Sep 2013;

  07 Apr 2014, 16:09

At the moment it is not possible to change the font size.

TRADERS FIRST™ Vote for your favorite features: https://ctrader.com/forum/suggestions

ABR170173 since: 16 Mar 2015;

  17 Jul 2015, 13:55
RE:

Spotware said:

At the moment it is not possible to change the font size.

Does something has been changed in this case? Is possible to change font parameters now?

Spotware's avatar

Spotware since: 23 Sep 2013;

  17 Jul 2015, 14:23

Dear Traders,

This option is still not available. For your information you can post your ideas/suggestions to http://vote.spotware.com/.

TRADERS FIRST™ Vote for your favorite features: https://ctrader.com/forum/suggestions