Martingale Entries Don't Appear to be Truley Random on Sample cBot

Created at 16 Nov 2018, 00:46
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
PR

Promaxx

Joined 05.10.2018

Martingale Entries Don't Appear to be Truley Random on Sample cBot
16 Nov 2018, 00:46


I've been running the cAlgo Sample Martingale cBot on a demo account and have concerns that I'm not seeing true random seeding on the trade entries - i.e. series after series of abnormally long sequences of the same valence of trade, followed by unusually long sequences in the opposite direction. I'm seeing this both in the traded positions and in the backtesting data. Does this bot have true random seeding, or have I missed something? Any insights would be much appreciated.


@Promaxx
Replies

tradermatrix
16 Nov 2018, 20:08

effectively...the robot is built for a first random order ... then it stays in the same direction ... and it leads to disaster if you are in the wrong direction for a long time.
test this one ... it is completely random.
Warning ... you will never do the same backtesting
cordially

// -------------------------------------------------------------------------------------------------
//
//    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 SampleMartingalecBot : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
        public int InitialVolume { get; set; }

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

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

        private Random random = new Random();

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

            ExecuteOrder(InitialVolume, GetRandomTradeType());
        }

        private void ExecuteOrder(long volume, TradeType tradeType)
        {
            var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit);

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

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

            if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code)
                return;

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, GetRandomTradeType());
            }
            else
            {
                ExecuteOrder((int)position.Volume * 2, GetRandomTradeType());
                //
            }
        }

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

 


@tradermatrix

Promaxx
16 Nov 2018, 21:44

RE:

Many thanks Marc - some homework for the weekend, and I'll fire it up on monday and post an update. Thanks again 

 

tradermatrix said:

 


@Promaxx

GammaQuant
23 Nov 2018, 20:30

I suppose every trader needs to go through the "Martingale" stage in there trading journey as a rites of passage..........


@GammaQuant