How to draw multiple same Chart Objects

Created at 23 Jun 2015, 13:27
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!
VL

Vlad_Wulf

Joined 23.06.2015

How to draw multiple same Chart Objects
23 Jun 2015, 13:27


Hello,

 

I am looking to spawn several vertical lines on the chart when the conditions are met.

The problem is that ChartObjects.DrawVerticalLine();  creates one line only.

 

I am using something like this in calculate:

 

  for (int i = index - 20; i <= index; i++)
            {
                ChartObjects.DrawVerticalLine("line", index, Colors.Orange);
            }

 

Normally it shoud draw a Line at each Bar but it does that one the last one only.

What's the problem?

 

Thanks


@Vlad_Wulf
Replies

Vlad_Wulf
23 Jun 2015, 13:40

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

int iterator = 0;
        protected override void Initialize()
        {
            // Initialize and create nested indicators
        }

        public override void Calculate(int index)
        {

string lineName = "line" + iterator;
           for (int i = index - Period; i <= index; i++)
            {
            
                ChartObjects.DrawVerticalLine(lineName, index, Colors.Orange);
                iterator += 1;


            }
        }
    }
}

Nevermind I resolved it this way.


@Vlad_Wulf

WhiteSage
25 Jun 2015, 16:50

Thats pretty much what I was going to suggest!

Objects must have unique names, that was they can be changed or deleted ;)


@WhiteSage