Implausible Indicator Output. Divide not working? Any ideas?

Created at 19 Nov 2017, 12: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!
Mikro's avatar

Mikro

Joined 20.06.2015

Implausible Indicator Output. Divide not working? Any ideas?
19 Nov 2017, 12:06


Hi all,

I am trying to take a look at the intervall between Server.Ticks.

So I wrote a simple Indicator (close to a SMA) measuring the time between ticks and returning the average pause in seconds over the specified period.

What I don't get straight ist that the result always remains 0 even though in debugging I can see valid calculation results (see Screenshot).

If I experiment and write 1/(double)Period to Result I get a valid output, but if I then try to switch back to divide 'sum' by periods I again receive zero!

Any Ideas???

THX!

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

namespace cAlgo
{
    /// <summary>
    /// Shows the average Pause inbetween two ServerTicks.
    /// </summary>
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class indMarketVelocity : Indicator
    {

        [Parameter(DefaultValue = 10)]
        public int Periods { get; set; }

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

        private IndicatorDataSeries ticks;

        protected override void Initialize()
        {
            ticks = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
            int hour = Server.Time.Hour;
            int minute = Server.Time.Minute;
            int second = Server.Time.Second;
            int msec = Server.Time.Millisecond;
            double timestamp = msec + 1000*second + 60*1000*minute + 24*60*1000*hour;

            ticks[index]=timestamp;
            double sum = 0;

            if (ticks.Count>Periods)
            {
                for (int i = index - Periods + 1; i <= index; i++)
                {
                    sum += ticks[i] - ticks[i - 1];
                }
                Result[index] = sum/(Periods*1000);
            }
        }
    }
}

 


@Mikro
Replies

Jiri
20 Nov 2017, 01:16 ( Updated at: 15 Jan 2024, 14:51 )

Hi! The server time is always returning current time of the server, you are trying to calculate historical data with it. You should be using MarketSeries.OpenTime instead. See [this indicator ]which is pretty much the same using different approach.


@Jiri

Mikro
20 Nov 2017, 20:53

Thx!

Sometimes the smal issues are overlooked ;)


@Mikro