RickyMoney

by ripupo88 in category Range at 08/09/2017
Description

You must try different parameters up to take profit. The main idea of this robot is put a smaller take profit and a bigger stop lost, always betting on the rebound after each new bar.

Range market: hight profits
Trend market: Very high losses

Risk: hight

Download
114 downloads
How to install
Warning! Executing the following cBot may result in loss of funds. Use it at your own risk.
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgo
// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API sample.
//
//    This cBot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk
//
//    The "Sample Martingale cBot" creates a random Sell or Buy order. If the Stop loss is hit, a new 
//    order of the same type (Buy / Sell) is created with double the Initial Volume amount. The cBot will 
//    continue to double the volume amount for  all orders created until one of them hits the take Profit. 
//    After a Take Profit is hit, a new random Buy or Sell order is created with the Initial Volume amount.
//
// -------------------------------------------------------------------------------------------------

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 RickyMoney : Robot
    {
        [Parameter("Initial Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double InitialQuantity { get; set; }

        [Parameter("SL", DefaultValue = 20)]
        public int StopLoss { get; set; }

        [Parameter("TP", DefaultValue = 20)]
        public int TakeProfit { get; set; }
        int newprofit;

        private Random random = new Random();
        bool ganada;
        bool compra;
        bool permiso;

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;
            newprofit = TakeProfit;

            ExecuteOrder(InitialQuantity, GetRandomTradeType(), StopLoss, TakeProfit);
        }

        private void ExecuteOrder(double quantity, TradeType tradeType, int stop, int take)
        {

            var volumeInUnits = Symbol.QuantityToVolume(quantity);
            var result = ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, "Robot", stop, take);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            permiso = true;
            Print("Closed");
            var position = args.Position;

            if (position.Label != "Robot" || position.SymbolCode != Symbol.Code)
                return;
            if (position.NetProfit > 0)
            {
                ganada = true;
                if (position.TradeType == TradeType.Buy)
                {
                    compra = true;
                }
                else
                {
                    compra = false;
                }
            }
            else
            {
                ganada = false;
                if (position.TradeType == TradeType.Buy)
                {
                    compra = true;
                }
                else
                {
                    compra = false;
                }
            }
        }

        protected override void OnBar()
        {
            if (permiso)
            {
                permiso = false;
                if (ganada)
                {
                    newprofit = TakeProfit;
                    if (compra)
                    {
                        ExecuteOrder(InitialQuantity, TradeType.Sell, StopLoss, TakeProfit);
                    }
                    else
                    {
                        ExecuteOrder(InitialQuantity, TradeType.Buy, StopLoss, TakeProfit);
                    }
                }
                else
                {
                    if (compra)
                    {

                        ExecuteOrder(InitialQuantity, TradeType.Buy, StopLoss / 1, newprofit);
                    }
                    else
                    {
                        ExecuteOrder(InitialQuantity, TradeType.Sell, StopLoss / 1, newprofit);
                    }
                }
            }
        }

        private TradeType GetRandomTradeType()
        {
            return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
        }
    }
}
Comments
0