Category Other  Published on 28/01/2021

Order Sends Order (OSO)

Description

This is a Bot that handles OSO Type Orders, it works only for 2 orders, you Type if you wanna Buy or Sell, the prices and the bot will handle the rest.

For more info on how OSO Orders work please check Investopedia's page: 

http://www.investopedia.com/university/intro-to-order-types/conditional-orders.asp

08/06/?? - Fixed Bug where Order would send before time
01/27/2021 - Updated settings to use the latest parameter features

----

Made by Waxy


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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class OrderSendsOrder : Robot
    {
        [Parameter("Type", DefaultValue = TradeType.Buy, Group = "Order #1")]
        public TradeType InputOrder1Type { get; set; }

        [Parameter("Price", DefaultValue = 1.0, Group = "Order #1")]
        public double InputOrder1Price { get; set; }

        [Parameter("Volume", DefaultValue = 10000, Group = "Order #1")]
        public int InputOrder1Size { get; set; }

        [Parameter("SL", DefaultValue = 20, Group = "Order #1")]
        public int InputOrder1StopLoss { get; set; }

        [Parameter("TP", DefaultValue = 40, Group = "Order #1")]
        public int InputOrder1TakeProfit { get; set; }


        //---

        [Parameter("Type", DefaultValue = TradeType.Sell, Group = "Order #2")]
        public TradeType InputOrder2Type { get; set; }

        [Parameter("Price", DefaultValue = 1.0, Group = "Order #2")]
        public double InputOrder2Price { get; set; }

        [Parameter("Volume", DefaultValue = 10000, Group = "Order #2")]
        public int InputOrder2Size { get; set; }

        [Parameter("SL", DefaultValue = 20, Group = "Order #2")]
        public int InputOrder2StopLoss { get; set; }

        [Parameter("TP", DefaultValue = 40, Group = "Order #2")]
        public int InputOrder2TakeProfit { get; set; }

        private string _label;

        protected override void OnStart()
        {
            _label = SymbolName + Server.Time.Ticks;

            if (InputOrder1Type == TradeType.Sell)
            {
                if (InputOrder1Price > Bars.ClosePrices.LastValue)
                    PlaceLimitOrder(TradeType.Sell, SymbolName, InputOrder1Size, InputOrder1Price, _label, InputOrder1StopLoss, InputOrder1TakeProfit);
                else
                    PlaceStopOrder(TradeType.Sell, SymbolName, InputOrder1Size, InputOrder1Price, _label, InputOrder1StopLoss, InputOrder1TakeProfit);
            }
            else
            {
                if (InputOrder1Price > Bars.ClosePrices.LastValue)
                    PlaceStopOrder(TradeType.Buy, SymbolName, InputOrder1Size, InputOrder1Price, _label, InputOrder1StopLoss, InputOrder1TakeProfit);
                else
                    PlaceLimitOrder(TradeType.Buy, SymbolName, InputOrder1Size, InputOrder1Price, _label, InputOrder1StopLoss, InputOrder1TakeProfit);
            }

            Positions.Opened += args =>
            {
                if (args.Position.Label != _label)
                    return;

                if (InputOrder2Type == TradeType.Sell)
                {
                    if (InputOrder2Price > Symbol.Bid)
                        PlaceLimitOrder(TradeType.Sell, SymbolName, InputOrder2Size, InputOrder2Price, _label, InputOrder2StopLoss, InputOrder2TakeProfit);
                    else
                        PlaceStopOrder(TradeType.Sell, SymbolName, InputOrder2Size, InputOrder2Price, _label, InputOrder2StopLoss, InputOrder2TakeProfit);
                }
                else
                {
                    if (InputOrder2Price > Symbol.Bid)
                        PlaceStopOrder(TradeType.Buy, SymbolName, InputOrder2Size, InputOrder2Price, _label, InputOrder2StopLoss, InputOrder2TakeProfit);
                    else
                        PlaceLimitOrder(TradeType.Buy, SymbolName, InputOrder2Size, InputOrder2Price, _label, InputOrder2StopLoss, InputOrder2TakeProfit);
                }

                Stop();
            };
        }
    }
}


Waxy's avatar
Waxy

Joined on 12.05.2015

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: OSO.algo
  • Rating: 5
  • Installs: 3267
  • Modified: 13/10/2021 09:55
Comments
Log in to add a comment.
No comments found.