Example #1
0
        /// <summary>
        /// cutting an order in n orders such that the sum of the volume equal initial volume.
        /// </summary>
        /// <param name="tradeType"></param>
        /// <param name="volume"></param>
        /// <param name="prefixLabel"></param>
        public static void splitAndExecuteOrder(this Robot robot, OrderParams op)
        {
            if (op == null)
            {
                throw new System.ArgumentException(String.Format("parameter 'op' must be non null", op));
            }
            if (op.Volume <= 0)
            {
                throw new System.ArgumentException(String.Format("parameter 'op.Volume' must be strictly positive", op.Volume));
            }

            double        sum       = op.Parties.Sum(x => Math.Abs(x));
            OrderParams   partialOP = new OrderParams(op);
            List <double> l         = new List <double>(op.Parties);

            l.Sort();

            for (int i = l.Count - 1; i >= 0; i--)
            {
                partialOP.Volume  = op.Volume.Value * l[i] / sum;
                partialOP.Comment = string.Format("{0}-{1}", partialOP.Comment, i);

                robot.executeOrder(partialOP);
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tradeType"></param>
        /// <param name="volume"></param>
        /// <param name="label"></param>
        public static void executeOrder(this Robot robot, OrderParams op)
        {
            if (op == null)
            {
                throw new System.ArgumentException(String.Format("parameter 'op' must be non null", op));
            }
            if (op.Volume <= 0)
            {
                throw new System.ArgumentException(String.Format("parameter 'op.Volume' must be strictly positive", op.Volume));
            }
            if (!op.TradeType.HasValue)
            {
                throw new System.ArgumentException(String.Format("parameter 'op.TradeType' must have a value", op.TradeType));
            }


            // it is necessary that the volume is a multiple of "microvolume".
            long v = robot.Symbol.NormalizeVolume(op.Volume.Value, RoundingMode.ToNearest);

            if (v > 0)
            {
                var result = robot.ExecuteMarketOrder(op.TradeType.Value, op.Symbol, v, op.Label, op.StopLoss, op.TakeProfit, op.Slippage, op.Comment);
                if (!result.IsSuccessful)
                {
                    robot.Print("error : {0}, {1}", result.Error, v);
                }
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="robot"></param>
        public static OrderParams martingale(this Robot robot, Position position, bool inversePosition = true, double martingaleCoeff = 1.5)
        {
            if ((position != null) && position.Pips < 0)
            {
                OrderParams op = new OrderParams(position);
                op.Comment = string.Format("{0}-{1}", position.Comment, "Mart");
                if (inversePosition)
                {
                    op.TradeType = position.TradeType.inverseTradeType();
                }
                op.Volume = position.Volume * martingaleCoeff;

                return(op);
            }
            else
            {
                return(null);
            }
        }
Example #4
0
 public OrderParams(OrderParams op) : this(op.TradeType, op.Symbol, op.Volume, op.Label, op.StopLoss, op.TakeProfit, op.Slippage, op.Comment, op.Id, op.Parties)
 {
 }
Example #5
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="robot"></param>
		public static OrderParams martingale(this Robot robot, Position position, bool inversePosition=true, double martingaleCoeff=1.5)
		{
			if ((position != null) && position.Pips < 0)
			{
				OrderParams op = new OrderParams(position);
				op.Comment = string.Format("{0}-{1}", position.Comment, "Mart");
				if (inversePosition)
					op.TradeType = position.TradeType.inverseTradeType();
				op.Volume = position.Volume * martingaleCoeff;

				return op;
			}
			else
				return null;
		}
Example #6
0
		/// <summary>
		/// cutting an order in n orders such that the sum of the volume equal initial volume.
		/// </summary>
		/// <param name="tradeType"></param>
		/// <param name="volume"></param>
		/// <param name="prefixLabel"></param>
		public static void splitAndExecuteOrder(this Robot robot, OrderParams op)
		{
			if (op == null)
				throw new System.ArgumentException(String.Format("parameter 'op' must be non null", op));
			if (op.Volume <= 0)
				throw new System.ArgumentException(String.Format("parameter 'op.Volume' must be strictly positive", op.Volume));

			double sum = op.Parties.Sum(x => Math.Abs(x));
			OrderParams partialOP = new OrderParams(op);
			List<double> l = new List<double>(op.Parties);
			l.Sort();

			for(int i=l.Count-1; i>=0; i--)
			{
				partialOP.Volume = op.Volume.Value * l[i] / sum;
				partialOP.Comment = string.Format("{0}-{1}",partialOP.Comment,i);

				robot.executeOrder(partialOP);
			}

		}
Example #7
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="tradeType"></param>
		/// <param name="volume"></param>
		/// <param name="label"></param>
		public static void executeOrder(this Robot robot, OrderParams op)
		{
			if (op==null)
				throw new System.ArgumentException(String.Format("parameter 'op' must be non null", op));
			if (op.Volume <= 0)
				throw new System.ArgumentException(String.Format("parameter 'op.Volume' must be strictly positive", op.Volume));
			if (!op.TradeType.HasValue)
				throw new System.ArgumentException(String.Format("parameter 'op.TradeType' must have a value", op.TradeType));


			// it is necessary that the volume is a multiple of "microvolume".
			long v = robot.Symbol.NormalizeVolume(op.Volume.Value, RoundingMode.ToNearest);

			if (v > 0)
			{
				var result = robot.ExecuteMarketOrder(op.TradeType.Value, op.Symbol, v, op.Label, op.StopLoss, op.TakeProfit, op.Slippage, op.Comment);
				if (!result.IsSuccessful)
					robot.Print("error : {0}, {1}", result.Error, v);
			}
		}
Example #8
0
		public OrderParams(OrderParams op) : this(op.TradeType,op.Symbol,op.Volume,op.Label,op.StopLoss,op.TakeProfit, op.Slippage, op.Comment, op.Id,op.Parties){}
Example #9
0
        /// <summary>
        /// 
        /// </summary>
        protected override void OnStart()
        {
            base.OnStart();

            double slippage = 2;
            // maximum slippage in point, if order execution imposes a higher slippage, the order is not executed.

            _botName = ToString();
            _instanceLabel = string.Format("{0}-{1}-{2}-{3}", _botName, _botVersion, Symbol.Code, TimeFrame.ToString());
            string positionComment = string.Format("{0}-v{1}", _botName, _botVersion);

            // order label passed by the bot
            initialOP = new OrderParams(null, Symbol, InitialVolume, _instanceLabel, StopLoss, TakeProfit, slippage, positionComment, null, new List<double> 
            {
                5,
                3,
                2
            });

            Positions.Closed += OnPositionClosed;

            strategies = new List<Strategy>();

            if (IsZZKwanActif)
                strategies.Add(new ZigZagKwanStrategy(this, MbfxLen, MbfxFilter));

            if (IsWPRActif)
                strategies.Add(new WPRSStrategy(this, WprSource, WprPeriod, WprOverbuyCeil, WprOversellCeil, WprMagicNumber, WprMinMaxPeriod, WprExceedMinMax));

            if (IsDCActif)
                strategies.Add(new DoubleCandleStrategy(this, DoubleCandleFineness));

            if (IsZZActif)
                strategies.Add(new ZigZagStrategy(this, ZzDepth, ZzDeviation, ZzBackStep));

            if (IsTMActif)
                strategies.Add(new TrendMagicStrategy(this, TMCciPeriod, TMAtrPeriod));
        }
Example #10
0
        /// <summary>
        /// 
        /// </summary>
        protected override void OnStart()
        {
            base.OnStart();

			_botName = ToString();
			_instanceLabel = string.Format("{0}-{1}-{2}-{3}", _botName, _botVersion, Symbol.Code, TimeFrame.ToString());

            double slippage = 2;
            // maximum slippage in point, if order execution imposes a higher slippage, the order is not executed.

			string positionComment = string.Format("{0}-v{1}", _botName, _botVersion);
            ;
            // order label passed by the bot
            initialOP = new OrderParams(null, Symbol, InitialVolume, _instanceLabel, StopLoss, TakeProfit, slippage, positionComment, null, new List<double> 
            {
                5,
                3,
                2
            });

            strategies = new List<Strategy>();
            strategies.Add(new ArgunesStrategy(this));
        }