BA
Help for a loop
26 Mar 2016, 19:49
Hi everyone,
Can somebody help me to loop the last line of the code? I would like to chose, with a parameter, how many bars the indicator use to loop that line, and not having to do it by "hand".
Thanks a lot for your help,
B.
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
public class CorrelationIndex : Indicator
{
[Output("Index curr 1", Color = Colors.Red)]
public IndicatorDataSeries Curr1 { get; set; }
[Output("Index curr 2", Color = Colors.Blue)]
public IndicatorDataSeries Curr2 { get; set; }
[Parameter(DefaultValue = 1)]
public int Period { get; set; }
[Parameter(DefaultValue = 60)]
public int Delay { get; set; }
[Parameter("Source EURUSD")]
public DataSeries Source1 { get; set; }
private PriceROC priceROCEURUSD;
private IndicatorDataSeries value1;
protected override void Initialize()
{
priceROCEURUSD = Indicators.PriceROC(Source1, Period);
value1 = CreateDataSeries();
}
public override void Calculate(int index)
{
value1[index] = (priceROCEURUSD.Result[index]);
Curr1[index] = (100 * (1 + value1[index]) * (1 + value1[index - 1]) * (1 + value1[index - 2]) * (1 + value1[index - 3]) * (1 + value1[index - 4]) * (1 + value1[index - 5]) * (1 + value1[index - 6]) * (1 + value1[index - 7]) * (1 + value1[index - 8]) * (1 + value1[index - 9]) * (1 + value1[index - 10]) * (1 + value1[index - 11]) * (1 + value1[index - 12]));
}
}
}
Replies
benjamintermonia
27 Mar 2016, 23:04
@benjamintermonia

whis.gg
26 Mar 2016, 22:28
Hey, I haven't tested but it should work.
double result = 0; for (int i = 0; i < Period; i++) { if (i == 0) { result = (1 + value1[index]); } else } result *= (1 + value1[index - i]) } } Curr1[index] = 100 * result;@whis.gg