Martingale Robot free

by alexk in category Other at 17/02/2012
Description

This robot is based on the martingale strategy.

This code is a cAlgo API sample.

The "Sample Martingale Robot" 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 robot 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.

13750 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 robot 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
//
//    All changes to this file will be lost on next application start.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
//    The "Sample Martingale Robot" 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 robot 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.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleMartingaleRobot : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
        public int InitialVolume { get; set; }

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

        [Parameter("Take Profit", DefaultValue = 40)]
        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, position.TradeType);
            }
        }

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

anteandrovic - October 23, 2012 @ 11:57

Any one have any comments re: optimal settings for this robot ?

BigStackBully - February 02, 2015 @ 18:45

I made a backtest on...

  • EURCHF M5,
  • 2014 + jan15. 10000 eur
  • Net profit: 7054 eur.
  • Balance DD 30%.

Straight line up. I like it.

But how to upload pictures here??

 

cservenak - February 06, 2015 @ 13:30

can anyone put trailling stop in this bot?

chiripacha - March 28, 2015 @ 21:37

astoundingly good results (to my opinion) with GPDJPY m20, Initial Volume 10000, Stop Loss and Take Profit 40 40, Starting  Balance USD 2000 (on a DEMO Spotware cAlgo). Net Profit starting from 02/03/2015 to 27/03/2015 USD 124,53 means about 6% in less than a month.

 

And that bot is free! What do you think?

 

chiripacha - April 10, 2015 @ 20:26

@cservenak

could you manage to add "trailing stop" to this bot?

vitalikifel - August 07, 2015 @ 12:34

In backtesting this robot works good but in live test sometimes the robot close a trade and somehow doesent open a new one so i need to stop the bot and start it from new.

conny.rosenberg@gmail.com - October 03, 2015 @ 21:23

Some " for dummies" to installl from github to Calgo..?

have clone from github to visual studio..then my knowledge ended:/

 

conny

lkbaghel - December 25, 2015 @ 17:45

I Have angrybird scalping robot converted from MT4 ea, not able to publish here due to some technical issues

similer to this ea check result here. https://www.myfxbook.com/portfolio/fxwinner/1454935 i will try this eawhen reach 1000 $

jumpsolid - April 12, 2016 @ 15:34

I am just starting out backtesting this one >>> very promising! <<<

Short term scalpers will love that one 

ethaneus99 - July 08, 2016 @ 00:01

please add trailing stop - after many attempts of backtest some are amazing some are really crap and result in a loss

Click - August 21, 2016 @ 23:55

Like this bot/strategy, but probably too risky to use a basic version. Trailing stop on this bot is not a good idea I think, since the point is that if one trade goes with loss, the next one will make you go with profit by doubling the volume and so on... So it will be much like gambling :)  Made another version of it and backtested it with profit from december 2012 to august 2016 on tick data with commission 30 (EURUSD in demo account starting capital 5000 USD) :)  Same with 1000 USD january 2016 to august 2016 :)  Still trying to make it work on other currencies with low starting capital though... :D

ctid299233 - February 22, 2017 @ 21:44

Amazing results, but don't really like the random trades. Does anyone have a version to al least take long trades on uptrends, say combined with a MA and short trades on a downtrend?...

Click, care to share your version?

Thanks

bhagya3udana856 - April 05, 2017 @ 09:19

I want to change the Posision multiplying factor from 2 to 2.5. I don't know programming but i changed the 2 in to 2.5 in calgo and compiled after i got two error massage 

1. best overloaded method match for calgo .robot.martingale robot

2. Cannot convert from double to long

Please tell me how to do that

                

Rog2548 - April 10, 2017 @ 21:46

@bhagya3udana856 

Try this: 5 / 2 instead of 2.5

 ExecuteOrder((int)position.Volume * 5 / 2, position.TradeType);

 

ChasBrownTH - May 02, 2017 @ 12:57

I love Martingales, in Backtesting, but not when they eventually trash my Real account, even a tiny one! However overall I have made money, just not as easily as I had hoped, but it is worth exploting, I think?

I also persevere with them, trying to get one of the many variants just right. Thanks for sharing this! ;)

amantalpur007@gmail.com - July 09, 2017 @ 16:58

Please traders help me. I want to add a limit of 4 trades on this bot. What is the code for that ? I'm not a programmer. I want this cbot to double my position 4 times in a row if the trade is loser, after 4 negative trades, i want this bot to start from initial amount with a random trade. What is the code for that ? Please help me. My email is Amantalpur007@gmail.com Believe me, if someone is willing to help me, i shall tell him/her the perfect method of using martingale with 200% per month. I'm not trying to tempt someone. I just want to share with him/her my experience of martingale, if one is willing to listen otherwise please help me. What ever favor you ask for, I'll do it. I need this badly

dleeeq8 - August 24, 2017 @ 06:08

this bot shows false profit because of BUG in: OnPositionsClosed

when you start new trade in OnPositionsClosed backtest just give you false win trade

thats if you use the: m1 bars from servers

in backtest settings

use: tick data from server and you will see a better results not false one from m1 bars

and the results are scary not 1k to milion but milion to zero

Danis - November 09, 2017 @ 00:28

Martingale is just an empirical method. This has nothing to do with the finance theory and science. If you want a real cBot you must find a solution for stop opening positions when the market is in range positions. This can do just if you know financial mathematics. A good example is to use just 3 indicators RSI, Simple Moving Average and Bollinger Band combined with financial mathematics.  I make this with a 90%  winning of trades. You don't need a lot of entries, just the good and surely entries.

ceakuk - March 28, 2018 @ 23:36

@Rog2548 and @bhagya3udana856 

You have to round to the nearest 1000. you can BUY/SELL 1000, 2000 but not 1500

 

(int)(1000*Math.Floor(Position.Volume*2.5/1000))

martinfou@gmail.com - May 26, 2018 @ 19:24

@amantalpur007@gmail.com you can check my code if you want to have a max number of loss in a row

 

https://github.com/martinfou/cAlgo/blob/master/Sources/Robots/MartingaleLimit/MartingaleLimit/MartingaleLimit.cs

 

wetfalls - December 23, 2018 @ 22:47

Hi, C Team,

Happy new year 2019!.  I want to set up this robot to take small profits all day long with many or hundereds of trades though out the day.

When USD/EUR  Closes it automatically switches to Asian markets during night trading. I want to set a automatic system with 5G connectivity to carry out my system night and day.

Kindly let me know the best way to execute it, I have all the hardwares and 5G set just need the C robots tuned to this mission.

Kind Regards

John

 

 

gleisonricci - March 23, 2020 @ 23:55

 

It would be great if you put a moving average to open favorable transactions, that way it would be less risky to bust the account.

ctrader.guru - December 10, 2020 @ 19:04

Add To Reverse on loss trade, good for trend following bad for lateral

 

 

 

// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API sample.
//
//    This robot 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
//
//    All changes to this file will be lost on next application start.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
//    The "Sample Martingale Robot" 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 robot 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.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MartingaleRobot : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 1000, MinValue = 0)]
        public int InitialVolume { get; set; }

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

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

        [Parameter("To Reverse?", DefaultValue = true)]
        public bool ToReverse { 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.NetProfit > 0)
            {
                ExecuteOrder(InitialVolume, position.TradeType);
            }
            else
            {

                TradeType reversed = (position.TradeType == TradeType.Sell) ? TradeType.Buy : TradeType.Sell;

                ExecuteOrder((int)position.Volume * 2, (ToReverse) ? reversed : position.TradeType);

            }
        }

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

nguyendan81985 - January 08, 2021 @ 05:49

Hi,

 

could you pls make cbot like this:

price close abvove ema20 -->buy position 1. if price go down 20pip, buy position 2, go down 40pips buy 3....., TP if profit > 50u. and the volume for position 1,2,3 is 0.1, 0.2, 0.3 

ctrader.guru - May 06, 2021 @ 10:30

A strategy like this scalper found here Adrenaline with ctrader.guru technology inside, this week special offer, enjoy!

5