A Big Bug on result of Line1[index]

Created at 23 Jun 2015, 17:55
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!
IM

Iman

Joined 18.01.2015

A Big Bug on result of Line1[index]
23 Jun 2015, 17:55


Hi all,

I am encountering a problem when trying to get value of Indicator data series ,

My code is as follows:

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.None)]
    public class NewIndicator : Indicator
    {
        private string Space = "";

        private MarketSeries Market_Series;
        private int CC;
        [Output("Line1", Color = Colors.Blue)]
        public IndicatorDataSeries Line1 { get; set; }
        [Output("Line2", Color = Colors.Violet)]
        public IndicatorDataSeries Line2 { get; set; }

        protected override void Initialize()
        {
            Market_Series = MarketData.GetSeries(TimeFrame);
            CC = Market_Series.Close.Count;
        }

        public override void Calculate(int index)
        {
            double HH1 = Market_Series.High[index];
            double LL1 = Market_Series.Low[index];

            double HH2 = Market_Series.High[index];
            double LL2 = Market_Series.Low[index];


            for (int j = 0; j < 26; j++)
            {
                if (HH2 < Market_Series.High[index - j])
                {
                    HH2 = Market_Series.High[index - j];
                }
                if (LL2 > Market_Series.Low[index - j])
                {
                    LL2 = Market_Series.Low[index - j];
                }
            }

            Line2[index + 13] = (HH2 + LL2) / 2.0;




            if (index > CC - 200)
            {
                for (int j = 9; j <= 26; j++)
                {
                    for (int i = 0; i < j; i++)
                    {
                        if (HH1 < Market_Series.High[index - i])
                        {
                            HH1 = Market_Series.High[index - i];
                        }
                        if (LL1 > Market_Series.Low[index - i])
                        {
                            LL1 = Market_Series.Low[index - i];
                        }
                        Line1[index + 26 - j] = (HH1 + LL1) / 2.0;
                    }
                }
            }


            for (int i = CC; i < CC + 13; i++)
            {
                ChartObjects.DrawText("StaticPositionText" + i, Space + "Line1[" + i + "]= " + Line1[i] + " # Line2[" + i + "]= " + Line2[i], StaticPosition.TopRight, Colors.HotPink);
                Space += "\n";

                if ((Line1[i] >= Line2[i] && Line1[i - 1] < Line2[i - 1]))
                {

                    ChartObjects.DrawVerticalLine("CrossVerticalLine" + i, i, Colors.HotPink, 1, LineStyle.Lines);
                    ChartObjects.DrawText("CrossVerticalText" + i, "Line1[" + i + "]= " + Line1[i] + " # Line2[" + i + "]= " + Line2[i], i, LL1, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.HotPink);
                }
            }
            Space = "";
        }
    }
}

The TimeFrame is : "Month1"

As a result, the output indicator is shown in the following figure:

But as you can see, the return value of the Line1 does not match by the values indicated in the upper right corner and

these values are wrong.

For example the value shown on vertical line is equal to 1.304215 (Line1[321] = 1.304215) but the actual value of Line1[321] is 1.222765 .

Please guide me as soon as possible .

 


@Iman
Replies

Spotware
24 Jun 2015, 10:05

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware

Iman
27 Jun 2015, 10:16 ( Updated at: 21 Dec 2023, 09:20 )

I think that cAlgo has a Big Bug and it need to debug very soon!

This problem is in the “ChartObjects.DrawText” code.

When I use it in the “For” loop, before “If” command (Line 76), it give different output than use it inside “if” (Line 83) command in this code!

Please see carefully again following code “

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.None)]
    public class NewIndicator : Indicator
    {
        private string Space = "";
 
        private MarketSeries Market_Series;
        private int CC;
        [Output("Line1", Color = Colors.Blue)]
        public IndicatorDataSeries Line1 { get; set; }
        [Output("Line2", Color = Colors.Violet)]
        public IndicatorDataSeries Line2 { get; set; }
 
        protected override void Initialize()
        {
            Market_Series = MarketData.GetSeries(TimeFrame);
            CC = Market_Series.Close.Count;
        }
 
        public override void Calculate(int index)
        {
            double HH1 = Market_Series.High[index];
            double LL1 = Market_Series.Low[index];
 
            double HH2 = Market_Series.High[index];
            double LL2 = Market_Series.Low[index];
 
 
            for (int j = 0; j < 26; j++)
            {
                if (HH2 < Market_Series.High[index - j])
                {
                    HH2 = Market_Series.High[index - j];
                }
                if (LL2 > Market_Series.Low[index - j])
                {
                    LL2 = Market_Series.Low[index - j];
                }
            }
 
            Line2[index + 13] = (HH2 + LL2) / 2.0;
 
 
 
 
            if (index > CC - 200)
            {
                for (int j = 9; j <= 26; j++)
                {
                    for (int i = 0; i < j; i++)
                    {
                        if (HH1 < Market_Series.High[index - i])
                        {
                            HH1 = Market_Series.High[index - i];
                        }
                        if (LL1 > Market_Series.Low[index - i])
                        {
                            LL1 = Market_Series.Low[index - i];
                        }
                        Line1[index + 26 - j] = (HH1 + LL1) / 2.0;
                    }
                }
            }
 
 
            for (int i = CC; i < CC + 13; i++)
            {
                ChartObjects.DrawText("StaticPositionText" + i, Space + "Line1[" + i + "]= " + Line1[i] + " # Line2[" + i + "]= " + Line2[i], StaticPosition.TopRight, Colors.HotPink);
                Space += "\n";
 
                if ((Line1[i] >= Line2[i] && Line1[i - 1] < Line2[i - 1]))
                {
 
                    ChartObjects.DrawVerticalLine("CrossVerticalLine" + i, i, Colors.HotPink, 1, LineStyle.Lines);
                    ChartObjects.DrawText("CrossVerticalText" + i, "Line1[" + i + "]= " + Line1[i] + " # Line2[" + i + "]= " + Line2[i], i, LL1, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.HotPink);
                }
            }
            Space = "";
        }
    }
}

As you can see, I have two series it output on the below Chart:

 

When I use “ChartObjects.DrawText” code inside “FOR” and outside “IF” (Line 76), for example: Line1for candle No.320 has value =1.222765(as shown top right corner) that’s right! But the same value is 1.317535 on the chart! That it is for Line2 [320]!

Whatever my code is correct’ but cAlgo calculates and shows two different value for the same command on chart.

I no need to any programmer that write code for me. YOU MUST DEBUG cAlgo! Because I think that is bug in Platform cAlgo.

PLEASE CONSIDER MATTER TO DEVELOPER CALGO TEAM IN SPOTWARE CO. AND SEND RESULT HERE.

Thanks a lot.

Good Luck!

 


@Iman

Spotware
29 Jun 2015, 14:25

Dear Trader,

As already mentioned we do not provide coding assistance services. If you believe that there is a bug/issue in cAlgo.API, could you please send us the simplest indicator that reproduces this issue. Then we will investigate. Thank you in advance.


@Spotware

Iman
29 Jun 2015, 14:57

Thank you and good luck !


@Iman