Cancel pending orders at endo of the day

06 Dec 2018, 21:16Cancel pending orders at endo of the day#1
DelTraderposts: 45since: 25 Jun 2017

Good night, I ask for help because I need to cancel pending orders at the end of the day. I tested the following code but it is not the best, I believe giving instructions specifically on changing Day candle would be the best.

Thank you so much.

protected override void OnTick(){
if (Server.Time.Hour == 21 && Server.Time.Minute == 59)
            {
                foreach (var _PendingOrders in PendingOrders)
                {
                    if (_PendingOrders.Label == Label)
                    {
                        Print("Cancel by time");
                        CancelPendingOrder(_PendingOrders);
                    }
                }
            }
}
07 Dec 2018, 10:07#2
Panagiotis Charalampousposts: 1818since: 13 Jan 2017

Hi DelTrader,

I would suggest  the below approach

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

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

        MarketSeries _daySeries;
        DateTime _lastDayOpen;
        protected override void OnStart()
        {
            _daySeries = MarketData.GetSeries(TimeFrame.Daily);
            _lastDayOpen = _daySeries.OpenTime.LastValue;
        }

        protected override void OnTick()
        {
            if (_lastDayOpen != _daySeries.OpenTime.LastValue)
            {
                _lastDayOpen = _daySeries.OpenTime.LastValue;
                foreach (var _PendingOrders in PendingOrders)
                {
                    if (_PendingOrders.Label == Label)
                    {
                        Print("Cancel by time");
                        CancelPendingOrder(_PendingOrders);
                    }
                }
            }
        }

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

Best Regards,

Panagiotis


Head of Community Management at cTrader
08 Dec 2018, 19:48#3
DelTraderposts: 45since: 25 Jun 2017

Thank you very much Panagiotis, It's perfect. You'r the greatest.
Best Regards!