Cannot compile code from documentation in Visual Studio 2022

Created at 19 Dec 2024, 22:17
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!
AB

abdul.latiff.hashim

Joined 01.07.2020

Cannot compile code from documentation in Visual Studio 2022
19 Dec 2024, 22:17


Hi,

I copied some code from https://help.ctrader.com/ctrader-algo/guides/trading/#getting-information-on-deals   . Now when I build using embedded cTrader compiler it will succeed. But when I proceed to build in Visual Studio 2022, the compilation failed. It gave following errors…

'Position' does not contain a definition for 'Deals' and no accessible extension method 'Deals' accepting a first argument of type 'Position' could be found (are you missing a using directive or an assembly reference?) 

'History' does not contain a definition for 'FindByPositionId' and no accessible extension method 'FindByPositionId' accepting a first argument of type 'History' could be found (are you missing a using directive or an assembly reference?)

How do I solve this problem?

 

using System;
using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class DealsExample : Robot
    {
        protected override void OnStart()
        {
            var position = ExecuteMarketOrder(TradeType.Buy, "EURUSD", 10000);

            var deals = position.Position.Deals; // ERROR HERE 

            foreach (var deal in deals)
            {
                Print(deal.ExecutionTime + " " + deal.Status + " " + deal.Id);
            }

            ClosePosition(position.Position, 3000);
            ClosePosition(position.Position, 7000);

            var closing_deals = History.FindByPositionId(position.Position.Id); // ERROR HERE

            foreach (var closing_deal in closing_deals)
            {
                Print(closing_deal.ClosingDeal.ExecutionTime + " " + closing_deal.ClosingDeal.VolumeInUnits);
            }
        }

        protected override void OnStop()
        {
        }
    }
}

@abdul.latiff.hashim
Replies

PanagiotisCharalampous
20 Dec 2024, 08:56

Hi there,

This feature is only available in cTrader 5.1.11. Please install it and it should work fine.

Best regards,

Panagiotis


@PanagiotisCharalampous