How to prefetch indicator history when Robot starts?

Created at 03 Oct 2018, 10:51
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!
diiptrade's avatar

diiptrade

Joined 17.11.2016

How to prefetch indicator history when Robot starts?
03 Oct 2018, 10:51


Hi!

Could you explain how to preload / prefetch indicator data (for example for ZigZag - https://ctrader.com/algos/indicators/show/1597) when cBot starts? Now I should whait for min 2 extremum points to draw Zigzag.

Thanks.


@diiptrade
Replies

PanagiotisCharalampous
03 Oct 2018, 11:03

Hi Roman,

Data is loaded in Indicators on their initialization. There is nothing special you need to do about it. 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(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        SimpleMovingAverage _sma;
        protected override void OnStart()
        {
            _sma = Indicators.SimpleMovingAverage(MarketSeries.Close, 14);
            for (int i = 14; i < _sma.Result.Count; i++)
            {
                Print("SMA: " + _sma.Result[i]);
            }
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

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

Best Regards,

Panagiotis


@PanagiotisCharalampous

diiptrade
03 Oct 2018, 15:56

Thanks!

Works!


@diiptrade

diiptrade
03 Oct 2018, 20:58

But, in real time it prefetch about 2k bars, in backtesting - about 120 bars... How to prefetch more?


@diiptrade

PanagiotisCharalampous
04 Oct 2018, 11:29

Hi Roman,

This is a limitation of backesting. A workaround is to start the backtesting earlier so that it can collect the necessary information.

Best Regards,

Panagiotis


@PanagiotisCharalampous