Indicator to display data in overlay

Created at 22 May 2019, 02:17
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AL

alex_mihail

Joined 09.08.2018

Indicator to display data in overlay
22 May 2019, 02:17


How would I go about create an indicator that shows data in numbers as an overlay over the main chart like this one https://www.algodeveloper.com/product/symbol-info/

 

I want to showing Directional Movement Index as numbers rather than an indicator taking up space under the chart.


@alex_mihail
Replies

PanagiotisCharalampous
22 May 2019, 09:46

Hi Alex,

Just set the indicator attribute to IsOverlay to true. See below

[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

Best Regards,

Panagiotis


@PanagiotisCharalampous

alex_mihail
22 May 2019, 19:31

RE:

Panagiotis Charalampous said:

Hi Alex,

Just set the indicator attribute to IsOverlay to true. See below

[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

Best Regards,

Panagiotis

Hi Pantagiotis,

Thanks, so how do I use this to print Directional Movement Index values as text over the main chart rather than an indicator with lines under the chart?


@alex_mihail

PanagiotisCharalampous
23 May 2019, 10:02

Hi alex_mihail,

If you just want to print text on the chart then you can use Chart.DrawText() function.

Best Regards,

Panagiotis


@PanagiotisCharalampous

alex_mihail
23 May 2019, 13:29

RE:

Panagiotis Charalampous said:

Hi alex_mihail,

If you just want to print text on the chart then you can use Chart.DrawText() function.

Best Regards,

Panagiotis

Is there anywhere in the help documents that explains the x/y axis parameters? I have tried the DrawText function and am not sure how to get it to to place the text where I want.

 

EDIT: To be honest I have no idea what I'm doing haha, I want to overlay the # values from Directional Movement Index over the chart like this indicator does with ATR: https://www.algodeveloper.com/product/symbol-info/


@alex_mihail

... Deleted by UFO ...

PanagiotisCharalampous
23 May 2019, 14:26

Hi alex_mihail,

Y parameter is the price level you want to print the text and for x parameter you have a choice between the bar index and and date.

If you have no idea what you are doing then a good idea would be to contact Ahmad(AlgoDeveloper) to do this for you :)

Best Regards,

Panagiotis


@PanagiotisCharalampous

alex_mihail
24 May 2019, 20:22

RE:

Panagiotis Charalampous said:

Hi alex_mihail,

Y parameter is the price level you want to print the text and for x parameter you have a choice between the bar index and and date.

If you have no idea what you are doing then a good idea would be to contact Ahmad(AlgoDeveloper) to do this for you :)

Best Regards,

Panagiotis

 

Ahmad told me "not his job" but provided an example.

How do I call values from Directional Movement System to string to show in this text?

 

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TextSample : Indicator
    {
        #region Fields

        private Color _textColor;

        private HorizontalAlignment _textHorizontalAlignment;

        private VerticalAlignment _textVerticalAlignment;

        private DirectionalMovementSystem dmi;

        #endregion Fields

        #region Parameters

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

        [Parameter("Text Horizontal Alignment", DefaultValue = 0, MinValue = 0, MaxValue = 3)]
        public int TextHorizontalAlignment { get; set; }

        [Parameter("Text Vertical Alignment", DefaultValue = 1, MinValue = 0, MaxValue = 3)]
        public int TextVerticalAlignment { get; set; }

        #endregion Parameters

        #region Methods

        protected override void Initialize()
        {
            _textColor = Color.FromName(TextColor);

            _textHorizontalAlignment = (HorizontalAlignment)TextHorizontalAlignment;

            _textVerticalAlignment = (VerticalAlignment)TextVerticalAlignment;

            dmi = Indicators.GetIndicator<SampleSMA>(14);

            Chart.DrawStaticText("Text_TextSample", "DMI Values Here", _textVerticalAlignment, _textHorizontalAlignment, _textColor));
        }

        public override void Calculate(int index)
        {

        }

        #endregion Methods
    }
}


@alex_mihail

afhacker
25 May 2019, 11:52

Here is DMI on chart:

using cAlgo.API;
using cAlgo.API.Indicators;
using System;
using System.Text;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DmiOnChart : Indicator
    {
        #region Fields

        private readonly string _name = "DMI On Chart";

        private Color _textColor;

        private HorizontalAlignment _textHorizontalAlignment;

        private VerticalAlignment _textVerticalAlignment;

        private DirectionalMovementSystem _dmi;

        private string _chartObjectNamesSuffix;

        #endregion Fields

        #region Parameters

        [Parameter("DMI Period", DefaultValue = 14)]
        public int DmiPeriod { get; set; }

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

        [Parameter("Text Horizontal Alignment", DefaultValue = 0, MinValue = 0, MaxValue = 3)]
        public int TextHorizontalAlignment { get; set; }

        [Parameter("Text Vertical Alignment", DefaultValue = 1, MinValue = 0, MaxValue = 3)]
        public int TextVerticalAlignment { get; set; }

        #endregion Parameters

        #region Methods

        protected override void Initialize()
        {
            _chartObjectNamesSuffix = string.Format("{0}_{1}", DateTime.Now.Ticks, _name);

            _textColor = Color.FromName(TextColor);

            _textHorizontalAlignment = (HorizontalAlignment)TextHorizontalAlignment;

            _textVerticalAlignment = (VerticalAlignment)TextVerticalAlignment;

            _dmi = Indicators.DirectionalMovementSystem(DmiPeriod);
        }

        public override void Calculate(int index)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(string.Format("ADX: {0}", Math.Round(_dmi.ADX.LastValue, 1)));
            stringBuilder.AppendLine(string.Format("DI-: {0}", Math.Round(_dmi.DIMinus.LastValue, 1)));
            stringBuilder.AppendLine(string.Format("DI+: {0}", Math.Round(_dmi.DIPlus.LastValue, 1)));

            Chart.DrawStaticText(_chartObjectNamesSuffix, stringBuilder.ToString(), _textVerticalAlignment, _textHorizontalAlignment, _textColor);
        }

        #endregion Methods
    }
}

 


@afhacker

alex_mihail
25 May 2019, 14:41

Thanks Ahmad, I would never have worked that out!


@alex_mihail