How to display levels on an Indicator?

Created at 05 May 2019, 16:30
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!
FI

firemyst

Joined 26.03.2019

How to display levels on an Indicator?
05 May 2019, 16:30


This code doesn't work. It only displays "0.000000000" on the chart when added.

Why?

I can scroll up or down, and nothing else is shown as shown in the screen capture.

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

namespace cAlgo
{
    [Levels(2, 1, 0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ConditionsOfEntry : Indicator
    {
        [Output("UpwardSell", LineStyle = LineStyle.Solid, PlotType = PlotType.Points, LineColor = "Red")]
        public IndicatorDataSeries UpwardSell { get; set; }
        [Output("UpwardNeutral", LineStyle = LineStyle.Solid, PlotType = PlotType.Points, LineColor = "Yellow")]
        public IndicatorDataSeries UpwardNeutral { get; set; }
        [Output("UpwardBuy", LineStyle = LineStyle.Solid, PlotType = PlotType.Points, LineColor = "Lime")]
        public IndicatorDataSeries UpwardBuy { get; set; }

        public int UpwardCount { get; set; }

        private const int UpwardMax = 5;

        public override void Calculate(int index)
        {
            //if (UpwardCount >= UpwardMax)
                UpwardBuy[index] = UpwardCount;
            //else if (UpwardCount > Math.Round(UpwardMax / 2.0, MidpointRounding.AwayFromZero))
            //    UpwardNeutral[index] = UpwardCount;
            //else
            //    UpwardSell[index] = UpwardCount;
        }

    }
}

 


@firemyst
Replies

PanagiotisCharalampous
06 May 2019, 12:34

Hi FireMyst,

What do you expect the code to do?  UpwardCount is always 0.

Best Regards,

Panagiotis


@PanagiotisCharalampous

firemyst
06 May 2019, 12:41

RE:

Panagiotis Charalampous said:

Hi FireMyst,

What do you expect the code to do?  UpwardCount is always 0.

Best Regards,

Panagiotis

I expect cTrader to show the levels 0, 1, 2 as per the Levels specification at the top of the code:

[Levels(2, 1, 0)]

regardless of what the output values would be.

Just like some indicators would have levels -2, -1, 0, 1, 2, but if the indicator runs and never goes below zero, the levels -1 and -2 are still shown.

 

 


@firemyst

PanagiotisCharalampous
06 May 2019, 12:58

Hi FireMyst,

The levels will appear when your indicator starts getting more values. At the moment it is zoomed at 0. e.g.

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

namespace cAlgo
{
    [Levels(2, 1, 0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ConditionsOfEntry : Indicator
    {
        [Output("UpwardSell", LineStyle = LineStyle.Solid, PlotType = PlotType.Points, LineColor = "Red")]
        public IndicatorDataSeries UpwardSell { get; set; }
        [Output("UpwardNeutral", LineStyle = LineStyle.Solid, PlotType = PlotType.Points, LineColor = "Yellow")]
        public IndicatorDataSeries UpwardNeutral { get; set; }
        [Output("UpwardBuy", LineStyle = LineStyle.Solid, PlotType = PlotType.Points, LineColor = "Lime")]
        public IndicatorDataSeries UpwardBuy { get; set; }

        public int UpwardCount { get; set; }

        private const int UpwardMax = 5;

        public override void Calculate(int index)
        {
            //if (UpwardCount >= UpwardMax)
            UpwardBuy[index] = index % 10;
            //else if (UpwardCount > Math.Round(UpwardMax / 2.0, MidpointRounding.AwayFromZero))
            //    UpwardNeutral[index] = UpwardCount;
            //else
            //    UpwardSell[index] = UpwardCount;
        }

    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous

firemyst
06 May 2019, 16:08

RE:

Panagiotis Charalampous said:

Hi FireMyst,

The levels will appear when your indicator starts getting more values. At the moment it is zoomed at 0. e.g.

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

namespace cAlgo
{
    [Levels(2, 1, 0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ConditionsOfEntry : Indicator
    {
        [Output("UpwardSell", LineStyle = LineStyle.Solid, PlotType = PlotType.Points, LineColor = "Red")]
        public IndicatorDataSeries UpwardSell { get; set; }
        [Output("UpwardNeutral", LineStyle = LineStyle.Solid, PlotType = PlotType.Points, LineColor = "Yellow")]
        public IndicatorDataSeries UpwardNeutral { get; set; }
        [Output("UpwardBuy", LineStyle = LineStyle.Solid, PlotType = PlotType.Points, LineColor = "Lime")]
        public IndicatorDataSeries UpwardBuy { get; set; }

        public int UpwardCount { get; set; }

        private const int UpwardMax = 5;

        public override void Calculate(int index)
        {
            //if (UpwardCount >= UpwardMax)
            UpwardBuy[index] = index % 10;
            //else if (UpwardCount > Math.Round(UpwardMax / 2.0, MidpointRounding.AwayFromZero))
            //    UpwardNeutral[index] = UpwardCount;
            //else
            //    UpwardSell[index] = UpwardCount;
        }

    }
}

Best Regards,

Panagiotis

 

I obviously found that a bit confusing because when I specify levels, I'd expect to see them there when the chart loads.

Might be worth considering updating the API documentation so others aren't caught out by it,but I'll leave that decision with your team.

Thank you.


@firemyst