why I got different results in Bot and indicator with the same code?

Created at 23 Mar 2019, 15:10
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!
PO

pozhy

Joined 03.04.2018

why I got different results in Bot and indicator with the same code?
23 Mar 2019, 15:10


I wonder why I got different numbers with the same code in robot and indicator?

this is a robot

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("3rd Timeframe", DefaultValue = "Hour")]
        public TimeFrame Timeframe1Br { get; set; }

        private MarketSeries BTseriesr;


        protected override void OnStart()
        {
            BTseriesr = MarketData.GetSeries(Symbol, Timeframe1Br);
        }

        protected override void OnTick()
        {

        }

        protected override void OnBar()
        {
            int indexr = MarketSeries.Close.Count - 1;
            Print(indexr + " " + MarketSeries.Close.Last(0) + " " + BTseriesr.Close[indexr]);

        }

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

this is an indicator

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {

        [Parameter("3rd Timeframe", DefaultValue = "Hour")]
        public TimeFrame Timeframe1B { get; set; }
        private MarketSeries BTseries;

        protected override void Initialize()
        {
            BTseries = MarketData.GetSeries(Symbol, Timeframe1B);
        }

        public override void Calculate(int index)
        {
            int idx1 = BTseries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
            ChartObjects.DrawText("Green Candles", index + " " + MarketSeries.Close.Last(0) + " " + BTseries.Close[index], StaticPosition.TopLeft, Colors.Green);

        }
    }
}


@pozhy
Replies

pozhy
26 Mar 2019, 03:13

any comment?


@pozhy

PanagiotisCharalampous
26 Mar 2019, 11:36

Hi pozhy,

This happens because the cBot is printing the value at 15:00 while the indicator prints the last value at 15:54.

Best Regards,

Panagiotis


@PanagiotisCharalampous