Indicator and ChartObjects.DrawHorizontalLine

Created at 03 Feb 2019, 18:28
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!
PM

pmcarvalho

Joined 16.01.2019

Indicator and ChartObjects.DrawHorizontalLine
03 Feb 2019, 18:28


Hi

I have made the following indicator.

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 Test : Indicator
    {
        protected override void Initialize()
        {
            // Initialize and create nested indicators
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
        }

        public void DrawOpen()
        {
            ChartObjects.DrawHorizontalLine("Open", MarketSeries.Open.Last(1), Colors.Red);
        }
    }
}

 

And in the cbot i wrote the following lines in OnStart

Test testInd = Indicators.GetIndicator<Test>();
testInd.DrawOpen();

But the line is not being drawn.

But if the function is in cbot, the line is drawn.

What am I doing wrong?

Thanks


@pmcarvalho
Replies

PanagiotisCharalampous
04 Feb 2019, 10:30

Hi pmcarvalho,

Why do you need to have the function inside an indicator?

Best Regards,

Panagiotis


@PanagiotisCharalampous

pmcarvalho
04 Feb 2019, 11:24

Hi Panagiotis

Because I wanted to do a functions library.

I have functions that are used in some bots and I have to have the same functions in all of them. And when I have to change one, I have to be looking at all the bots.

And I do not know a way to do a library of functions.

Thanks


@pmcarvalho