distance Multiplier martingale

Created at 18 May 2015, 20:10
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

distance Multiplier martingale
18 May 2015, 20:10


hello
in my martingale system I would increase with the volume the SL and TP. (with distanceMultiplier)
in my example I make a mistake.
SL and TP increases once.
somebody t it a solution?
cordially.
 


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 PositioNX : Robot
    {

        [Parameter("Start  ACHETER ", DefaultValue = false)]
        public bool Buy { get; set; }

        [Parameter("Start  VENDRE ", DefaultValue = true)]
        public bool Sell { get; set; }

        [Parameter("InitialVolume", DefaultValue = 10000, MinValue = 0)]
        public int InitialVolume { get; set; }

        [Parameter("SL And TP", DefaultValue = 5)]
        public double SLTP { get; set; }

        [Parameter("Multiplier", DefaultValue = 1.5)]
        public double Multiplier { get; set; }

        [Parameter("distance Multiplier", DefaultValue = 1.5)]
        public double distanceMultiplier { get; set; }


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

            buy();
            sell();
        }
        private void buy()
        {

            if (Buy == true)
            {



                ExecuteOrder(InitialVolume, TradeType.Buy);

            }
        }
        private void sell()
        {

            if (Sell == true)
            {


                ExecuteOrder(InitialVolume, TradeType.Sell);


            }
        }

        private void ExecuteOrder(long volume, TradeType tradeType)
        {

            var result = ExecuteMarketOrder(tradeType, Symbol, volume, "X.inverse", SLTP, SLTP);

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

        }
        private void OnPositionsClosed(PositionClosedEventArgs args)
        {


            Print("Closed");

            var position = args.Position;

            if (position.Label != "X.inverse" || position.SymbolCode != Symbol.Code)
                return;
            if (position.Pips > 0)
                buy();
            if (position.Pips > 0)
                sell();
            if (position.GrossProfit < 0)
            {
                TradeType tt = TradeType.Sell;

                if (position.TradeType == TradeType.Sell)

                    tt = TradeType.Buy;


                ExecuteMarketOrder(tt, Symbol, Symbol.NormalizeVolume(position.Volume * Multiplier), "X.inverse", SLTP * distanceMultiplier, SLTP * distanceMultiplier);
            }
        }
    }
}





 


@tradermatrix
Replies

Spotware
16 Jun 2015, 17:26

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware