Martingale type robot

Created at 28 Apr 2015, 17:49
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!
HY

hypertrader

Joined 20.04.2015

Martingale type robot
28 Apr 2015, 17:49


Hi, I think this will be a Martingale type robot.

 

When I start the robot I want to be able to choose buy/sell, volume and TP/SL.

 

Take for example a 10K buy order with 30 pip SL and 30pip TP.

If TP is reached I want the robot to take no further action.

 

If SL is hit I want the robot to open a double volume in the opposite direction. (eg 20K sell with 30pip SL and 30pip TP.)

I want this to repeat doubling until TP is finally reached.

 

Any ideas peeps?

 

Andy


@hypertrader
Replies

oktrader
28 Apr 2015, 18:59

RE:

Hi Andy, 

take a look at this : /algos/cbots/show/3


@oktrader

hypertrader
28 Apr 2015, 19:16

Thanks, almost what I'm looking for.

I'll have a tinker, just need to change

i) The initial buy/sell from random to chosen.

ii) If stop loss is hit robot will double position in opposite direction.

iii) Robot opens no further trades after TP is hit.


@hypertrader

hypertrader
28 Apr 2015, 21:05

I'm not a programmer but I'm thinking.

i) I need to change the "GetRandomTradeType" to solve the first part of my problem:

 

           protected override void OnStart()

           {

                    Positions.Closed += OnPositionsClosed;

 

                    ExecuteOrder(InitialVolume, GetRandomTradeType());

            }

 

 


@hypertrader

tradermatrix
28 Apr 2015, 22:49

RE:

hypertrader said:

Hi, I think this will be a Martingale type robot.

 

When I start the robot I want to be able to choose buy/sell, volume and TP/SL.

 

Take for example a 10K buy order with 30 pip SL and 30pip TP.

If TP is reached I want the robot to take no further action.

 

If SL is hit I want the robot to open a double volume in the opposite direction. (eg 20K sell with 30pip SL and 30pip TP.)

I want this to repeat doubling until TP is finally reached.

 

Any ideas peeps?

 

Andy

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

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

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

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

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

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

        [Parameter("Take Profit", DefaultValue = 40)]
        public int TakeProfit { 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", StopLoss, TakeProfit);

            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)

                Stop();


            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, position.TradeType);


            }


            else
            {

                ExecuteOrder((int)position.Volume * Multiplier, position.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy);


            }
        }
    }
}
 



bon trade


@tradermatrix

hypertrader
29 Apr 2015, 11:20

Wow tradermatrix, thanks a lot. Multiplier feature is a great added bonus too.

Works really well in a volatile market and with support/resistance. Means I can get my life back instead of staring at a screen.

Do you have a paypal email, I'd like to send you a gift.

 

Kindest Regards

 

Andy


@hypertrader

tradermatrix
29 Apr 2015, 12:38

RE:

hypertrader said:

Wow tradermatrix, thanks a lot. Multiplier feature is a great added bonus too.

Works really well in a volatile market and with support/resistance. Means I can get my life back instead of staring at a screen.

Do you have a paypal email, I'd like to send you a gift.

 

Kindest Regards

 

Andy

Andy hello
I am glad that this robot suits you.
my paypal email address is in my profile.
I have tested the robot last night in the demo, the idea is good, and I'll use the real account.
cordially
Marc


@tradermatrix

hypertrader
29 Apr 2015, 13:23

Smashing, I find it is best with JPY crosses that move 100+ pips a day, I like to manually enter when the market has made a large move or pull back and sell high/buy low.

 

It's also quite good for trading triangles like on a 1hr to 4hr chart. I'm using a 30pip SL and a 33 pip TP.

 

Thanks again.

 

Andy


@hypertrader