How to select and get position attributes by label?

Created at 08 May 2015, 02:15
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!
SW

SwXavi

Joined 06.05.2015

How to select and get position attributes by label?
08 May 2015, 02:15


Hello People

I need help regarding this issue, I have many positions with a single label id, I would like to get the unrealized profit/loss for those positions.

There is Symbol.UnrealizedNetProfit, however that's for a Symbol. I also have Position.GrossProfit but that's only for the last executed order.

I found an indirect way to do this which is simple arithmetic for the entry point and the current price, however it may be a little inaccurate due to swap/spreads and commissions.

Any help/ideas are appreciated.

 


@SwXavi
Replies

SwXavi
08 May 2015, 11:41

RE:

8053143 said:

Hello People

I need help regarding this issue, I have many positions with a single label id, I would like to get the unrealized profit/loss for those positions.

There is Symbol.UnrealizedNetProfit, however that's for a Symbol. I also have Position.GrossProfit but that's only for the last executed order.

I found an indirect way to do this which is simple arithmetic for the entry point and the current price, however it may be a little inaccurate due to swap/spreads and commissions.

Any help/ideas are appreciated.

 

Sorry I'm new to calgo it was easy, heres the code:

 

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

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

        double total = 0;

        protected override void OnStart()
        {
            ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "test");
            ExecuteMarketOrder(TradeType.Sell, Symbol, 20000, "test");
        }

        protected override void OnTick()
        {

            foreach (var pos in Positions)
            {
                if (pos.Label == "test")
                {
                    total += pos.NetProfit;
                    ChartObjects.DrawText("NetProfit", "Net Profit: " + Math.Round(total, 2).ToString(), StaticPosition.TopRight, Colors.Green);
                }
            }
            total = 0;
        }

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

 


@SwXavi

Spotware
17 Jun 2015, 17:46

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware