Indicator does not work on new version

Created at 19 Dec 2022, 23:42
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!
JO

JoaoMGH

Joined 24.10.2020

Indicator does not work on new version
19 Dec 2022, 23:42


Hi, i am posting the whole code as requested by Panagiotis.

It worked fine on older versions, if u guys are able to test it.

it draws lines and a box at selected distance from Supertrend indicator.

selections can be via bool, to indexes, jpy pairs, and all other pairs.

many thanks, best regards.

 

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

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

        [Parameter("INDEX", Group = "INSTRUMENT", DefaultValue = false, MinValue = 5)]
        public bool INDEX { get; set; }

        [Parameter("OTHERS", Group = "INSTRUMENT", DefaultValue = false, MinValue = 5)]
        public bool EUR { get; set; }

        [Parameter("JPY", Group = "INSTRUMENT", DefaultValue = false, MinValue = 1)]
        public bool JPY { get; set; }

        [Parameter("ENTRY BOX IN PIPS ", DefaultValue = 10, Step = 5)]
        public double Buffer1 { get; set; }

        [Parameter("BUFFER 1 PIPS", DefaultValue = 25, Step = 5)]
        public double Buffer2 { get; set; }

        [Parameter("BUFFER 2 PIPS", DefaultValue = 50, Step = 5)]
        public double Buffer3 { get; set; }

        [Parameter("BUFFER 3 PIPS", DefaultValue = 100, Step = 5)]
        public double Buffer4 { get; set; }



        private Supertrend SUP;

        protected override void Initialize()
        {
            SUP = Indicators.Supertrend(6, 3);


        }
        public override void Calculate(int index)
        {
            var SUPdn = SUP.DownTrend.LastValue;
            var SUPup = SUP.UpTrend.LastValue;

            string one = Buffer1.ToString();
            string two = Buffer2.ToString();
            string tree = Buffer3.ToString();
            string four = Buffer4.ToString();

            if (EUR)
            {

                Chart.DrawHorizontalLine("horizontalLine1", ((SUPup + Buffer1 / 10000)), Color.DarkGreen, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine2", ((SUPup + Buffer2 / 10000)), Color.DarkGreen, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine3", ((SUPup + Buffer3 / 10000)), Color.DarkGreen, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine4", ((SUPup + Buffer4 / 10000)), Color.DarkGreen, 1, LineStyle.Lines);

                Chart.DrawText("test1", one, index + 5, ((SUPup + Buffer1 / 10000)), Color.DarkGreen);
                Chart.DrawText("test2", two, index + 5, ((SUPup + Buffer2 / 10000)), Color.DarkGreen);
                Chart.DrawText("test3", tree, index + 5, ((SUPup + Buffer3 / 10000)), Color.DarkGreen);
                Chart.DrawText("test4", four, index + 5, ((SUPup + Buffer4 / 10000)), Color.DarkGreen);

                Chart.DrawHorizontalLine("horizontalLine7", ((SUPdn - Buffer1 / 10000)), Color.DarkRed, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine8", ((SUPdn - Buffer2 / 10000)), Color.DarkRed, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine9", ((SUPdn - Buffer3 / 10000)), Color.DarkRed, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine10", ((SUPdn - Buffer4 / 10000)), Color.DarkRed, 1, LineStyle.Lines);

                Chart.DrawText("test11", one, index + 5, ((SUPdn - Buffer1 / 10000)), Color.DarkRed);
                Chart.DrawText("test88", two, index + 5, ((SUPdn - Buffer2 / 10000)), Color.DarkRed);
                Chart.DrawText("test99", tree, index + 5, ((SUPdn - Buffer3 / 10000)), Color.DarkRed);
                Chart.DrawText("test1010", four, index + 5, ((SUPdn - Buffer4 / 10000)), Color.DarkRed);

                Chart.DrawRectangle("Recta", index - 2, ((SUPup + (Buffer1 / 10000))), index + 2, SUPup, Color.DarkGreen, 2, LineStyle.Lines);



                Chart.DrawRectangle("Recta2", index - 2, ((SUPdn - (Buffer1 / 10000))), index + 2, SUPdn, Color.DarkRed, 2, LineStyle.Lines);


            }
            if (INDEX)
            {
                Chart.DrawHorizontalLine("horizontalLine1", ((SUPup + Buffer1)), Color.DarkGreen, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine2", ((SUPup + Buffer2)), Color.DarkGreen, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine3", ((SUPup + Buffer3)), Color.DarkGreen, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine4", ((SUPup + Buffer4)), Color.DarkGreen, 1, LineStyle.Lines);

                Chart.DrawText("test1", one, index + 5, ((SUPup + Buffer1)), Color.DarkGreen);
                Chart.DrawText("test2", two, index + 5, ((SUPup + Buffer2)), Color.DarkGreen);
                Chart.DrawText("test3", tree, index + 5, ((SUPup + Buffer3)), Color.DarkGreen);
                Chart.DrawText("test4", four, index + 5, ((SUPup + Buffer4)), Color.DarkGreen);

                Chart.DrawHorizontalLine("horizontalLine7", ((SUPdn - Buffer1)), Color.DarkRed, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine8", ((SUPdn - Buffer2)), Color.DarkRed, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine9", ((SUPdn - Buffer3)), Color.DarkRed, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine10", ((SUPdn - Buffer4)), Color.DarkRed, 1, LineStyle.Lines);

                Chart.DrawText("test77", one, index + 5, ((SUPdn - Buffer1)), Color.DarkRed);
                Chart.DrawText("test88", two, index + 5, ((SUPdn - Buffer2)), Color.DarkRed);
                Chart.DrawText("test99", tree, index + 5, ((SUPdn - Buffer3)), Color.DarkRed);
                Chart.DrawText("test1010", four, index + 5, ((SUPdn - Buffer4)), Color.DarkRed);

                Chart.DrawRectangle("Recta", index - 2, ((SUPup)), index + 2, SUPup, Color.DarkGreen, 2, LineStyle.Lines);



                Chart.DrawRectangle("Recta2", index - 2, ((SUPdn - (Buffer1))), index + 2, SUPdn, Color.DarkRed, 2, LineStyle.Lines);


            }


            if (JPY)
            {



                Chart.DrawHorizontalLine("horizontalLine1", ((SUPup + Buffer1 / 100)), Color.DarkGreen, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine2", ((SUPup + Buffer2 / 100)), Color.DarkGreen, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine3", ((SUPup + Buffer3 / 100)), Color.DarkGreen, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine4", ((SUPup + Buffer4 / 100)), Color.DarkGreen, 1, LineStyle.Lines);

                Chart.DrawText("test1", one, index + 5, ((SUPup + Buffer1 / 100)), Color.DarkGreen);
                Chart.DrawText("test2", two, index + 5, ((SUPup + Buffer2/ 100)), Color.DarkGreen);
                Chart.DrawText("test3", tree, index + 5, ((SUPup + Buffer3 / 100)), Color.DarkGreen);
                Chart.DrawText("test4", four, index + 5, ((SUPup + Buffer4 / 100)), Color.DarkGreen);

                Chart.DrawHorizontalLine("horizontalLine7", ((SUPdn - Buffer1 / 100)), Color.DarkRed, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine8", ((SUPdn - Buffer2 / 100)), Color.DarkRed, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine9", ((SUPdn - Buffer3 / 100)), Color.DarkRed, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("horizontalLine10", ((SUPdn - Buffer4 / 100)), Color.DarkRed, 1, LineStyle.Lines);

                Chart.DrawText("test77", one, index + 5, ((SUPdn - Buffer1 / 100)), Color.DarkRed);
                Chart.DrawText("test88", two, index + 5, ((SUPdn - Buffer2 / 100)), Color.DarkRed);
                Chart.DrawText("test99", tree, index + 5, ((SUPdn - Buffer3 / 100)), Color.DarkRed);
                Chart.DrawText("test1010", four, index + 5, ((SUPdn - Buffer4 / 100)), Color.DarkRed);


                Chart.DrawRectangle("Recta", index - 2, ((SUPup + (Buffer1 / 100))), index + 2, SUPup, Color.DarkGreen, 2, LineStyle.Lines);



                Chart.DrawRectangle("Recta2", index - 2, ((SUPdn - (Buffer1 / 100))), index + 2, SUPdn, Color.DarkRed, 2, LineStyle.Lines);




            }

        }


    }
}



 


@JoaoMGH
Replies

PanagiotisChar
20 Dec 2022, 09:40

Hi there,

Here is your problem. You should check if your values are NaN

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

JoaoMGH
20 Dec 2022, 11:35 ( Updated at: 21 Dec 2023, 09:23 )

Re: yes they are NaN

Hi hello, thanks for you answer.

In fact they are NaN, i should have told this on the first post, and thats the problem, dont know howw to work with that.

But what i dont understand is why it was working fine on older versions and now it doens't. 

how do i work this out?

Many thanks.

 

PanagiotisChar said

Hi there,

Here is your problem. You should check if your values are NaN

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 


@JoaoMGH

... Deleted by UFO ...

PanagiotisChar
20 Dec 2022, 12:06

But what i dont understand is why it was working fine on older versions and now it doens't. 

Because the previous version was just swallowing the exception, the new one doesn't. You need to handle it

In fact they are NaN, i should have told this on the first post, and thats the problem, dont know howw to work with that.

Check that they are not NaN before you use them

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us


@PanagiotisChar

JoaoMGH
20 Dec 2022, 16:20

RE:

Many thanks.

I'll try to fix it.

Best regards.

 

 

PanagiotisChar said:

But what i dont understand is why it was working fine on older versions and now it doens't. 

Because the previous version was just swallowing the exception, the new one doesn't. You need to handle it

In fact they are NaN, i should have told this on the first post, and thats the problem, dont know howw to work with that.

Check that they are not NaN before you use them

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@JoaoMGH