Execute Market Orders and Stop Orders in all Symbols with just one bot

Created at 15 Aug 2018, 21:14
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!
RY

ryanoia@gmail.com

Joined 09.03.2018

Execute Market Orders and Stop Orders in all Symbols with just one bot
15 Aug 2018, 21:14


Is it possible to have a bot that will execute market orders and stop orders in all symbols with just one bot? 

What I want to achieve is if I click play on the bot, it executes a market order and/or a stop (either a buy or a sell depending on my specifications)

  1. Let's say I want to have a buy market order and buy stop located at 10 pips above in all GBPUSD, GBPJPY, GBPCAD all at once, how can I do that with just one click?
  2. Let's say I want to have a buy and sell market order and buy and sell stop located at 10 pips away in all pairs in a given workspace all at once, how can I do that with just one click? Is that possible?

 


@ryanoia@gmail.com
Replies

ryanoia@gmail.com
16 Aug 2018, 19:31

Open buy and sell and stop orders in all symbols, not just one

In particular, I can do this with one pair:

 ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "order 1", null, 11, null);
 ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "order 1", null, 11, null);
 PlaceStopOrder(TradeType.Buy, Symbol, Volume, Symbol.Ask + 16 * Symbol.PipSize, "myStopOrder", null, 11, null);
 PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Bid - 16 * Symbol.PipSize, "myStopOrder", null, 11, null);

 

How do I do that with multiple pairs?
                 


@ryanoia@gmail.com

ryanoia@gmail.com
16 Aug 2018, 19:51

Open buy and sell and stop orders in all symbols, not just one

This is the code for one pair:

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 OpenPositions : Robot
    {
        [Parameter("Volume", DefaultValue = 1000, MinValue = 1, Step = 1)]
        public int Volume { get; set; }

        protected override void OnStart()
        {
            ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "order 1", null, 11, null);
            ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "order 1", null, 11, null);
            PlaceStopOrder(TradeType.Buy, Symbol, Volume, Symbol.Ask + 16 * Symbol.PipSize, "myStopOrder", null, 11, null);
            PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Bid - 16 * Symbol.PipSize, "myStopOrder", null, 11, null);
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

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

How can I do this for multiple selected pairs?


@ryanoia@gmail.com

PanagiotisCharalampous
17 Aug 2018, 09:27

Hi ryanoia@gmail.com,

See 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 OpenPositions : Robot
    {
        [Parameter("Volume", DefaultValue = 1000, MinValue = 1, Step = 1)]
        public int Volume { get; set; }

        protected override void OnStart()
        {
            var gbpusd = MarketData.GetSymbol("GBPUSD");
            ExecuteMarketOrder(TradeType.Buy, gbpusd, Volume, "order 1", null, 11, null);
            ExecuteMarketOrder(TradeType.Sell, gbpusd, Volume, "order 1", null, 11, null);
            PlaceStopOrder(TradeType.Buy, gbpusd, Volume, gbpusd.Ask + 16 * Symbol.PipSize, "myStopOrder", null, 11, null);
            PlaceStopOrder(TradeType.Sell, gbpusd, Volume, gbpusd.Bid - 16 * Symbol.PipSize, "myStopOrder", null, 11, null);

            var gbpjpy = MarketData.GetSymbol("GBPJPY");
            ExecuteMarketOrder(TradeType.Buy, gbpjpy, Volume, "order 1", null, 11, null);
            ExecuteMarketOrder(TradeType.Sell, gbpjpy, Volume, "order 1", null, 11, null);
            PlaceStopOrder(TradeType.Buy, gbpjpy, Volume, gbpjpy.Ask + 16 * Symbol.PipSize, "myStopOrder", null, 11, null);
            PlaceStopOrder(TradeType.Sell, gbpjpy, Volume, gbpjpy.Bid - 16 * Symbol.PipSize, "myStopOrder", null, 11, null);

            var gbpcad = MarketData.GetSymbol("GBPCAD");
            ExecuteMarketOrder(TradeType.Buy, gbpcad, Volume, "order 1", null, 11, null);
            ExecuteMarketOrder(TradeType.Sell, gbpcad, Volume, "order 1", null, 11, null);
            PlaceStopOrder(TradeType.Buy, gbpcad, Volume, gbpcad.Ask + 16 * Symbol.PipSize, "myStopOrder", null, 11, null);
            PlaceStopOrder(TradeType.Sell, gbpcad, Volume, gbpcad.Bid - 16 * Symbol.PipSize, "myStopOrder", null, 11, null);
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

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

Best Regards,

Panagiotis


@PanagiotisCharalampous

ryanoia@gmail.com
17 Aug 2018, 10:00

Thanks. 

As a way of contributing to the community, this also worked too:

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 HolyGrailAllPairs : Robot
    {
        [Parameter("Volume", DefaultValue = 1000, MinValue = 1, Step = 1)]
        public int Volume { get; set; }

        public enum ConsideredPairs
        {
            NZDCAD,
            NZDJPY,
            NZDUSD
        }

        protected override void OnStart()
        {
            foreach (string singlePair in Enum.GetNames(typeof(ConsideredPairs)))
            {
                Symbol Symbol = MarketData.GetSymbol(singlePair);
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "order 1", null, 11, null);
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "order 1", null, 11, null);
                PlaceStopOrder(TradeType.Buy, Symbol, Volume, Symbol.Ask + 16 * Symbol.PipSize, "myStopOrder", null, 11, null);
                PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Bid - 16 * Symbol.PipSize, "myStopOrder", null, 11, null);
            }
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

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

I hope my 2 other queries get answered.

 

By the way, since we're talking, what is the difference between executemarketorderasync and executemarketorder only? is one better than the other?

My understanding is, if it's executemarketorder, this needs to be processed first before the bot proceeds to execute the next line in command. If it's executemarketorderasync, then everything executes independent of one another. Is my understanding on point?


@ryanoia@gmail.com

PanagiotisCharalampous
17 Aug 2018, 10:05

Ηi ryanoia@gmail.com,

Yes you understood it correct. If your logical sequency is not dependent on the outcome of the market order execution, then you should probably use ExecuteMarketOrderAsync.

Best Regards,

Panagiotis


@PanagiotisCharalampous

ryanoia@gmail.com
17 Aug 2018, 10:14

Thanks for the quick response.

 

Just for clarification, every command (not sure if I labeled this correctly) can be async, like modifyposition, etc. 


@ryanoia@gmail.com

ryanoia@gmail.com
17 Aug 2018, 10:15

or even notifications.sendemail i.e. notifiactions.sendemailasync


@ryanoia@gmail.com

ryanoia@gmail.com
17 Aug 2018, 10:26

No need to answer that, just found the answer myself. Answer is, not all commands have an async counterpart.

Thanks. 


@ryanoia@gmail.com