help plz

Created at 01 Aug 2019, 20:55
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!
US

useretinv

Joined 15.04.2016

help plz
01 Aug 2019, 20:55


If i apply same cbot code at different 5 symbols at the same time Is there a code i can use to read (total net profit of all positions) . And close it all if reached # amount of $. And start over. For example, if i apply code on 5 different pairs, can i add code to close all positions at all symbols at the same time, ( maybe one pair loses and the other two gains some profit, i want that code to ignore net profit of each pair, but only counts on total profit for all positions and close it all when reach Specific value of profit. Thank you.

@useretinv
Replies

PanagiotisCharalampous
02 Aug 2019, 09:38

Hi useretinv,

See an example below

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

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

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            if (Positions.Sum(x => x.NetProfit) > Amount)
                foreach (var position in Positions)
                    position.Close();
        }

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

Best Regards,

Panagiotis


@PanagiotisCharalampous

useretinv
02 Aug 2019, 13:33

Thank you, But X refers to what?
@useretinv

PanagiotisCharalampous
02 Aug 2019, 14:51

Hi useretinv,

It is an expression for a selector. Read more here

Best Regards,

Panagiotis


@PanagiotisCharalampous

useretinv
02 Aug 2019, 19:20

Can i add symbols i need to the code? I couldn't make the back test on multi symbol, back test available only for ever pair separately
@useretinv

PanagiotisCharalampous
05 Aug 2019, 09:27

Hi useretinv,

If you mean to filter the positions by symbol, here is an example below

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

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

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            if (Positions.Where(j => j.SymbolName == "EURUSD" || j.SymbolName == "EURGBP").Sum(x => x.NetProfit) > Amount)
                foreach (var position in Positions)
                    position.Close();
        }

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

Best Regards,

Panagiotis


@PanagiotisCharalampous