Getting coordinates from objects drawn by cystom indicator.

Created at 03 Aug 2022, 09:43
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!
IS

isabakas

Joined 25.11.2021

Getting coordinates from objects drawn by cystom indicator.
03 Aug 2022, 09:43


Hi all, how would one store the coordinates from objects that are drawn on the chart by a custom indicator? I I want my indicator to draw a trendline between each arrow it draws. Therefore i need the coordinates of the arrows.

Sourcecode:

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class Multitimeframerenkoema : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("SlowmaPeriods", DefaultValue = 14)]
        public int SlowmaPeriods { get; set; }
        
        [Parameter("FastmaPeriods", DefaultValue = 14)]
        public int FastmaPeriods { get; set; }

        [Output("Slowma", LineColor = "Red")]
        public IndicatorDataSeries Resultslowma { get; set; }
        
        [Output("Fastma", LineColor = "Yellow")]
        public IndicatorDataSeries Resultfastma { get; set; }
        
        [Output("Cross")]
        public IndicatorDataSeries Resultcross { get; set; }

        private double slowma;
        private double fastma;
        
        protected override void Initialize()
        {
            slowma = 2.0 / (SlowmaPeriods + 1);
            fastma = 2.0 / (FastmaPeriods + 1);
        }

        public override void Calculate(int index)
        {
        //Slowma
            var previousValueslow = Resultslowma[index - 1];
            
            if (double.IsNaN(previousValueslow))
            {
                Resultslowma[index] = Source[index];
            }
            else
            {
                Resultslowma[index] = Source[index] * slowma + previousValueslow * (1 - slowma);
            }
            
        //Fastma
            {
           var previousValuefast = Resultfastma[index - 1];
           
           if (double.IsNaN(previousValuefast))
            {
                Resultfastma[index] = Source[index];
            }
            else
            {
                Resultfastma[index] = Source[index] * fastma + previousValuefast * (1 - fastma);
            }

            if ((previousValueslow > previousValuefast && Resultslowma[index] < Resultfastma[index]))
                Resultcross[index] = 1;
            else if (previousValueslow < previousValuefast && Resultslowma[index] > Resultfastma[index])
                Resultcross[index] = -1;
            else
                Resultcross[index] = 0;

            //Draw arrows
            if (Resultcross[index] == 1)
            {
                Chart.DrawIcon(index.ToString(), ChartIconType.UpArrow, index, Bars.LowPrices[index], "blue");
            }
            else if (Resultcross[index] == -1)
            {
                Chart.DrawIcon(index.ToString(), ChartIconType.DownArrow, index, Bars.HighPrices[index], "purple");
            }
           
          
         }
    }
    }
}
 


@isabakas