Skip to main content Skip to footer

ByMarketTradeExitSignal - type of Exit Signal that allows to send a signal to close position immediately by market;

The main function inside which a developer should implement all logic of Stop Loss and Take Profit calculation is OnProcessPosition. The below examle show of implementation of close at some special date and time exit signal.

public class CloseAtDateTimeExitSignal : ByMarketTradeExitSignal
{
        /// <summary>
        /// The time of the day, HH:mm
        /// </summary>
        [UnitProperty(Name = "Close At", CategoryName = "Parameters", Order = 0)]

        public DateTime CloseAt { get; set; } = DateTime.Now.AddDays(1);

        #region Overrides of ByMarketTradeExitSignal

        /// <inheritdoc />
        protected override void OnProcessPosition(Position position, ref bool closePosition, ref string? signalName)
        {
            if (Input.Count < 2)
                return;

            var lastBarTime = Bars.GetLastTime();
            if (lastBarTime >= CloseAt)
            {
                closePosition = true;
                signalName = "Exit by date and time";
            }
        }

        #endregion
}

Cookies Notice

We use cookies to improve your experience, personalize content, and analyze our traffic. By clicking "Accept All Cookies," you agree to the storing of cookies on your device. You can manage your cookie preferences at any time by visiting our Cookie Settings.