Category Other  Published on 18/12/2020

AUD Weighted Currency Index


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


using System.Collections.Generic;



namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AUDWeightedCurrencyIndex : Indicator
    {

        [Parameter("USD Weight", DefaultValue = 26.12)]
        public double usdWeight { get; set; }

        [Parameter("CAD Weight", DefaultValue = 2.86)]
        public double cadWeight { get; set; }

        [Parameter("GBP Weight", DefaultValue = 10.56)]
        public double gbpWeight { get; set; }

        [Parameter("EUR Weight", DefaultValue = 25.57)]
        public double eurWeight { get; set; }

        [Parameter("JPY Weight", DefaultValue = 30.55)]
        public double jpyWeight { get; set; }

        [Parameter("CHF Weight", DefaultValue = 2.42)]
        public double chfWeight { get; set; }

        [Parameter("Line TimeFrame", DefaultValue = 0)]
        public TimeFrame TF { get; set; }

        [Parameter("MA Period", DefaultValue = 20)]
        public int Period { get; set; }


        [Output("Aud Index", LineColor = "Yellow")]

        public IndicatorDataSeries Result { get; set; }

        [Output("Average", LineColor = "Yellow", LineStyle = LineStyle.LinesDots)]

        public IndicatorDataSeries Result2 { get; set; }



        public Bars Eurgbp;
        public Bars Gbpaud;
        public Bars Audusd;
        public Bars Gbpcad;
        public Bars Gbpjpy;
        public Bars Gbpchf;


        public Bars[] aud_Pairs = new Bars[6];

        public string[] usd_symbols = new string[6];

        public double[] weights = new double[6];


        public double[] f_pairs = new double[6];

        public double[] r_pairs = new double[6];

        public double[] l_weight = new double[6];


        public double f_Euraud, f_Audusd, f_Gbpaud, f_Audjpy, f_Audcad, f_Audchf;

        public double r_Euraud, r_Audusd, r_Gbpaud, r_Audjpy, r_Audcad, r_Audchf;


        private IndicatorDataSeries averagebff;

        private IndicatorDataSeries temp;

        private MovingAverage average;


        protected override void Initialize()
        {

            // Reference Exhchange Rates from close prices of 02/01/2020
            //-------------------------------------------------------------------------------------------------------------------------------------------------------------


            temp = CreateDataSeries();

            averagebff = CreateDataSeries();

            average = Indicators.MovingAverage(averagebff, Period, MovingAverageType.Exponential);


            f_Euraud = 1 / 1.59839;
            f_Gbpaud = 1 / 1.87927;
            f_Audusd = 0.69894;

            f_Audcad = 0.90736;
            f_Audjpy = 75.879;
            f_Audchf = 0.6787;
            //-------------------------------------------------------------------------------------------------------------------------------------------------------------

            f_pairs[0] = f_Euraud;
            f_pairs[1] = f_Gbpaud;
            f_pairs[2] = f_Audusd;
            f_pairs[3] = f_Audcad;
            f_pairs[4] = f_Audjpy;
            f_pairs[5] = f_Audchf;

            r_pairs[0] = r_Euraud;
            r_pairs[1] = r_Gbpaud;
            r_pairs[2] = r_Audusd;
            r_pairs[3] = r_Audcad;
            r_pairs[4] = r_Audjpy;
            r_pairs[5] = r_Audchf;

            aud_Pairs[0] = Eurgbp;
            aud_Pairs[1] = Gbpaud;
            aud_Pairs[2] = Audusd;
            aud_Pairs[3] = Gbpcad;
            aud_Pairs[4] = Gbpjpy;
            aud_Pairs[5] = Gbpchf;

            l_weight[0] = eurWeight;
            l_weight[1] = gbpWeight;
            l_weight[2] = usdWeight;
            l_weight[3] = cadWeight;
            l_weight[4] = jpyWeight;
            l_weight[5] = chfWeight;

            usd_symbols[0] = "EURAUD";
            usd_symbols[1] = "GBPAUD";
            usd_symbols[2] = "AUDUSD";
            usd_symbols[3] = "AUDCAD";
            usd_symbols[4] = "AUDJPY";
            usd_symbols[5] = "AUDCHF";



            for (int i = 0; i < aud_Pairs.Length; i++)
            {
                aud_Pairs[i] = MarketData.GetBars(TF, usd_symbols[i]);
            }

        }

        public override void Calculate(int index)
        {
            // Setting the reference quote


            //var index2 = GetIndexByTF(BarSeries[i], this.Bars, index);

            double sum = 0;



            for (int i = 0; i < aud_Pairs.Length; i++)
            {
                var index2 = GetIndexByTF(aud_Pairs[i], this.Bars, index);

                if (i < 2)
                {

                    r_pairs[i] = ((1 / aud_Pairs[i].ClosePrices[index2]) / f_pairs[i]) * l_weight[i];

                    sum += r_pairs[i];
                }

                else
                {

                    r_pairs[i] = (aud_Pairs[i].ClosePrices[index2] / f_pairs[i]) * l_weight[i];

                    sum += r_pairs[i];
                }

            }


            averagebff[index] = sum;

            Result[index] = sum;

            if (double.IsNaN(average.Result[index]) == false)
            {
                Result2[index] = average.Result[index];
            }

        }

        int GetIndexByTF(Bars B1, Bars B2, int index)
        {
            var index2 = B1.OpenTimes.GetIndexByTime(B2.OpenTimes[index]);
            return index2;
        }

    }
}


AN
andurei

Joined on 30.09.2020

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: AUD Weighed Currency Indexes.algo
  • Rating: 0
  • Installs: 1275
  • Modified: 13/10/2021 09:55
Comments
Log in to add a comment.
No comments found.