Topics
19 Mar 2021, 09:59
 852
 4
04 Dec 2020, 11:56
 1405
 12
Replies

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

shop.n33
18 Mar 2021, 15:22

RE: RE: Thank you so much!!!

shop.n33 said:

shop.n33 said:

amusleh said:

shop.n33 said:

PanagiotisCharalampous said:

Hi shop.n33,

Your cBot is still executing random orders. See here

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, GetRandomTradeType());
            }
            else
            {
                ExecuteOrder((int)position.Volume * 2, position.TradeType);
            }

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi,

Here is the code that will change the trade type to opposite trade type of previous position:

using cAlgo.API;
using System;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MartingaleRobot : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
        public int InitialVolume { get; set; }

        [Parameter("Stop Loss", DefaultValue = 4)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 5)]
        public int TakeProfit { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;

            ExecuteOrder(InitialVolume, TradeType.Buy);
        }

        private void ExecuteOrder(long volume, TradeType tradeType)
        {
            var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            Print("Closed");

            var position = args.Position;

            if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code) return;

            var nextOrderTradeType = position.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, nextOrderTradeType);
            }
            else
            {
                ExecuteOrder((int)position.Volume * 2, nextOrderTradeType);
            }
        }

        private TradeType GetRandomTradeType()
        {
            return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
        }
    }
}

 

 

 

 


@shop.n33

shop.n33
18 Mar 2021, 15:19

RE: Thank you so much!!!

shop.n33 said:

amusleh said:

shop.n33 said:

PanagiotisCharalampous said:

Hi shop.n33,

Your cBot is still executing random orders. See here

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, GetRandomTradeType());
            }
            else
            {
                ExecuteOrder((int)position.Volume * 2, position.TradeType);
            }

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi,

Here is the code that will change the trade type to opposite trade type of previous position:

using cAlgo.API;
using System;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MartingaleRobot : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
        public int InitialVolume { get; set; }

        [Parameter("Stop Loss", DefaultValue = 4)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 5)]
        public int TakeProfit { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;

            ExecuteOrder(InitialVolume, TradeType.Buy);
        }

        private void ExecuteOrder(long volume, TradeType tradeType)
        {
            var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            Print("Closed");

            var position = args.Position;

            if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code) return;

            var nextOrderTradeType = position.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, nextOrderTradeType);
            }
            else
            {
                ExecuteOrder((int)position.Volume * 2, nextOrderTradeType);
            }
        }

        private TradeType GetRandomTradeType()
        {
            return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
        }
    }
}

 

 

 


@shop.n33

shop.n33
18 Mar 2021, 15:18

Thank you so much!!!

amusleh said:

shop.n33 said:

PanagiotisCharalampous said:

Hi shop.n33,

Your cBot is still executing random orders. See here

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, GetRandomTradeType());
            }
            else
            {
                ExecuteOrder((int)position.Volume * 2, position.TradeType);
            }

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi,

Here is the code that will change the trade type to opposite trade type of previous position:

using cAlgo.API;
using System;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MartingaleRobot : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
        public int InitialVolume { get; set; }

        [Parameter("Stop Loss", DefaultValue = 4)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 5)]
        public int TakeProfit { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;

            ExecuteOrder(InitialVolume, TradeType.Buy);
        }

        private void ExecuteOrder(long volume, TradeType tradeType)
        {
            var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            Print("Closed");

            var position = args.Position;

            if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code) return;

            var nextOrderTradeType = position.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, nextOrderTradeType);
            }
            else
            {
                ExecuteOrder((int)position.Volume * 2, nextOrderTradeType);
            }
        }

        private TradeType GetRandomTradeType()
        {
            return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
        }
    }
}

 

 


@shop.n33

shop.n33
17 Mar 2021, 20:17

RE: thank. And what needs to be written so that the direction changes with each new order?

PanagiotisCharalampous said:

Hi shop.n33,

Your cBot is still executing random orders. See here

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, GetRandomTradeType());
            }
            else
            {
                ExecuteOrder((int)position.Volume * 2, position.TradeType);
            }

Best Regards,

Panagiotis 

Join us on Telegram

 


@shop.n33

shop.n33
08 Dec 2020, 15:06

RE:

PanagiotisCharalampous said:

// -------------------------------------------------------------------------------
//
//    This is a Template used as a guideline to build your own Robot. 
//    Please use the “Feedback” tab to provide us with your suggestions about cAlgo’s API.
//
// -------------------------------------------------------------------------------

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using System.Collections.Generic;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MartingaleRobot : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
        public int InitialVolume { get; set; }

        [Parameter("Stop Loss", DefaultValue = 4)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 5)]
        public int TakeProfit { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;

            ExecuteOrder(InitialVolume, TradeType.Buy);
        }

        private void ExecuteOrder(long volume, TradeType tradeType)
        {
            var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            Print("Closed");
            var position = args.Position;

            if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code)
                return;

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, GetRandomTradeType());
            }
            else
            {
                ExecuteOrder((int)position.Volume * 2, position.TradeType);
            }
        }

        private TradeType GetRandomTradeType()
        {
            return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
        }
    }
}

 


@shop.n33

shop.n33
04 Dec 2020, 15:48

RE:

 

When moving sideways, the bot opened only in a given direction. But, with an active movement, prices began to open in another. Why?


@shop.n33

shop.n33
04 Dec 2020, 12:34

RE: Thank you very much

PanagiotisCharalampous said:

Hi shop.n33,

You should change the following line of code

ExecuteOrder(InitialVolume, GetRandomTradeType());

If you want only buy orders, it should be

ExecuteOrder(InitialVolume, TradeType.Buy);

 If you want only sell orders, it should be

ExecuteOrder(InitialVolume, TradeType.Sell);

Best Regards,

Panagiotis 

Join us on Telegram

 


@shop.n33

shop.n33
04 Dec 2020, 06:16

Found a solution?


@shop.n33