martingale

Created at 11 Nov 2013, 17:32
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!
TR

tradermatrix

Joined 24.07.2012

martingale
11 Nov 2013, 17:32


bonjour
pouvez vous m' aider.
je voudrais rajouter une formule pour cette martingale.
une martingale classique double le volume à l infinie(jusqu à obtenir le gain)
je pose donc un levier qui me permet de doubler le nombre de fois désiré.
le probleme avec ma martingale c est que si je regle par exemple:
[Martingale Levels 1 .volume 10000]
si le trade est perdant le volume double normalement [20000]
mais si le trade est de nouveau perdant le trade de [20000]revient plusieurs fois(jusqu'à obtenir le take-profit)


mon désire: le volume maxi(réglé par le levier)s éxécute une seule fois(meme si le trade est perdant)

par exemple.
[Martingale Levels : 2 .volume :10000]
trade initial 10000 puis 20000 puis 40000 fini(stoploss touché ,plus de retour) .


cordialement

 

hello
can you help me '.
I would like to add a formula to this martingale.
a classic martingale doubles the volume to infinity (up to get gain)
So I put a lever that allows me to double the desired number of times.
the martingale problem with my c rule is that if I, for example:
[1 lever. volume 10000]
if the trade is losing doubles the volume normally [20000]
but if the trade is again losing the trade of [20000] back several times (until the take-profit)
my desire: the maximum volume (set by the lever) s executes only once (even if the trade is a loser)
for example:
[levier2. volume 10000]
initial trade 10000 and 20000 and 40000 finished (stoploss affected more back).


cordially

 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  [Parameter("Martingale Levels", DefaultValue = 1, MinValue = 0, MaxValue = 10)]
        public int MartingaleMax { get; set; }
   [Parameter("Martingale Reverse", DefaultValue = false)]
        public bool MartingaleReverse { get; set; }

 private int MartingaleLevel = 0;

  private int BuyVolume = 0, Count = 0, TakeProfit = 0;

 protected override void OnPositionOpened(Position openedPosition)
        {
            position = openedPosition;
        }

        protected override void OnPositionClosed(Position closedPosition)
        {
            switch (closedPosition.TradeType)
            {
                case TradeType.Buy:
                    LongPositions--;
                    break;
                case TradeType.Sell:
                    ShortPositions--;
                    break;
            }

            if (MartingaleMax > 0 && MartingaleLevel < MartingaleMax)
            {

                BuyVolume = BuyVolume * 2;
                MartingaleLevel++;

            }

            if (closedPosition.GrossProfit < 0)
            {
                switch (closedPosition.TradeType)
                {
                    case TradeType.Buy:




                        if (MartingaleMax > 0)
                        {

                            if (MartingaleReverse == true)
                            {
                                TakeProfit = (int)(closedPosition.Pips / -1);
                                Request request = new MarketOrderRequest(TradeType.Sell, BuyVolume) 
                                {
                                    Label = "777",
                                    SlippagePips = Slippage,
                                    StopLossPips = StopLoss,
                                    TakeProfitPips = TakeProfit
                                };

                                Trade.Send(request);

                            }
                            else
                            {
                                TakeProfit = (int)(closedPosition.Pips / -1);
                                Request request = new MarketOrderRequest(TradeType.Buy, BuyVolume) 
                                {
                                    Label = "777",
                                    SlippagePips = Slippage,
                                    StopLossPips = StopLoss,
                                    TakeProfitPips = TakeProfit
                                };


                                Trade.Send(request);
                            }

                        }

                        break;

                    case TradeType.Sell:



                        if (MartingaleMax > 0)
                        {
                            if (MartingaleReverse == true)
                            {
                                TakeProfit = (int)(closedPosition.Pips / -1);
                                Request request = new MarketOrderRequest(TradeType.Buy, BuyVolume) 
                                {
                                    Label = "777",
                                    SlippagePips = Slippage,
                                    StopLossPips = StopLoss,
                                    TakeProfitPips = TakeProfit
                                };
                                Trade.Send(request);


                            }
                            else
                            {
                                TakeProfit = (int)(closedPosition.Pips / -1);
                                Request request = new MarketOrderRequest(TradeType.Sell, BuyVolume) 
                                {
                                    Label = "777",
                                    SlippagePips = Slippage,
                                    StopLossPips = StopLoss,
                                    TakeProfitPips = TakeProfit
                                };


                                Trade.Send(request);
                            }
                        }

                        break;
                }
            }
            else
            {
                MartingaleLevel = 0;
                BuyVolume = TradeVolume;
            }
        }

 


@tradermatrix
Replies

jeex
12 Nov 2013, 22:49

martingale

The second best way for using martingale is not simply by doubling the lots, but by calculating the needed lots in relation to the TakeProfit of the next trade. You should also build in a stop when the StopLoss of the next trade would eventually cost too much.

The best way for using martingale is not to use it. It's very tempting, but very risky as well.


@jeex

tradermatrix
18 Dec 2013, 12:40

thank you
in this formula;
    BuyVolume =BuyVolume *  2;
                  MartingaleLevel + +;
the formula doubles the volume to infinity (up to get gain)
I would like to double that once.(even if the trade is a loser)
can you help me.

cordially


@tradermatrix

jeex
18 Dec 2013, 13:58

BackOnBalence

In stead of Martingale youcould use a Back On Balance algorithm., that keeps track of the highest balance and tries to get back to that balance after a loss.

private double HighestBalance = 0;
protected override void OnPositionClosed(...)
{
   ...
   HighestBalance = Math.Max(Account.Balance, HighestBalance);
}

The method for calculating a new balance then must calculate the volume based on the takeprofit of the next trade.

private long BackOnBalance(double needed, int takeprofit)
{
    double loss = needed - Account.Balance;

    // if On Balance return VolumeMin or a fixed Min Lot.
    if (needed == 0 || loss <= 0)
    {
        return Symbol.VolumeMin;
    }
    else
    {
        double singlelotprofit = Symbol.PipValue * takeprofit;
        return Symbol.NormalizeVolume(loss / singlelotprofit);
    }
}

When opening a trade:

var result = ExecuteMarketOrder(TradeType.Buy, Symbol, BackOnBalance(HighestBalance, TP), Label, SL, TP);

This way a winning trade always gets you back on track at minimum risk.

Speaking of risk: you should ad some risk management to it, as well as checking if the lot size fits within the margin. And i'm not sure if Symbol.PipValue gives the value of a pip in Base Currency or in Account Currency. In that case, you should convert the singlelotprofit to you account currency.

NOT TESTED and of course it needs some fine tuning, but this one should get you going.

Last but not least: intensive testing should learn you that it is way better to invest time in good trading strategies than in Martingale strategies, because in the end, Martingale and all methodes derived from Martingale will cost you all your money.


@jeex

tradermatrix
19 Dec 2013, 17:46

thank you for these explanations
I will try to apply your method on my robots
cordially


@tradermatrix