Please convert those MT4 codes to cAlgo

Created at 05 Jan 2015, 17:13
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!
SA

SaifBD

Joined 05.01.2014

Please convert those MT4 codes to cAlgo
05 Jan 2015, 17:13


GetTickCount();

TimeCurrent();


@SaifBD
Replies

deklin
05 Jan 2015, 23:53

Re: Please convert those MT4 codes to cAlgo

Instead of TimeCurrent() use Server.Time

Print ( Server.Time );

See:
/api/reference/internals/iserver/time

The time can be formatted using C#
http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

---

Instead of GetTickCount() I would just start a variable at 0 and add to it every tick.  

Here is an example that incorporates both of these solutions:

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 simpleTest : Robot
    {
        long tickCounter = 0;

        [Parameter("TotalTicsToStopAt", DefaultValue = 10)]

        protected override void OnStart()
        {
            Print("Current Time: " + Server.Time);
            Print("Current Time with Custom Formatting: " + Server.Time.ToString("ddd,  MMM d yyyy H':'mm':'ss tt"));
        }

        protected override void OnTick()
        {
            Print("Tick Count: " + tickCounter++);
        }

        protected override void OnStop()
        {
        }
    }
}

 


@deklin