If the previous trade is positive, it doubles the volume

Created at 16 Jul 2017, 20:25
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!
DelFonseca's avatar

DelFonseca

Joined 25.06.2017

If the previous trade is positive, it doubles the volume
16 Jul 2017, 20:25


Hello Everyone,

In 1st place, sorry for my English.

My ideia is that every successful trade, bot double volume of previous trade. If the trade is unseccessful, it returns the inicial volume.

Example:
Trade 1: Buy 0.01 (successful)
Trade 2: Buy 0.02 (successful)
Trade 3: Sell 0.04 (successful)
Trade 4: Buy 0.08 (successful)
Trade 5 Sell 1.16 (unsuccessful)
Trade 6 Buy 0.01 (successful)
(...)

Thank  You
         private void ExecuteStrategy()
        {
            if (!Indicator_ShouldBuy && !Indicator_ShouldSell)
                return;

            var myPositions = Positions.FindAll(label, Symbol);
            if (myPositions.Length > MaxOpenTrades)
            {
                return;
            }
            else
            {

                if (Spread > MaxSpread)
                {
                    return;
                }
            }

            longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            bool nolong = longPosition == null;
            bool noshort = shortPosition == null;

            if (Indicator_ShouldSell)
            {
                if (noshort)
                {
                    ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label, SL, TP);
                }
                else
                {
                    if (parabolic.Result.Last(2) < parabolic.Result.Last(1))
                    {
                        ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label, SL, TP);
                    }
                }
            }
            else if (Indicator_ShouldBuy)
            {
                if (nolong)
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label, SL, TP);
                }
                else
                {
                    if (parabolic.Result.Last(2) > parabolic.Result.Last(1))
                    {
                        ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label, SL, TP);
                    }
                }

            }
        }


@DelFonseca
Replies

DelFonseca
19 Jul 2017, 23:23

         [Parameter("Multiply Lots when Win", DefaultValue = true)]
        public bool MultiplyLotsOnWin { get; set; }

        [Parameter("Max Multiply Lots", DefaultValue = 1)]
        public int MaxMultiplyLots { get; set; }

(...)

         private double _initialQuantity = 0;
        void Positions_Closed(PositionClosedEventArgs obj)
        {
            if (MultiplyLotsOnWin && obj.Position.SymbolCode == Symbol.Code && obj.Position.Label == label)
            {
                if (_initialQuantity == 0)
                    _initialQuantity = Quantity;

                Quantity = (obj.Position.Pips > 0) ? Quantity * 2 : _initialQuantity;
            }
        }


@DelFonseca