Multi-timeframe robots/indicators

13 Dec 2018, 09:53Multi-timeframe robots/indicators#31
Panagiotis Charalampousposts: 2446since: 13 Jan 2017

Hi oliveira.phc,

A workaround is to get the timeframe as a parameter. See below

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter]
        public TimeFrame Timeframe { get; set; }

        protected override void OnStart()
        {
            var t = MarketData.GetSeries(Timeframe);
        }

        protected override void OnTick()
        {

        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis


Head of Community Management at cTrader
17 Dec 2018, 12:26RE:#32
oliveira.phcposts: 21since: 15 Nov 2018
Panagiotis Charalampous said:

Hi oliveira.phc,

A workaround is to get the timeframe as a parameter. See below

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter]
        public TimeFrame Timeframe { get; set; }

        protected override void OnStart()
        {
            var t = MarketData.GetSeries(Timeframe);
        }

        protected override void OnTick()
        {

        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis


Thank you for your readiness, Panagiotis. But, regarding the TimeFrame class, wouldn't it be necessary to update the API in order add properties of type Tick to it? The current API only have properties of type Time. https://ctrader.com/api/reference/timeframe I don't know if it is technically possible for cTrader to have multiple timeframe bots of type Tick, but it seems that it is doable for now. Kind regards, Paulo Oliveira
17 Dec 2018, 12:28RE: RE:#33
oliveira.phcposts: 21since: 15 Nov 2018
Sorry, I meant NOT doable for now.
17 Dec 2018, 12:36#34
Panagiotis Charalampousposts: 2446since: 13 Jan 2017

Hi oliveira.phc,

MarketData.GetSeries(Timeframe) should work fine for tick data, as long as you set the timeframe from the interface. We just need to update the Timeframe class. We will do this in one of he upcoming updates.

Best Regards,

Panagiotis


Head of Community Management at cTrader
17 Dec 2018, 12:58RE:#35
oliveira.phcposts: 21since: 15 Nov 2018
Thanks again.
02 Feb 2019, 02:37#36
shrumrposts: 11since: 03 Jan 2019

I have modified the indicator to just display daily 50/100/200 averages on the chart. 

Please have alook. I am very novice at this. 

 

I do wanted to ask, is it possible to disable this overlay value which appear on when mouse hovers over the MA lines?

 

 

Here is the full code:

 

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class MultiTF_MA2 : Indicator
    {

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

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

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

        private MarketSeries seriesdaily;

        private MovingAverage ma50;
        private MovingAverage ma100;
        private MovingAverage ma200;

        protected override void Initialize()
        {
            seriesdaily = MarketData.GetSeries(TimeFrame.Daily);
            ma50 = Indicators.MovingAverage(seriesdaily.Close, 50, MovingAverageType.Simple);
            ma100 = Indicators.MovingAverage(seriesdaily.Close, 100, MovingAverageType.Simple);
            ma200 = Indicators.MovingAverage(seriesdaily.Close, 200, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {

            var index50 = GetIndexByDate(seriesdaily, MarketSeries.OpenTime[index]);
            if (index50 != -1)
                MA50[index] = ma50.Result[index50];

            var index100 = GetIndexByDate(seriesdaily, MarketSeries.OpenTime[index]);
            if (index100 != -1)
                MA100[index] = ma100.Result[index100];

            var index200 = GetIndexByDate(seriesdaily, MarketSeries.OpenTime[index]);
            if (index200 != -1)
                MA200[index] = ma200.Result[index200];

        }


        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i > 0; i--)
            {
                if (time == series.OpenTime[i])
                    return i;
            }
            return -1;
        }
    }
}

 

04 Feb 2019, 10:22#37
Panagiotis Charalampousposts: 2446since: 13 Jan 2017

Hi shrumr,

At the moment this is not possible.

Best Regards,

Panagiotis


Head of Community Management at cTrader
04 Feb 2019, 10:40RE:#38
Vitali Gajdabrusposts: 30since: 20 Aug 2015

 

Hi oliveira.phc,

MarketData.GetSeries(Timeframe) should work fine for tick data, as long as you set the timeframe from the interface. We just need to update the Timeframe class. We will do this in one of he upcoming updates.

Have you updated the Timeframe class?

MarketData.GetSeries(Timeframe.tick)

How can i do this?

07 Mar 2019, 17:33RE:#39
ctid1032297posts: 1since: 07 Mar 2019

cAlgo_Development said:

We added new functionality to cAlgo - the ability for robots and indicators to retrieve OHLCV data for multiple timeframes. This can be done using the MarketData.GetSeries method:

MarketSeries m5series = MarketData.GetSeries(TimeFrame.Minute5);

We recommend to call the GetSeries method in the Robot.OnStart() or the Indicator.Initialize() methods.

When the series for a specified timeframe is received, you can access the series values or build an indicator based on that series:

private MarketSeries m10;
private MovingAverage ma;

protected override void OnStart()
{
    m10 = MarketData.GetSeries(TimeFrame.Minute10);
    ma = Indicators.SimpleMovingAverage(m10.High, 14);
}

The new version of our Demo cTrader and cAlgo is released and can be downloaded from www.spotware.com

Update: Backtesting of Multi-timeframe robots is supported now.

Is it possible to call this but not for one of the time based timeframes? I.e Range bars?

07 Mar 2019, 17:59#40
Panagiotis Charalampousposts: 2446since: 13 Jan 2017

Hi ctid1032297,

Thanks for posting in our forum. Renko and Range bars are not available yet.

Best Regards,

Panagiotis


Head of Community Management at cTrader