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 JPYXWeighedCurrencyIndex : Indicator
{
[Parameter("USD Weight", DefaultValue = 74.76)]
public double usdWeight { get; set; }
[Parameter("EUR Weight", DefaultValue = 19.03)]
public double eurWeight { get; set; }
[Parameter("GBP Weight", DefaultValue = 3.16)]
public double gbpWeight { get; set; }
[Parameter("AUD Weight", DefaultValue = 1.58)]
public double audWeight { get; set; }
[Parameter("JPY Weight", DefaultValue = 7.06)]
public double jpyWeight { get; set; }
[Parameter("CHF Weight", DefaultValue = 1.45)]
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("CAD Index", LineColor = "Magenta")]
public IndicatorDataSeries Result { get; set; }
[Output("Average", LineColor = "White")]
public IndicatorDataSeries Result2 { get; set; }
// chf, jpy gbp, aud, usd, eur
public Bars Cadchf;
public Bars Cadjpy;
public Bars Gbpcad;
public Bars Audcad;
public Bars Usdcad;
public Bars Eurcad;
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_Audcad, f_Usdcad, f_Gbpcad, f_Eurcad, f_Cadjpy, f_Cadchf;
public double r_Audcad, r_Usdcad, r_Gbpcad, r_Eurcad, r_Cadjpy, r_Cadchf;
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_Gbpcad = 1.70549;
f_Audcad = 0.90736;
f_Usdcad = 1.2979;
f_Cadjpy = 83.614;
f_Eurcad = 121.3;
f_Cadchf = 0.74789;
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// chf, jpy gbp, aud, usd, eur
f_pairs[0] = f_Cadchf;
f_pairs[1] = f_Cadjpy;
f_pairs[2] = f_Gbpcad;
f_pairs[3] = f_Audcad;
f_pairs[4] = f_Usdcad;
f_pairs[5] = f_Eurcad;
// gbp, aud, usd, cad, eur, chf
r_pairs[0] = r_Cadchf;
;
r_pairs[1] = r_Cadjpy;
r_pairs[2] = r_Gbpcad;
r_pairs[3] = r_Audcad;
r_pairs[4] = r_Usdcad;
r_pairs[5] = r_Eurcad;
eur_Pairs[0] = Cadchf;
eur_Pairs[1] = Cadjpy;
eur_Pairs[2] = Gbpcad;
eur_Pairs[3] = Audcad;
eur_Pairs[4] = Usdcad;
eur_Pairs[5] = Eurcad;
l_weight[0] = chfWeight;
l_weight[1] = jpyWeight;
l_weight[2] = gbpWeight;
l_weight[3] = audWeight;
l_weight[4] = usdWeight;
l_weight[5] = eurWeight;
eur_Symbols[0] = "CADCHF";
eur_Symbols[1] = "CADJPY";
eur_Symbols[2] = "GBPCAD";
eur_Symbols[3] = "AUDCAD";
eur_Symbols[4] = "USDCAD";
eur_Symbols[5] = "EURCAD";
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 > 2)
{
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: CAD CURRENCY INDEX.algo
- Rating: 0
- Installs: 1392
- 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.