Cannot print to log

Created at 03 Oct 2017, 17:37
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
ST

Stokes Bay

Joined 18.04.2016

Cannot print to log
03 Oct 2017, 17:37


Can someone please tell me why the following code does not print the values indicated. Thanks.

 

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

namespace cAlgo.Robots
{
    [Robot()]
    public class PCAccounttargethit : Robot
    {

        [Parameter(DefaultValue = "Account Target Hit cBot")]
        public string cBotLabel { get; set; }

        [Parameter()]
        public DataSeries SourceSeries { get; set; }


        [Parameter("TargetBalance", DefaultValue = 5000)]
        public double TargetBalance { get; set; }


        protected override void OnStart()
        {

        }

        protected override void OnBar()
        {

            // Some condition to close all positions
            if (Account.Equity > TargetBalance)
                foreach (var position in Positions)
                    ClosePosition(position);
        }

        private void PositionsOnClosed(PositionClosedEventArgs obj)
        {
            Position closedPosition = obj.Position;
            if (closedPosition.Label != cBotLabel)
                return;

            Print("position closed with {0} gross profit", closedPosition.GrossProfit);
            Print("Account info:");
            Print(Account.Balance);
            Print(Account.Equity);
            Print(Account.Margin);
            Print("Open Positions: " + Positions.Count + "position(s)");
            Print("Pending Orders: " + PendingOrders.Count + "order(s)");
            Print("Current Balance is {0}, Equity is {1}.", Account.Balance, Account.Equity);
        }
    }
}

 


@Stokes Bay
Replies

BeardPower
03 Oct 2017, 18:19

if (closedPosition.Label != cBotLabel)
    return;

Your code does not set the label for the position.


@BeardPower