Custom RSI indicator problem

Created at 22 Jun 2018, 18:32
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!
MH

MHBB

Joined 30.10.2015

Custom RSI indicator problem
22 Jun 2018, 18:32


Using the formula to calculate Relative Strength Index I programmed my own custom indicator, and tested it using backtesting data, I get the same values

But when I run the indicator live, for example using tick dataseries I get different values

Do live and backtesting calculate/store data differently?

 


@MHBB
Replies

MHBB
23 Jun 2018, 02:25

Should have said, tested my custom RSI against the inbuilt RSI, in backtesting I get the same results, but in live I get different values


@MHBB

PanagiotisCharalampous
25 Jun 2018, 10:10 ( Updated at: 29 Aug 2022, 08:35 )

Hi Simon,

In order to help you, we will need more information. Please provide us with the following

  1. The custom indicator
  2. The exact steps you use to check the indicators (Broker, Symbol, Backtesting paramaters etc)
  3. Any screenshots that can help us understand the problem.

Best Regards,

Panagiotis


@PanagiotisCharalampous

MHBB
25 Jun 2018, 17:06

Hi Panagiotis, thanks for the reply

Now I understand the problem, I was calculating my custom RSI in a cbot and not an indicator, so the data was different

Can you explain to me why Indicators Calculate on every index, example

244031
244032
244033
244034
244035
244036
244037
244038
244039
244040
244041
244042

.....

Code example

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class indexTest : Indicator
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        StreamWriter log = new StreamWriter("c:/testIndicator.txt", true, Encoding.ASCII, 0x10000);

        protected override void Initialize()
        {
        }
        public override void Calculate(int index)
        {
            log.WriteLine(index);
            log.Flush();
        }

        public void Close()
        {
            log.Close();
        }
    }
}

But cBots don't calculate on every index, for example when I log every tick I get this:

244031
244039
244041
244043
244045

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private StreamWriter log = new StreamWriter("c:/indexTest.txt", true, Encoding.ASCII, 0x10000);

        private indexTest indexTest;

        protected override void OnStart()
        {
            indexTest = Indicators.GetIndicator<indexTest>(0);
        }

        protected override void OnTick()
        {
            indexTest.Result.Last(0);

            log.WriteLine(MarketSeries.Close.Count);
            log.Flush();
        }

        protected override void OnStop()
        {
            log.Close();
            indexTest.Close();
        }
    }
}

@MHBB

PanagiotisCharalampous
25 Jun 2018, 17:35

Hi Simon,

The indicator's Calculate method is called for each historic bar starting from the beginning of the series up to the current bar and then on each incoming tick. See here. cBots have different methods for bars and ticks, OnTick and OnBar. Essentially cBots should be used for trading and not for calculating indicators.

Best Regards,

Panagiotis

 


@PanagiotisCharalampous

MHBB
25 Jun 2018, 17:48

Thanks for the clarification Panagiotis


@MHBB