Multi-currency indicator bug. No data in last few bars.
Multi-currency indicator bug. No data in last few bars.
17 Dec 2013, 20:06
Hi all,
I have developed a multi-currency indicator, but it looks like the last few bars are incorrect as the data is always missing from a few of the currencies. I have constructed a sample to demonstrate the issue (below).
If you run the indicator on EURUSD H1, you will notice that for the last few bars there is no line in the indicator. This is because the MarketSeries for some of the other currencies return NaN.
Could you please help?
Thanks!
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC)] public class Test : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } MarketSeries series1; MarketSeries series2; MarketSeries series3; protected override void Initialize() { series1 = MarketData.GetSeries("USDJPY", this.TimeFrame); series2 = MarketData.GetSeries("AUDUSD", this.TimeFrame); series3 = MarketData.GetSeries("USDCAD", this.TimeFrame); } public override void Calculate(int index) { Result[index] = series1.Close[index] + series2.Close[index] + series3.Close[index]; if (double.IsNaN(series1.Close[index])) Print("Nan: Series 1"); if (double.IsNaN(series2.Close[index])) Print("Nan: Series 2"); if (double.IsNaN(series3.Close[index])) Print("Nan: Series 3"); } } }
Replies
amiscell
18 Dec 2013, 03:01
Solved!
Thanks, Jeex! This is fabulous, problem solved!
I am posting the working code for the sample for others to see. Needless to say, the sample doesn't make sense as it's adding up currency, it's just meant to show how to make this work :)
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC)] public class Test : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } MarketSeries series1; MarketSeries series2; MarketSeries series3; protected override void Initialize() { series1 = MarketData.GetSeries("USDJPY", this.TimeFrame); series2 = MarketData.GetSeries("AUDUSD", this.TimeFrame); series3 = MarketData.GetSeries("USDCAD", this.TimeFrame); } public override void Calculate(int index) { int index1 = series1.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]); int index2 = series2.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]); int index3 = series3.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]); Result[index] = series1.Close[index1] + series2.Close[index2] + series3.Close[index3]; if (double.IsNaN(series1.Close[index1])) Print("Nan: Series 1"); if (double.IsNaN(series2.Close[index2])) Print("Nan: Series 2"); if (double.IsNaN(series3.Close[index3])) Print("Nan: Series 3"); } } }
@amiscell
crank
27 Dec 2014, 16:29
RE: Solved!
How would I use the Stochastic Oscillator %K for two different symbols in indicators or robots?
Thanks, Jeex! This is fabulous, problem solved!
I am posting the working code for the sample for others to see. Needless to say, the sample doesn't make sense as it's adding up currency, it's just meant to show how to make this work :)
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC)] public class Test : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } MarketSeries series1; MarketSeries series2; MarketSeries series3; protected override void Initialize() { series1 = MarketData.GetSeries("USDJPY", this.TimeFrame); series2 = MarketData.GetSeries("AUDUSD", this.TimeFrame); series3 = MarketData.GetSeries("USDCAD", this.TimeFrame); } public override void Calculate(int index) { int index1 = series1.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]); int index2 = series2.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]); int index3 = series3.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]); Result[index] = series1.Close[index1] + series2.Close[index2] + series3.Close[index3]; if (double.IsNaN(series1.Close[index1])) Print("Nan: Series 1"); if (double.IsNaN(series2.Close[index2])) Print("Nan: Series 2"); if (double.IsNaN(series3.Close[index3])) Print("Nan: Series 3"); } } }
@crank
jeex
17 Dec 2013, 20:38
Index is not similar
I ran into the same mistake. Problem is that you have to make a different index for each series:
Here you'll find what you need: /forum/calgo-support/2105?page=1#4 and there are more threads about this. Look for multi timeframe and multi symbol.
@jeex