two bots

Created at 19 Mar 2021, 09:59
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!
SH

shop.n33

Joined 04.12.2020

two bots
19 Mar 2021, 09:59


two bots are launched on the same currency pair and on the same time frame. Both bots manage each other's orders. How to set personality? thank


@shop.n33
Replies

amusleh
19 Mar 2021, 11:03

Hi,

You can use order label parameter to set unique ID for orders, add a string type label parameter to your bot and then use that parameter value as your bot executed orders label, the other bot can use the same label to filter the orders and find the previous bot opened orders.


@amusleh

shop.n33
19 Mar 2021, 11:23

RE:

amusleh said:

Hi,

You can use order label parameter to set unique ID for orders, add a string type label parameter to your bot and then use that parameter value as your bot executed orders label, the other bot can use the same label to filter the orders and find the previous bot opened orders.

Thank. I have no experience. Can you write what needs to be changed here?

 

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 MartingaleRobot : Robot
    {


@shop.n33

amusleh
19 Mar 2021, 11:36

Hi,

This sample bot might help you:

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class BarBreakoutTradingSample : Robot
    {
        private double _volumeInUnits;

        [Parameter("Breakount Amount (Pips)", DefaultValue = 10, MinValue = 0)]
        public double BreakountAmountInPips { get; set; }

        [Parameter("Volume (Lots)", DefaultValue = 0.01)]
        public double VolumeInLots { get; set; }

        [Parameter("Label", DefaultValue = "BarBreakoutTradingSample")]
        public string Label { get; set; }

        public Position[] BotPositions
        {
            get
            {
                return Positions.Where(iPosition => Label.Equals(iPosition.Label, StringComparison.OrdinalIgnoreCase)
                && iPosition.SymbolName.Equals(SymbolName, StringComparison.OrdinalIgnoreCase))
                    .ToArray();
            }
        }

        protected override void OnStart()
        {
            if (string.IsNullOrWhiteSpace(Label))
            {
                Print("Please provide a label");

                Stop();
            }

            BreakountAmountInPips *= Symbol.PipSize;

            _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
        }

        protected override void OnTick()
        {
            if (BotPositions.Length > 0) return;

            if (Symbol.Ask >= Bars.Last(1).High + BreakountAmountInPips)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label);
            }
            else if (Symbol.Bid <= Bars.Last(1).Low - BreakountAmountInPips)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label);
            }
        }

        protected override void OnBar()
        {
            foreach (var position in BotPositions)
            {
                if ((position.TradeType == TradeType.Buy && Bars.Last(1).Close < Bars.Last(1).Open)
                    || (position.TradeType == TradeType.Sell && Bars.Last(1).Close > Bars.Last(1).Open))
                {
                    ClosePosition(position);
                }
            }
        }
    }
}

Please read the API references if its hard to understand the sample bot code.


@amusleh