Accessing Costume Indicator via cBots Mayhem - ZigZag

HexDex since: 21 Sep 2022;

  21 Sep 2022, 15:44
Accessing Costume Indicator via cBots Mayhem - ZigZag

Dear support and members here,

Trust me, if I had any other choice than to create this topic, I would have done it. I have spent a monster amount of time playing with codes and reading this forum but I could not get a solution for my problem. So I need your support and guidance here.

Background:

I have a ZigZag indicator that I need to get its extremes(Peaks and Valleys) within my cBot to do what I want to do(Trading logic and whatnot). Obviously to get the ZigZag indicator extreme points I need to call it and access its outputs within my cBot code. 

What I did:

  • the indicator has source code is built with no errors and warnings --> OK
  • I added a reference to my cBot to the indicator ---> OK

  • re-built the indicator --> OK
  • re-built the cBot  --> OK
  • I added the necessary codes as shown below(Note, it works just fine and with no issues with every single customer indicator that I have except this one which I need)

Results:

After doing all the above when I try to build the cBot I keep getting these errors.

Codes for reference and investigation:

The cBot:

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class test : Robot
    {
        private MyZigZag _zz;
        [Parameter(DefaultValue = "Hello world!")]
        public string Message { get; set; }
        protected override void OnStart()
        {
           _zz = Indicators.GetIndicator<MyZigZag>( 20,5,3);
        }

        protected override void OnTick()
        {
        }

        protected override void OnStop()
        {
        }
    }
}

The Indicator 

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


namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MyZigZag:Indicator
    {

        [Parameter(DefaultValue = 20)]
        public int Depth { get; set; }

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

        [Output("MyZigZag", LineColor ="#FFFF0000")]
        public IndicatorDataSeries Result { get; set; }

        #region Private fields
        
        private double _lastLow;
        private double _lastHigh;
        private double _low;
        private double _high;
        private int _lastHighIndex;
        private int _lastLowIndex;
        private int _type;
        private double _point;
        private double _currentLow;
        private double _currentHigh;

        private IndicatorDataSeries _highZigZags; 
        private IndicatorDataSeries _lowZigZags;
        
        #endregion

        protected override void Initialize()
        {
            _highZigZags = CreateDataSeries();
            _lowZigZags = CreateDataSeries();
            _point = Symbol.TickSize;
        }

        public override void Calculate(int index)
        {
           
            if (index < Depth)
            {
                Result[index] = 0;
                _highZigZags[index] = 0;
                _lowZigZags[index] = 0;
                return;
            }

            _currentLow = Functions.Minimum(Bars.LowPrices, Depth);            
            if (Math.Abs(_currentLow - _lastLow) < double.Epsilon)
                _currentLow = 0.0;
            else
            {
                _lastLow = _currentLow;
                
                if ((Bars.LowPrices[index] - _currentLow) > (Deviation * _point))
                    _currentLow = 0.0;
                else
                {
                    for (int i = 1; i <= BackStep; i++)
                    {
                        if (Math.Abs(_lowZigZags[index - i]) > double.Epsilon 
                            && _lowZigZags[index - i] > _currentLow)
                            _lowZigZags[index - i] = 0.0;
                    }
                }
            }
            if (Math.Abs(Bars.LowPrices[index] - _currentLow) < double.Epsilon)
                _lowZigZags[index] = _currentLow;
            else
                _lowZigZags[index] = 0.0;

            _currentHigh = Bars.HighPrices.Maximum(Depth);

            if (Math.Abs(_currentHigh - _lastHigh) < double.Epsilon)
                _currentHigh = 0.0;
            else
            {
                _lastHigh = _currentHigh;

                if ((_currentHigh - Bars.HighPrices[index] ) > (Deviation * _point))
                    _currentHigh = 0.0;
                else
                {
                    for (int i = 1; i <= BackStep; i++)
                    {
                        if (Math.Abs(_highZigZags[index - i]) > double.Epsilon && _highZigZags[index - i] < _currentHigh)
                            _highZigZags[index - i] = 0.0;
                    }
                }
            }

            if (Math.Abs(Bars.HighPrices[index] - _currentHigh) < double.Epsilon)
                _highZigZags[index] = _currentHigh;
            else
                _highZigZags[index] = 0.0;


            switch(_type)
            {
                case 0:
                    if(Math.Abs(_low - 0) < double.Epsilon && Math.Abs(_high - 0) < double.Epsilon)
                    {
                        if(Math.Abs(_highZigZags[index]) > double.Epsilon)
                        {
                            _high = Bars.HighPrices[index];
                            _lastHighIndex = index;
                            _type = -1;
                            Result[index] = _high;
                        }
                        if(Math.Abs(_lowZigZags[index]) > double.Epsilon)
                        {
                            _low = Bars.LowPrices[index];
                            _lastLowIndex = index;
                            _type = 1;
                            Result[index] = _low;
                        }
                    }
                    break;
                case 1:
                    if (Math.Abs(_lowZigZags[index]) > double.Epsilon && _lowZigZags[index] < _low && Math.Abs(_highZigZags[index] - 0.0) < double.Epsilon)
                    {
                        Result[_lastLowIndex] = double.NaN;
                        _lastLowIndex = index;
                        _low = _lowZigZags[index];
                        Result[index] = _low;
                    }
                    if (Math.Abs(_highZigZags[index] - 0.0) > double.Epsilon && Math.Abs(_lowZigZags[index] - 0.0) < double.Epsilon)
                    {
                        _high = _highZigZags[index];
                        _lastHighIndex = index;
                        Result[index] = _high;
                        _type = -1;
                    }
                    break;
                case -1:
                    if (Math.Abs(_highZigZags[index]) > double.Epsilon && _highZigZags[index] > _high && Math.Abs(_lowZigZags[index] - 0.0) < double.Epsilon)
                    {
                        Result[_lastHighIndex] = double.NaN;
                        _lastHighIndex = index;
                        _high = _highZigZags[index];
                        Result[index] = _high;
                    }
                    if (Math.Abs(_lowZigZags[index]) > double.Epsilon && Math.Abs(_highZigZags[index]) <= double.Epsilon)
                    {
                        _low = _lowZigZags[index];
                        _lastLowIndex = index;
                        Result[index] = _low;
                        _type = 1;
                    }
                    break;
                default: return;
            }
            
        }
    }
}
PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  21 Sep 2022, 15:09

