QuickStart - Starter Robot

Created at 14 Jan 2014, 16:06
Spotware's avatar

cTrader Team

Joined 23.09.2013

QuickStart - Starter Robot
14 Jan 2014, 16:06


// -------------------------------------------------------------------------------------------------
//
//    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();
             }
        }

    }
}

 


@Spotware