issue on retrieving marketseries for other symbols

Created at 10 Nov 2018, 13:27
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CY

cysecsbin.01

Joined 10.11.2018 Blocked

issue on retrieving marketseries for other symbols
10 Nov 2018, 13:27


i was trying to code a heatmap, but i had an issue with inconsistent marketseries.

i'll post the example code with pics for reference.

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 MarketSeries_Test : Indicator
    {

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private MarketSeries EURUSD;

        protected override void Initialize()
        {
            Symbol eurusd = MarketData.GetSymbol("EURUSD");
            EURUSD = MarketData.GetSeries(eurusd, TimeFrame.Hour);
        }

        public override void Calculate(int index)
        {
            Result[index] = EURUSD.Close[index];
        }
    }
}

this code, when used on EURUSD chart, produces a correct representation of the close price for this symbol, as shown here

but when the indicator is used on a different chart than the series requested, for example, CADJPY, a different output is returned:

how is this possible? the marketdata.getSeries method should always return the same series, in this case EURUSD Closing price from the 1H chart, regardless of the chart the indicator is applied on.

I followed the instructions posted here https://ctrader.com/forum/whats-new/1531 to initialize the series.

any help would be appreciated.

Thanks in advance


Replies

PanagiotisCharalampous
12 Nov 2018, 12:32

Hi cysecsbin.01

Thanks for posting in our forum. See the below the correct way to implement this.

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 MarketSeries_Test : Indicator
    {
 
        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }
 
        private MarketSeries EURUSD;
 
        protected override void Initialize()
        {
            Symbol eurusd = MarketData.GetSymbol("EURUSD");
            EURUSD = MarketData.GetSeries(eurusd, TimeFrame.Hour);
        }
 
        public override void Calculate(int index)
        {
            Result[index] = EURUSD.Close[EURUSD.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index])];
        }
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous