Replies

andresort28
17 Apr 2020, 07:00

RE:
  • PanagiotisCharalampous said:

Hi andresort28,

Can you please post the indicator code and let us know which broker you use?

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi Panagiotis,
I attached my indicator code. I'm using FxPro as my broker.
Please help me to know which is wrong and why I'm getting that error.

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class HeikenAshiSmoothed : Indicator
    {
        [Parameter("Open")]
        public static DataSeries Source_Open { get; set; }

        [Parameter("Close")]
        public DataSeries Source_Close { get; set; }

        [Parameter("High")]
        public DataSeries Source_High { get; set; }

        [Parameter("Low")]
        public DataSeries Source_Low { get; set; }

        [Parameter(DefaultValue = 50, MinValue = 1)]
        public int Periods { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType { get; set; }

        public const string START_ROW = "\n\n\n";
        private Color color_up = Color.LawnGreen;
        private Color color_down = Color.Red;

        private MovingAverage maOpen;
        private MovingAverage maClose;
        private MovingAverage maHigh;
        private MovingAverage maLow;
        private IndicatorDataSeries haClose;
        private IndicatorDataSeries haOpen;

        private int count;
        private int index_actual;
        private Color color_close;


        protected override void Initialize()
        {
            Print("Initialize HA");
            maOpen = Indicators.MovingAverage(Source_Open, Periods, MAType);
            maClose = Indicators.MovingAverage(Source_Close, Periods, MAType);
            maHigh = Indicators.MovingAverage(Source_High, Periods, MAType);
            maLow = Indicators.MovingAverage(Source_Low, Periods, MAType);

            haOpen = CreateDataSeries();
            haClose = CreateDataSeries();

            count = 0;
        }

        public override void Calculate(int index)
        {
            count++;
            string t1 = START_ROW + "Count:\t" + count;
            string t2 = "\nIndex:\t" + index;
            Chart.DrawStaticText("data", t1 + t2, VerticalAlignment.Top, HorizontalAlignment.Left, Color.LightBlue);

            double haHigh;
            double haLow;
            Color colorCandle;

            if (index > index_actual)
            {
                index_actual = index;

                Chart.DrawStaticText("Label_Close", START_ROW + "\n\n" + "Close:", VerticalAlignment.Top, HorizontalAlignment.Left, Color.LightBlue);

                if (color_close == color_up)
                    Chart.DrawStaticText("close_data", START_ROW + "\n\n" + "\tUp", VerticalAlignment.Top, HorizontalAlignment.Left, color_up);
                if (color_close == color_down)
                    Chart.DrawStaticText("close_data", START_ROW + "\n\n" + "\tDown", VerticalAlignment.Top, HorizontalAlignment.Left, color_down);
            }

            if (index > 0 && !double.IsNaN(maOpen.Result[index - 1]))
            {
                haOpen[index] = (haOpen[index - 1] + haClose[index - 1]) / 2;
                haClose[index] = (maOpen.Result[index] + maClose.Result[index] + maHigh.Result[index] + maLow.Result[index]) / 4;
                haHigh = Math.Max(maHigh.Result[index], Math.Max(haOpen[index], haClose[index]));
                haLow = Math.Min(maLow.Result[index], Math.Min(haOpen[index], haClose[index]));
                colorCandle = (haOpen[index] > haClose[index]) ? color_down : color_up;

                color_close = colorCandle;
                Chart.DrawStaticText("Label_Value", START_ROW + "\n\n\n" + "Value:", VerticalAlignment.Top, HorizontalAlignment.Left, Color.LightBlue);

                if (color_close == color_up)
                    Chart.DrawStaticText("value_data", START_ROW + "\n\n\n" + "\tUp", VerticalAlignment.Top, HorizontalAlignment.Left, color_up);
                if (color_close == color_down)
                    Chart.DrawStaticText("value_data", START_ROW + "\n\n\n" + "\tDown", VerticalAlignment.Top, HorizontalAlignment.Left, color_down);


                Chart.DrawRectangle("BarHA" + index, index, haOpen[index], index, haClose[index], colorCandle, 5, LineStyle.Solid);
                Chart.DrawRectangle("LineHA" + index, index, haHigh, index, haLow, colorCandle, 1, LineStyle.Solid);


                //Print("Count:\t" + count + "\t\tIndex:\t" + index + "\t\tColor:\t" + Color.ToString());
            }
            else if (!double.IsNaN(maOpen.Result[index]))
            {
                haOpen[index] = (maOpen.Result[index] + maClose.Result[index]) / 2;
                haClose[index] = (maOpen.Result[index] + maClose.Result[index] + maHigh.Result[index] + maLow.Result[index]) / 4;
                haHigh = maHigh.Result[index];
                haLow = maLow.Result[index];

                Chart.DrawStaticText("data", "INTO ELSE", VerticalAlignment.Top, HorizontalAlignment.Left, Color.Yellow);
            }
        }
    }
}

 


@andresort28

andresort28
10 Sep 2016, 07:19

Excellent news. Definitely I love cTrader & cAlgo and your product area. Anything I can collaborate to improve your platform, please feel free to contact me. I'm Software Engineer and I'll feel really good in order to improve the best algorithmic trading platform in the world.
@andresort28