Fibo and zig zag custom

Created at 03 Oct 2020, 15:08
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!
LU

luca.tocchi

Joined 25.03.2020

Fibo and zig zag custom
03 Oct 2020, 15:08


 

hi this is my bot where i entered the zig zag indicator. now I would like to insert this other indicator called Autofibo. How can I insert and print the values of the fibonacci lines?

Thank you

My bot:

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class zigzagfattobene : Robot
    {
        [Parameter(DefaultValue = 12)]
        public int Depth { get; set; }

        [Parameter(DefaultValue = 5)]
        public int Deviation { get; set; }

        [Parameter(DefaultValue = 3)]
        public int BackStep { get; set; }

        [Output("ZigZag", Color = Colors.OrangeRed)]
        public IndicatorDataSeries Result { get; set; }

        private ZigZag zigzag1;

        protected override void OnStart()
        {
            zigzag1 = Indicators.GetIndicator<ZigZag>(12, 5, 3);
        }

        double GetZigZagValue(DataSeries dataSeries, int indexFromEnd)
        {
            for (var i = MarketSeries.Close.Count - 1; i >= 0; i--)
            {
                if (!double.IsNaN(zigzag1.Result[i]))
                {
                    if (indexFromEnd == 0)
                        return zigzag1.Result[i];
                    indexFromEnd--;
                }
            }
            return double.NaN;
        }

        protected override void OnTick()
        {
            var lastValue = GetZigZagValue(zigzag1.Result, 0);
            var previousValue = GetZigZagValue(zigzag1.Result, 1);

            if (lastValue > previousValue)
                Print("lastValue {0} > previousValue {1}", lastValue, previousValue);
            if (lastValue < previousValue)
                Print("lastValue {0} < previousValue {1}", lastValue, previousValue);

        }
    }
}

 

Autofibo

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Autofibo : Indicator
    {
        [Parameter("Look Back Period ", DefaultValue = 100)]
        public int lookback { get; set; }

        [Parameter("Series Timeframe")]
        public TimeFrame tf { get; set; }




        private MarketSeries series1;


        protected override void Initialize()
        {
            // Initialize and create nested indicators
            series1 = MarketData.GetSeries(tf);

            OnTimer();
            Timer.Start(60);
        }

        protected override void OnTimer()
        {
            // Initialize and create nested indicators

            //find index
            var hidate = Time.Date;
            var lodate = Time.Date;
            var superhi = MarketSeries.Close.LastValue;
            var superlo = MarketSeries.Close.LastValue;
            var highval = series1.High;
            var loval = series1.Low;

            for (var i = 0; i < lookback; i++)
            {
                //find hi
                if (highval.Last(i) > superhi)
                {
                    superhi = highval.Last(i);
                    hidate = series1.OpenTime.Last(i);
                }

                //findlo
                if (loval.Last(i) < superlo)
                {
                    superlo = loval.Last(i);
                    lodate = series1.OpenTime.Last(i);
                }


                var bull = (hidate > lodate) ? true : false;
                var datechosen = (bull) ? lodate : hidate;

                //set value of line

                List<double> level = new List<double> 
                {
                    0.0,
                    23.6,
                    38.0,
                    50.0,
                    61.8,
                    100
                };


                var now = MarketSeries.OpenTime.LastValue;
                var distance = superhi - superlo;
//drawline 

                foreach (var lev in level)
                {
                    var dev = lev / 100 * distance;
                    var val = (bull) ? superhi - dev : superlo + dev;

                    ChartObjects.DrawLine(lev + "%", datechosen, val, now, val, (bull) ? Colors.Red : Colors.Blue, 1, LineStyle.Solid);
                    ChartObjects.DrawText(lev + "% text", lev + "%", MarketSeries.OpenTime.Count + 1, val + 0.5 * Symbol.PipSize, VerticalAlignment.Center, HorizontalAlignment.Right, (bull) ? Colors.Red : Colors.Blue);



                }

            }
        }

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

I have read the references on the indicators but I find some difficulties

 


@luca.tocchi
Replies

PanagiotisCharalampous
05 Oct 2020, 08:07

Hi Luca,

The information you need to access in not accessible from this indicator. You need to make the information accessibe e.g. through a public property, and then access it from the cBot.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

luca.tocchi
05 Oct 2020, 13:41

RE:

PanagiotisCharalampous said:

Hi Luca,

The information you need to access in not accessible from this indicator. You need to make the information accessibe e.g. through a public property, and then access it from the cBot.

Best Regards,

Panagiotis 

Join us on Telegram

Thanks!


@luca.tocchi

... Deleted by UFO ...