Topics

Forum Topics not found

Replies

lakshanperera1313
18 Jul 2020, 13:12

Now there is a way with new cAlgo API updates

        protected override void OnStart()
        {
            // Subscribe to the Trade Closing event
            Positions.Closed += OnPositionsClosed;
        }


        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            // check if the position has been closed due to stoploss or takeprofit or any other(stop out etc)
            if(args.Reason == PositionCloseReason.StopLoss)
            {
                Print("Position has been closed due to Stop Loss");
            }
            else if(args.Reason == PositionCloseReason.TakeProfit)
            {
                Print("Position has been closed due to Take Profit");
            }
        }

With the new cAlgo API, the reason for position closing can be checked as shown above.

Hope this helps someone who has the same question.

All the best!


@lakshanperera1313