Replies

umadrat2012
28 Jan 2022, 11:05

RE: thank you, how would the code look like if my cbot trades multiple currencies at the same time?

amusleh said:

Hi,

Here is an example:

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DrawIcon : Robot
    {
        private double _initialEquity;

        [Parameter("Equity Increase Amount", DefaultValue = 100)]
        public double EquityIncreaseAmount { get; set; }

        protected override void OnStart()
        {
            _initialEquity = Account.Equity;
        }

        protected override void OnTick()
        {
            if (Account.Equity - _initialEquity >= EquityIncreaseAmount)
            {
                Stop();
            }
        }
    }
}

It works properly only if your cBot trades the current chart symbol, if it trades multiple symbols then you have to use all symbols Tick events and check equity every time a symbol tick is received.

 


@umadrat2012

umadrat2012
08 Oct 2021, 07:48

RE:

amusleh said:

Hi,

Try this sample cBot:

using System;
using System.Linq;
using cAlgo.API;
using System.Globalization;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        private TimeSpan _closeTime;

        [Parameter("Close Time", DefaultValue = "17:00:00")]
        public string CloseTime { get; set; }

        [Parameter("Close Day", DefaultValue = DayOfWeek.Friday)]
        public DayOfWeek CloseDay { get; set; }

        protected override void OnStart()
        {
            if (TimeSpan.TryParse(CloseTime, CultureInfo.InvariantCulture, out _closeTime) == false)
            {
                Print("Incorrect close time value");

                Stop();
            }

            Timer.Start(1);
        }

        protected override void OnTimer()
        {
            if (Server.Time.DayOfWeek == CloseDay && Server.Time.TimeOfDay >= _closeTime)
            {
                var positionsCopy = Positions.ToArray();

                foreach (var position in Positions)
                {
                    ClosePosition(position);
                }
            }
        }
    }
}

 

Thank you very much, implementing this into my cbot seems to be working


@umadrat2012