DrawText of TimeFrame

Created at 24 Sep 2017, 09:35
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!
MaVe's avatar

MaVe

Joined 24.08.2015

DrawText of TimeFrame
24 Sep 2017, 09:35


Hi,

can somebody tell me how to draw the TimeFrame Text "H12" instead of Hour12?

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

namespace cAlgo
{
    [Indicator("Text", IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Text : Indicator
    {
        [Parameter("Test TimeFrame", DefaultValue = "Hour12")]
        public TimeFrame TestTimeFrame { get; set; }
        private MarketSeries T;
// -----        
        Colors Tc = Colors.Black;
// ------------------------------------------------------        
        protected override void Initialize()
        {
            T = MarketData.GetSeries(Symbol, TestTimeFrame);
        }
// ------------------------------------------------------ 
        public override void Calculate(int index)
        {
            var Text = TestTimeFrame;

            ChartObjects.DrawText("Text", "Text " + Text, index + 1, T.Close.Last(1), VerticalAlignment.Top, HorizontalAlignment.Right, Tc);
        }
    }
}


@MaVe
Replies

PanagiotisCharalampous
25 Sep 2017, 09:51

Hi MaVe,

There is no build in way to do that. You can try implementing your own function as below

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

namespace cAlgo
{
    [Indicator("Text", IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Text : Indicator
    {
        [Parameter("Test TimeFrame", DefaultValue = "Hour12")]
        public TimeFrame TestTimeFrame { get; set; }
        private MarketSeries T;
// -----        
        Colors Tc = Colors.White;
// ------------------------------------------------------        
        protected override void Initialize()
        {
            T = MarketData.GetSeries(Symbol, TestTimeFrame);
        }
// ------------------------------------------------------ 
        public override void Calculate(int index)
        {
            var Text = GetTimeFrameText();
            ChartObjects.DrawText("Text", "Text " + Text, index + 1, T.Close.Last(1), VerticalAlignment.Top, HorizontalAlignment.Right, Tc);
        }

        private string GetTimeFrameText()
        {
            if (TestTimeFrame == TimeFrame.Hour12)
            {
                return "H12";
            }
            return TestTimeFrame;
        }
    }
}

You can add more conditions and put the text you need for each timeframe. Let me know if this helps.

Best Regards,

Panagiotis


@PanagiotisCharalampous

MaVe
25 Sep 2017, 10:20

Hi Panagiotis,

Thank you for providing this information.

It would be easier if it was available as a DefaultValue...

MaVe


@MaVe

MaVe
25 Sep 2017, 11:19

Hi Panagiotis,

There is an error message at line 35 for the above suggestion.

Error CS0029

I don't know how to fix this...

MaVe


@MaVe

... Deleted by UFO ...

PanagiotisCharalampous
25 Sep 2017, 11:26

Hi MaVe,

The below should be working

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

namespace cAlgo
{
    [Indicator("Text", IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Text : Indicator
    {
        [Parameter("Test TimeFrame", DefaultValue = "Hour12")]
        public TimeFrame TestTimeFrame { get; set; }
        private MarketSeries T;
// -----        
        Colors Tc = Colors.White;
// ------------------------------------------------------        
        protected override void Initialize()
        {
            T = MarketData.GetSeries(Symbol, TestTimeFrame);
        }
// ------------------------------------------------------ 
        public override void Calculate(int index)
        {
            var Text = GetTimeFrameText();
            ChartObjects.DrawText("Text", "Text " + Text, index + 1, T.Close.Last(1), VerticalAlignment.Top, HorizontalAlignment.Right, Tc);
        }

        private string GetTimeFrameText()
        {
            if (TestTimeFrame == TimeFrame.Hour12)
            {
                return "H12";
            }
            return TestTimeFrame.ToString();
        }
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous