Replies

hugicardoso
29 Mar 2022, 20:41

RE:

Works very good thanks for the help.

amusleh said:

Hi,

Try to increase the timer interval, ex:

using cAlgo.API;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class z : Robot
    {
        [Parameter("Max time position open(hours)", DefaultValue = 2, MinValue = 1)]
        public int MaxTimeOpen { get; set; }

        protected override void OnStart()
        {
            Timer.Start(3600);

            // Put your initialization logic here
            Print("Start robot: ", Server.Time.Hour);
            if (Server.Time.Hour == 0)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, 10000, "", 100, 100);
            }
        }

        protected override void OnTimer()
        {
            foreach (var position in Positions)
            {
                var timeElapsedSincePositionEntryTime = Server.TimeInUtc - position.EntryTime;

                Print("timeElapsedSincePositionEntryTime: {0}", timeElapsedSincePositionEntryTime);

                if (timeElapsedSincePositionEntryTime.TotalHours >= MaxTimeOpen)
                {
                    ClosePosition(position);
                }
            }
        }
    }
}

 

 


@hugicardoso

hugicardoso
29 Mar 2022, 19:03

RE:

Thank you very much, but when I use the optimization it is very slow, it goes from 7h to 5 days. which makes it very difficult to use

 

amusleh said:

Hi,

Try this:

using cAlgo.API;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class z : Robot
    {
        [Parameter("Max time position open(hours)", DefaultValue = 2, MinValue = 1)]
        public int MaxTimeOpen { get; set; }

        protected override void OnStart()
        {
            Timer.Start(1);

            // Put your initialization logic here
            Print("Start robot: ", Server.Time.Hour);
            if (Server.Time.Hour == 0)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, 10000, "", 100, 100);
            }
        }

        protected override void OnTimer()
        {
            foreach (var position in Positions)
            {
                var timeElapsedSincePositionEntryTime = Server.TimeInUtc - position.EntryTime;

                Print("timeElapsedSincePositionEntryTime: {0}", timeElapsedSincePositionEntryTime);

                if (timeElapsedSincePositionEntryTime.TotalHours >= MaxTimeOpen)
                {
                    ClosePosition(position);
                }
            }
        }
    }
}

 

 


@hugicardoso