Hi HexDex,

As far as I can see the indicator is called Kamz and not MyZigZag.

Best Regards,

Panagiotis 

Join us onTelegram andFacebook

Head of Community Management at cTrader

HexDex since: 21 Sep 2022;

  21 Sep 2022, 15:46
RE:

PanagiotisCharalampous said:

Hi HexDex,

As far as I can see the indicator is called Kamz and not MyZigZag.

Best Regards,

Panagiotis 

Join us onTelegram andFacebook

Hi,

You are right but that was me posting the code before renaming it. I updated the code in the first post but the same problem persists to exist. 

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  22 Sep 2022, 12:43

Hi HexDex,

You don't seem to reference the Indicator's namespace

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MyZigZag:Indicator
    {

inside the cBot

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

Best Regards,

Panagiotis 

Join us onTelegram andFacebook

Head of Community Management at cTrader

HexDex since: 21 Sep 2022;

  22 Sep 2022, 13:33
RE:

PanagiotisCharalampous said:

Hi HexDex,

You don't seem to reference the Indicator's namespace

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MyZigZag:Indicator
    {

inside the cBot

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

Best Regards,

Panagiotis 

Join us onTelegram andFacebook

Hi,

Sorry, I don't get you, what am I missing exactly? Could you elaborate on how to fix it?

What code should I add to cBot/Indicator to rectify the issue?

Cheers

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  22 Sep 2022, 13:40

Hi HexDex,

Add the namespace in the using section.

Best Regards,

Panagiotis 

Join us onTelegram andFacebook

Head of Community Management at cTrader

HexDex since: 21 Sep 2022;

  22 Sep 2022, 14:59
RE:

PanagiotisCharalampous said:

Hi HexDex,

Add the namespace in the using section.

Best Regards,

Panagiotis 

Join us onTelegram andFacebook

RESOLVED now. Thanks heaps for the help