How to code array ?

Created at 16 Feb 2016, 07:16
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!
HI

hiba7rain

Joined 20.07.2014

How to code array ?
16 Feb 2016, 07:16


Hi

just wanted your support to show how to code array to compare 3 or 4 past values

 

Thanks


@hiba7rain
Replies

Jiri
16 Feb 2016, 13:37 ( Updated at: 21 Dec 2023, 09:20 )

Hi, I hope this sample will help.

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ArraySample : Indicator
    {
        private double[] array;

        protected override void Initialize()
        {
            array = new double[4];

            array[0] = 23.6;
            array[1] = 38.2;
            array[2] = 50;
            array[3] = 61.8;

            foreach (var a in array)
                Print(a);
        }

        public override void Calculate(int index)
        {

        }
    }
}


@Jiri

hiba7rain
16 Feb 2016, 14:51 ( Updated at: 21 Dec 2023, 09:20 )

RE:

Thanks TMC

that's relay helpful

but how if i would like to use the array to compare between two values say for example the last two high points or the last low points 

 

Thanks

tmc. said:

Hi, I hope this sample will help.

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ArraySample : Indicator
    {
        private double[] array;

        protected override void Initialize()
        {
            array = new double[4];

            array[0] = 23.6;
            array[1] = 38.2;
            array[2] = 50;
            array[3] = 61.8;

            foreach (var a in array)
                Print(a);
        }

        public override void Calculate(int index)
        {

        }
    }
}

 


@hiba7rain

Jiri
16 Feb 2016, 15:26

You need to write the method finding highs and lows first, then you just compare them. However you don't need an array for it, it's better to use IndicatorDataSeries instead. I recommend to look at indicators that are published by others. Or hire someone to code the indicator you want. I'm also freelancer so feel free to contact me via email if you want my service.


@Jiri

hiba7rain
16 Feb 2016, 19:33

RE:

Thank you tmc

indicatorDaraSeries could you give simple example of it for compression between values

Thanks  

tmc. said:

You need to write the method finding highs and lows first, then you just compare them. However you don't need an array for it, it's better to use IndicatorDataSeries instead. I recommend to look at indicators that are published by others. Or hire someone to code the indicator you want. I'm also freelancer so feel free to contact me via email if you want my service.

 


@hiba7rain

hiba7rain
18 Feb 2016, 08:57

how to compare and create indicator data series for a customized indicator?


@hiba7rain

Spotware
24 Feb 2016, 14:46

Dear Trader,

You can compare the values of the IndicatorDataseries, but not the IndicatorDataseries with each other.

Please have a look at the following code snippet:

        public ExponentialMovingAverage ema;

        protected override void Initialize()
        {
            ema = Indicators.ExponentialMovingAverage(Source, Periods);
        }

        public override void Calculate(int index)
        {
            Result[index] = 1;

            if (Result[index] < ema.Result[index])
                Print("Successful");

        }

 


@Spotware