This indicator will evolve into a currency index. When the indicator runs on the cable chart there is a logical outcome. When run on other gbp pairs there are different outcomes. Whatever the currency chart that I have up I want to see my indicator appear
This indicator will evolve into a currency index. When the indicator runs on the cable chart there is a logical outcome. When run on other gbp pairs there are different outcomes. Whatever the currency chart that I have up I want to see my indicator appear
22 Nov 2019, 14:41
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class IndicatorEnquiry : Indicator
{
[Parameter("Time Frame", DefaultValue = "Daily")]
public TimeFrame Frame { get; set; }
[Parameter("Period", DefaultValue = 5)]
public int Bars { get; set; }
[Parameter("Index change period", DefaultValue = 5)]
public int xBars { get; set; }
[Parameter("Index change period long term", DefaultValue = 20)]
public int xBarsLongTerm { get; set; }
[Output("GBP index", LineColor = "Blue", Thickness = 2, PlotType = PlotType.Line, LineStyle = LineStyle.Dots)]
public IndicatorDataSeries GBPInd { get; set; }
private IndicatorDataSeries gbpusdDiff;
private IndicatorDataSeries totalNet;
protected override void Initialize()
{
gbpusdDiff = CreateDataSeries();
totalNet = CreateDataSeries();
}
public override void Calculate(int index)
{
var gbpusd = MarketData.GetSeries("GBPUSD", Frame);
//rates at 2 Jan 19 open
var gbpStart = 1.26;
//The gbp...Diff variables are %
gbpusdDiff[index] = ((gbpStart - gbpusd.Open[index]) / (gbpStart)) * 100;
totalNet[index] = (gbpusdDiff[index]);
GBPInd[index] = 100 - (totalNet[index] / 1);
GBPInd[index] = Math.Round(GBPInd[index], 3);
}
}
}
Replies
lucrum
22 Nov 2019, 15:01
RE:
Panagiotis Charalampous said:
Hi Nick,
Can you please explain to us what is the problem? What did you expect to happen and what happens instead?
Best Regards,
Panagiotis
When this code is run on a Daily GBPUSD chart the indicator at the most recent bar shows the net movement (%) from 2 January 2019, based on a start level of 100. This is correct. When I run this on a GBPJPY chart for instance, I get a different, and incorrect, outcome.
Nick
@lucrum
PanagiotisCharalampous
22 Nov 2019, 15:06
Hi Nick,
The symbol is hardcoded
var gbpusd = MarketData.GetSeries("GBPUSD", Frame);
Do you change that before running on GBPJPY?
Best Regards,
Panagiotis
@PanagiotisCharalampous
lucrum
22 Nov 2019, 16:26
RE:
Panagiotis Charalampous said:
Hi Nick,
The symbol is hardcoded
var gbpusd = MarketData.GetSeries("GBPUSD", Frame);
Do you change that before running on GBPJPY?
Best Regards,
Panagiotis
Dear Panagiotis
No. Irrespective of the daily chart on display I want to see only the GBPUSD calculation. In other words whilst on a GBPJPY chart I want to see the GBPUSD indicator in the window underneath.
Nick
@lucrum
Spotware
22 Nov 2019, 16:45
Hi Nick,
This happens because you are using the wrong index for the market series. Line 45 should change to the following
gbpusdDiff[index] = ((gbpStart - gbpusd.Open[gbpusd.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index])]) / (gbpStart)) * 100;
Best Regards,
Panagiotis
@Spotware
lucrum
22 Nov 2019, 16:56
RE:
Spotware said:
Hi Nick,
This happens because you are using the wrong index for the market series. Line 45 should change to the following
gbpusdDiff[index] = ((gbpStart - gbpusd.Open[gbpusd.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index])]) / (gbpStart)) * 100;
Best Regards,
Panagiotis
Dear Panagiotis
Thank you. Is there any cTrader documentation that fully explains how [index] works?
Nick
@lucrum
PanagiotisCharalampous
25 Nov 2019, 08:49
Hi Nick,
Index is just an array index, nothing more. Since MarketSeries from different timeframes might have values for different times on the same index, you need to map the index of one Market series to the other. This is achieved with the following method
gbpusd.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index])
In this case, the method gets the opening time at an index of the current MarketSeries and returns the index for the same time for the gbpusd market series.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
22 Nov 2019, 14:47
Hi Nick,
Can you please explain to us what is the problem? What did you expect to happen and what happens instead?
Best Regards,
Panagiotis
@PanagiotisCharalampous