Description
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 EURWeighedCurrencyIndex : Indicator
{
[Parameter("USD Weight", DefaultValue = 37.97)]
public double usdWeight { get; set; }
[Parameter("CAD Weight", DefaultValue = 3.54)]
public double cadWeight { get; set; }
[Parameter("GBP Weight", DefaultValue = 30.12)]
public double gbpWeight { get; set; }
[Parameter("AUD Weight", DefaultValue = 2.02)]
public double audWeight { get; set; }
[Parameter("JPY Weight", DefaultValue = 9.62)]
public double jpyWeight { get; set; }
[Parameter("CHF Weight", DefaultValue = 14.68)]
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("Average", LineColor = "White")]
public IndicatorDataSeries Result2 { get; set; }
[Output("EUR Index", LineColor = "Blue")]
public IndicatorDataSeries Result { get; set; }
public Bars Eurgbp;
public Bars Euraud;
public Bars Eurusd;
public Bars Eurcad;
public Bars Eurjpy;
public Bars Eurchf;
public Bars[] eur_Pairs = new Bars[6];
public string[] eur_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_Eurusd, f_Eurgbp, f_Eurjpy, f_Eurcad, f_Eurchf;
public double r_Euraud, r_Eurusd, r_Eurgbp, r_Eurjpy, r_Eurcad, r_Eurchf;
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_Eurgbp = 1 / 0.855;
f_Euraud = 1 / 1.59731;
f_Eurusd = 1 / 1.11558;
f_Eurcad = 1 / 1.44981;
f_Eurjpy = 1 / 121.3;
f_Eurchf = 1 / 1.085;
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
f_pairs[0] = f_Eurgbp;
f_pairs[1] = f_Euraud;
f_pairs[2] = f_Eurusd;
f_pairs[3] = f_Eurcad;
f_pairs[4] = f_Eurjpy;
f_pairs[5] = f_Eurchf;
r_pairs[0] = r_Eurgbp;
r_pairs[1] = r_Euraud;
r_pairs[2] = r_Eurusd;
r_pairs[3] = r_Eurcad;
r_pairs[4] = r_Eurjpy;
r_pairs[5] = r_Eurchf;
eur_Pairs[0] = Eurgbp;
eur_Pairs[1] = Euraud;
eur_Pairs[2] = Eurusd;
eur_Pairs[3] = Eurcad;
eur_Pairs[4] = Eurjpy;
eur_Pairs[5] = Eurchf;
l_weight[0] = gbpWeight;
l_weight[1] = audWeight;
l_weight[2] = usdWeight;
l_weight[3] = cadWeight;
l_weight[4] = jpyWeight;
l_weight[5] = chfWeight;
eur_Symbols[0] = "EURGBP";
eur_Symbols[1] = "EURAUD";
eur_Symbols[2] = "EURUSD";
eur_Symbols[3] = "EURCAD";
eur_Symbols[4] = "EURJPY";
eur_Symbols[5] = "EURCHF";
for (int i = 0; i < eur_Pairs.Length; i++)
{
eur_Pairs[i] = MarketData.GetBars(TF, eur_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 < eur_Pairs.Length; i++)
{
var index2 = GetIndexByTF(eur_Pairs[i], this.Bars, index);
if (i >= eur_Pairs.Length)
{
r_pairs[i] = ((1 / eur_Pairs[i].ClosePrices[index2]) / f_pairs[i]) * l_weight[i];
sum += r_pairs[i];
}
else
{
r_pairs[i] = (eur_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: EUR Weighed Currency Index.algo
- Rating: 0
- Installs: 1376
- Modified: 13/10/2021 09:55
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
No comments found.