MarketData other symbol, using index on 2nd symbol gives other opentime

Created at 14 Feb 2014, 00:52
ST

StormeNet

Joined 13.12.2013

MarketData other symbol, using index on 2nd symbol gives other opentime
14 Feb 2014, 00:52


Hi,

I'm trying to create a overlay with other chart data, however, when I try to access the other symbol data the open/close time doesn't seem to match. On top of that when trying to implement an offset it was clear to me that the open/close time can't be fixed with an offset because it doesn't scale:

I log each time the current marketseries opentime and the 2nd symbol marketseries opentime with the same index given in the calculate method and I receive this logging:

13/02/2014 23:47:07.174 | 21/10/2012 22:00:00 - 21/10/2012 23:00:00
13/02/2014 23:47:07.174 | 21/10/2012 23:00:00 - 22/10/2012 0:00:00
*snip * Already 1hr difference here
13/02/2014 23:47:07.720 | 28/05/2013 1:00:00 - 23/05/2013 6:00:00
13/02/2014 23:47:07.720 | 28/05/2013 2:00:00 - 23/05/2013 7:00:00
*snip* several days difference
13/02/2014 23:48:12.991 | 13/02/2014 22:00:00 - 27/01/2014 17:00:00
13/02/2014 23:48:17.109 | 13/02/2014 22:00:00 - 27/01/2014 17:00:00
 

Is there a easy way to have them aligned or do I need to write my own alignment function for this?

Thanks

Here is my code:

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class MultiSymbolMA : Indicator
    {
        private MarketSeries series2, series3;
        private Symbol symbol2, symbol3;

        [Parameter(DefaultValue = "EURCHF")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = "EURCAD")]
        public string Symbol3 { get; set; }

        [Output("Symbol2Trace", Color = Colors.LightSkyBlue)]
        public IndicatorDataSeries Symbol2Trace { get; set; }

        [Parameter(DefaultValue = 1)]
        public double Symbol2Multiplier { get; set; }

        [Parameter(DefaultValue = 0)]
        public double Symbol2SerieOffset { get; set; }

        [Output("Symbol3Trace", Color = Colors.Black)]
        public IndicatorDataSeries Symbol3Trace { get; set; }

        private MovingAverage ma;

        protected override void Initialize()
        {
            ma = Indicators.MovingAverage(MarketSeries.Close, 200, MovingAverageType.Simple);
            if (Symbol2 != "")
            {
                symbol2 = MarketData.GetSymbol(Symbol2);
                series2 = MarketData.GetSeries(symbol2, TimeFrame);
            }

            if (Symbol3 != "")
            {
                symbol3 = MarketData.GetSymbol(Symbol3);
                series3 = MarketData.GetSeries(symbol3, TimeFrame);
            }
        }

        public override void Calculate(int index)
        {
            DrawSeries(series2, index, Symbol2Trace, 0);
        }

        public void DrawSeries(MarketSeries serie, int index, IndicatorDataSeries indicator, double offset)
        {
            Print("{0} - {1}", MarketSeries.OpenTime[index], serie.OpenTime[index]);
            if (serie != null)
            {
                double pipdiff = serie.Close[index + (int)Symbol2SerieOffset] - serie.Close[index + (int)Symbol2SerieOffset - 1];
                indicator[index] = ma.Result[index] + pipdiff * Symbol2Multiplier;
            }
        }
    }
}

 


@StormeNet
Replies

StormeNet
14 Feb 2014, 00:54

Oh, those results were using EURHUF as main chart and EURUSD as 2nd sybmol on the 1hr timeframe.


@StormeNet

Spotware
14 Feb 2014, 17:03

Different symbols could have different sessions. If you want to match series from different symbols you need to use GetIndexByExactTime method. You can find an example there: /forum/whats-new/1463


@Spotware