QuickStart - Starter Robot

Spotware's avatar

Spotware since: 23 Sep 2013;

  14 Jan 2014, 16:06
QuickStart - Starter Robot
// -------------------------------------------------------------------------------------------------
//
//    The Starter cBot will execute a buy order on start
//    On each tick it will check the net profit and if it reached a predefined value
//    it will close the position and stop.
//
// -------------------------------------------------------------------------------------------------
using System;
using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class Starter_cBot : Robot
    {

        [Parameter(DefaultValue = 10000)]
        public int Volume { get; set; }

        [Parameter(DefaultValue = 10)]
        public double Profit { get; set; }

        [Parameter(DefaultValue = 10)]
        public double StopLossPips { get; set; }


        [Parameter(DefaultValue = "My Robot")]
        public string MyLabel { get; set; }


        protected override void OnStart()
        {
            ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, MyLabel, StopLossPips, null);
            
        }
        protected override void OnTick()
        {
            var position = Positions.Find(MyLabel, Symbol, TradeType.Buy);
            if(position == null)
            {
                Stop();
                return;
            }
            if (position.NetProfit > Profit)
            {
                ClosePosition(position);                        
                Stop();
             }
        }

    }
}
TRADERS FIRSTâ„¢ Vote for your favorite features: https://ctrader.com/forum/suggestions