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 USDWeighedCurrencyIndex : Indicator
{
[Parameter("EUR Weight", DefaultValue = 39.59)]
public double eurWeight { get; set; }
[Parameter("CAD Weight", DefaultValue = 27.966)]
public double cadWeight { get; set; }
[Parameter("AUD Weight", DefaultValue = 9.915)]
public double audWeight { get; set; }
[Parameter("GBP Weight", DefaultValue = 11.087)]
public double gbpWeight { get; set; }
[Parameter("JPY Weight", DefaultValue = 13.105)]
public double jpyWeight { get; set; }
[Parameter("CHF Weight", DefaultValue = 5.337)]
public double chfWeight { get; set; }
[Parameter("Line TimeFrame", DefaultValue = 0)]
public TimeFrame TF { get; set; }
[Output("USD Index", LineColor = "Green")]
public IndicatorDataSeries Result { get; set; }
public Bars Eurusd;
public Bars Gbpusd;
public Bars Audusd;
public Bars Usdcad;
public Bars Usdjpy;
public Bars Usdchf;
public Bars[] usd_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_eurusd, f_gbpusd, f_audusd, f_usdjpy, f_usdcad, f_usdchf;
public double r_eurusd, r_gbpusd, r_audusd, r_usdjpy, r_usdcad, r_usdchf;
protected override void Initialize()
{
// Reference Exhchange Rates from close prices of 02/02/2020
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
f_eurusd = 1 / (1.11725);
f_gbpusd = 1 / (1.31353);
f_audusd = 1 / (0.69894);
f_usdcad = 1.29866;
f_usdjpy = 108.555;
f_usdchf = 0.97115;
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
f_pairs[0] = f_eurusd;
f_pairs[1] = f_gbpusd;
f_pairs[2] = f_audusd;
f_pairs[3] = f_usdcad;
f_pairs[4] = f_usdjpy;
f_pairs[5] = f_usdchf;
r_pairs[0] = r_eurusd;
r_pairs[1] = r_gbpusd;
r_pairs[2] = r_audusd;
r_pairs[3] = r_usdcad;
r_pairs[4] = r_usdjpy;
r_pairs[5] = r_usdchf;
usd_Pairs[0] = Eurusd;
usd_Pairs[1] = Gbpusd;
usd_Pairs[2] = Audusd;
usd_Pairs[3] = Usdcad;
usd_Pairs[4] = Usdjpy;
usd_Pairs[5] = Usdchf;
l_weight[0] = eurWeight;
l_weight[1] = gbpWeight;
l_weight[2] = audWeight;
l_weight[3] = cadWeight;
l_weight[4] = jpyWeight;
l_weight[5] = chfWeight;
usd_symbols[0] = "EURUSD";
usd_symbols[1] = "GBPUSD";
usd_symbols[2] = "AUDUSD";
usd_symbols[3] = "USDCAD";
usd_symbols[4] = "USDJPY";
usd_symbols[5] = "USDCHF";
for (int i = 0; i < usd_Pairs.Length; i++)
{
usd_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 < usd_Pairs.Length; i++)
{
var index2 = GetIndexByTF(usd_Pairs[i], this.Bars, index);
if (i <= 2)
{
r_pairs[i] = ((1 / usd_Pairs[i].ClosePrices[index2]) / f_pairs[i]) * l_weight[i];
sum += r_pairs[i];
}
else
{
r_pairs[i] = (usd_Pairs[i].ClosePrices[index2] / f_pairs[i]) * l_weight[i];
sum += r_pairs[i];
}
}
Result[index] = sum;
}
int GetIndexByTF(Bars B1, Bars B2, int index)
{
var index2 = B1.OpenTimes.GetIndexByTime(B2.OpenTimes[index]);
return index2;
}
}
}
AN
andrey.thales18
Joined on 31.08.2020
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: USD Weighed Currency Index.algo
- Rating: 5
- Installs: 1214
- Modified: 13/10/2021 09:54
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.
Love this indicator ! and the USD one as well!