Issue: EMA values from bot don't match EMA values for previous bars on renko chart

Created at 18 Aug 2023, 13:06
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!
FI

firemyst

Joined 26.03.2019

Issue: EMA values from bot don't match EMA values for previous bars on renko chart
18 Aug 2023, 13:06


Hi all:

I have an issue with cBots where on Renko charts, the EMA values obtained from a cBot don't match the EMA values for previous bars displayed on the chart.

See screen capture below. GER40 on Renko 5 chart:

Here is the sample code to reproduce the issue:

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

    public class BugBot : Robot
    {
        private MovingAverage ma1;
        private MovingAverage ma2;

        protected override void OnStart()
        {
            ma1 = Indicators.MovingAverage(Bars.ClosePrices, 4, MovingAverageType.Exponential);
            ma2 = Indicators.MovingAverage(Bars.ClosePrices, 8, MovingAverageType.Exponential);
            Print("Put an EMA 4 and EMA 8 indicator on a GER40 Renko 5 chart. ");
        }

        protected override void OnTick()
        {
        }

        protected override void OnBar()
        {
            double ma1LastResult = Math.Round(ma1.Result.Last(1), Symbol.Digits);
            double ma2LastResult = Math.Round(ma2.Result.Last(1), Symbol.Digits);
            Print("Last Bar Open Time {0}, MA1 Last Value {1}, MA2 Last Value {2}", Bars.OpenTimes.Last(1), ma1LastResult, ma2LastResult);
            Print("Now compare these values against what's shown on the actual cTrader chart for the two EMA values for the last bar");
            ChartStaticText cst = Chart.DrawStaticText("cst", "Bar Open Time: " + Bars.OpenTimes.Last(1) + Environment.NewLine + "4 EMA: " + ma1LastResult + Environment.NewLine + "8 EMA: " + ma2LastResult + Environment.NewLine, VerticalAlignment.Top, HorizontalAlignment.Right, Color.White);
            cst.IsInteractive = true;
        }

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

    }
}

 

Any ideas?

Is there an issue with cTrader charts on Renko timeframes?


@firemyst
Replies

firemyst
22 Aug 2023, 11:27 ( Updated at: 21 Dec 2023, 09:23 )

@Spotware, any ideas or updates? Able to reproduce?

I tried again today on the Ger40 Renko 5 chart.

I changed the above code from:

double ma1LastResult = Math.Round(ma1.Result.Last(1), Symbol.Digits);
            double ma2LastResult = Math.Round(ma2.Result.Last(1), Symbol.Digits);

to:

double ma1LastResult = Math.Round(ma1.Result.Last(1), 2);
            double ma2LastResult = Math.Round(ma2.Result.Last(1), 2);

and still get values that differ between the .Last(1) outputs and the Market Snapshot tool today as shown below:

Times are UTC + 8

 

I would expect the output from ma1.Result.Last(1) to be the same, or at least within mathematical rounding distance of the displayed value on the chart. 

In the case of the 4 EMA, calgo returns a value that differs by 20% of a pip. This difference certainly shouldn't be acceptable.

Thank you.


@firemyst