How to feed indicator data before cBot starts?

Created at 08 May 2019, 02:38
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!
jumpycalm's avatar

jumpycalm

Joined 28.03.2019

How to feed indicator data before cBot starts?
08 May 2019, 02:38


Hi Panagiotis,

Just quick question. All indicators will need to collect some data first before able to show on the chart. Moving average for example, if moving average is set to 200 periods, the indicator will not form untill 200 period passed. Which means, if I use this type of indicator, cBot will not open trade untill 200 candle bars have passed? Is there any way to feed cBot with data before cBot start, for example, if I use 200 moving average, I get the moving average data right after I start cBot? I have attached screenshot and code to explain this. This cBot will open buy position on each candle bar when price is above 200 moving average for demostration.

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        private MovingAverage movingAverage;

        protected override void OnStart()
        {
            movingAverage = Indicators.MovingAverage(MarketSeries.Close, 200, MovingAverageType.Simple);
        }

        protected override void OnBar()
        {
            if (Symbol.Bid > movingAverage.Result.LastValue)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, 1000, "NewcBot", 20, 20);
            }
        }

        protected override void OnStop()
        {
            foreach (var position in Positions)
            {
                if (position.SymbolName == SymbolName && position.Label == "NewcBot")
                    ClosePosition(position);
            }
        }
    }
}

 


@jumpycalm
Replies

PanagiotisCharalampous
08 May 2019, 17:08

Hi,

At the moment the formula to retrieve previous bars is the following

Backtesting start date - 100 * minutes in timeframe - 3 days

If your indicator needs more data than that, then you will have this issue. However we are looking into changing this behavior in the future.

Best Regards,

Panagiotis


@PanagiotisCharalampous

jumpycalm
08 May 2019, 17:28

RE:

Panagiotis Charalampous said:

Hi,

At the moment the formula to retrieve previous bars is the following

Backtesting start date - 100 * minutes in timeframe - 3 days

If your indicator needs more data than that, then you will have this issue. However we are looking into changing this behavior in the future.

Best Regards,

Panagiotis

Thank you Panagiotis for your prompt reply. I will just select earlier dates as a workaround for now.


@jumpycalm