Issues with data returned when referencing other symbols
Issues with data returned when referencing other symbols
26 Apr 2019, 10:42
Hello cTDN Community,
I was hoping someone might be kind enough to help me resolve an issue I'm having when calling the prices from another symbol. The indicator returns the close price of another symbol for the given chart index. I've pasted the indicator code below as well as screenshots.
The issue:
- When the close prices of e.g. EURHKD are called by the indicator on the EURHKD chart, the indicator works as expected and essentially duplicates the chart.
- When the close prices of e.g. EURHKD are called by the indicator on another chart e.g. USDHKD, the indicator returns a completely different dataseries.
- When the prices are called at different timeframe, the dataseries looks different once again.
- I've tried this with different symbols with similar results.
I thought perhaps I might have made a mistake with "timezone," "timeframe" or "index" but I can't seem to make sense of what's going on.
I also thought perhaps it might be an issue with the symbols' indexes not matching, but in the example you'll see the indicator shows that EURHKD was once at above 12.0, which it hasn't been since 2008.
Any help would be appreicated!
----------
Charts:
- LHS: EURHKD
- Top: EURHKD Chart
- Bottom: Indicator of EURHKD close prices
- RHS: USDHKD
- Top: USDHKD Chart
- Bottom: Indicator of EURHKD close prices
- Timeframes: 1 Month; 1 Day; 1 Minute
You'll notice the LHS chart & indicator match in every case; however the indicators from LHS to RHS don't when I'd expect that they should.
using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; namespace cAlgo.Indicators { [Indicator("P_C_Source", IsOverlay = false, ScalePrecision = 5)] public class P_C_Source : Indicator { [Output("P_C_Source", LineColor = "Red", LineStyle = LineStyle.Solid)] public IndicatorDataSeries Result { get; set; } [Parameter()] public string SymbolCode { get; set; } private MarketSeries PC_Symbol_series; private Symbol PC_Symbol; protected override void Initialize() { PC_Symbol = MarketData.GetSymbol(SymbolCode); PC_Symbol_series = MarketData.GetSeries(PC_Symbol, TimeFrame); } public override void Calculate(int index) { Result[index] = PC_Symbol_series.Close[index]; } } }
Monthly timeframe
Daily timeframe
Minute timeframe
Replies
JohnK
30 Apr 2019, 15:02
RE:
Panagiotis Charalampous said:
Hi John,
You need to make sure you are using corresponing indices. See below the correct way to implement it
using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; namespace cAlgo.Indicators { [Indicator("P_C_Source", IsOverlay = false, ScalePrecision = 5)] public class P_C_Source : Indicator { [Output("P_C_Source", LineColor = "Red", LineStyle = LineStyle.Solid)] public IndicatorDataSeries Result { get; set; } [Parameter()] public string SymbolCode { get; set; } private MarketSeries PC_Symbol_series; private Symbol PC_Symbol; protected override void Initialize() { PC_Symbol = MarketData.GetSymbol(SymbolCode); PC_Symbol_series = MarketData.GetSeries(PC_Symbol, TimeFrame); } public override void Calculate(int index) { Result[index] = PC_Symbol_series.Close[PC_Symbol_series.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index])]; } } }Best Regards,
Panagiotis
Hi Panagiotis,
The indicator now appears to be functioning as intended. Very much appreciate the support!
Thank you,
John
@JohnK
PanagiotisCharalampous
30 Apr 2019, 12:34
Hi John,
You need to make sure you are using corresponing indices. See below the correct way to implement it
Best Regards,
Panagiotis
@PanagiotisCharalampous