Category Other  Published on 29/01/2016

Iceberg bot

Description

DEFINITION of 'Iceberg Order' from Investopedia

A large single order that has been divided into smaller lots, usually through the use of an automated program, for the purpose of hiding the actual order quantity.

Read more: Iceberg Order Definition | Investopedia http://www.investopedia.com/terms/i/icebergorder.asp#ixzz3yaphczPe 

Sometimes a trader wants to place a big order into smaller pieces, this bot makes it possible, using timer it places an orders each number of seconds you can define.

Please let me know in case of any bug.


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 Iceberging : Robot
    {
        [Parameter("Order Size", DefaultValue = 10000)]
        public int _OrderSize { get; set; }
        [Parameter("Order Multiplier", DefaultValue = 2)]
        public int _OrderMultiplier { get; set; }
        [Parameter("Order Type", DefaultValue = "Buy")]
        public string _OrderType { get; set; }
        [Parameter("Interval (seconds)", DefaultValue = 1)]
        public int _Interval { get; set; }
        [Parameter("Stop Loss (pips)", DefaultValue = 10)]
        public int _SL { get; set; }
        [Parameter("Take Profits (pips)", DefaultValue = 10)]
        public int _TP { get; set; }
        [Parameter("Close Orders on stop", DefaultValue = true)]
        public bool _CloseOrders { get; set; }

        int _count;
        TradeType _Tradetype;
        string _Label = "label";

        protected string GetLabel(string _TType)
        {
            Random rn = new Random(10);
            int x = rn.Next(100, 10000);
            _Label = _TType + x.ToString();

            var _CLD = History.FindLast(_Label);
            var _CLO = Positions.Find(_Label);
            while (_CLD != null || _CLO != null)
            {
                x++;
                _Label = _TType + x.ToString();
                _CLD = History.FindLast(_Label);
                _CLO = Positions.Find(_Label);
            }
            return _Label;
        }


        protected override void OnTimer()
        {
            _count++;

            if (_count <= _OrderMultiplier)
            {
                TradeResult _order = ExecuteMarketOrder(_Tradetype, Symbol, _OrderSize, _Label, _SL, _TP);
                if (!_order.IsSuccessful)
                {
                    Print("Error number {0}, Bot Will Stop", _order.Error);
                    Stop();
                }
            }

            base.OnTimer();
        }

        protected override void OnStart()
        {
            _Label = GetLabel(Symbol.Code);

            Print("Bot is Starting, the total size of the order is {0}", _OrderSize * _OrderMultiplier);

            if (_OrderType.ToLower() == "buy")
            {
                _Tradetype = TradeType.Buy;
            }
            else if (_OrderType.ToLower() == "sell")
            {
                _Tradetype = TradeType.Sell;
            }
            else
            {
                Print("Error: Please type 'buy' or 'sell'");
                Stop();
            }

            Timer.Start(_Interval);
        }

        protected override void OnStop()
        {
            if (_CloseOrders)
            {
                foreach (var pos in Positions)
                {
                    if (pos.Label == _Label)
                    {
                        TradeResult _OrderClose = ClosePosition(pos);

                        if (!_OrderClose.IsSuccessful)
                        {
                            Print("Warning, error {0} trying to close this position, bot will stop");
                            break;
                        }
                    }
                }

            }
        }
    }
}


Waxy's avatar
Waxy

Joined on 12.05.2015

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Iceberging.algo
  • Rating: 0
  • Installs: 3058
  • Modified: 13/10/2021 09:55
Comments
Log in to add a comment.
ME
megamemo · 6 years ago

Those are really usefull tools!!!! there is not possible to put distance like a traddle strategy ?