Set Stop Loss/Take Profit

admin's avatar

admin since: 30 Nov -0001;

  12 Oct 2012, 10:25
Set Stop Loss/Take Profit

Simple Robot to open a position and modify to set stop loss and take profit.

// -------------------------------------------------------------------------------------------------
//
//    This cBot is an example of executing a market order setting stop loss and take profit
//
// -------------------------------------------------------------------------------------------------

using cAlgo.API;

namespace cAlgo.Robots
{
[Robot]
    public class SimpleRobot : Robot
    {
        [Parameter("Volume", DefaultValue = 10000, MinValue = 0)]
        public int Volume { 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()
        {
            var result = ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "My Label", StopLoss, TakeProfit);
            if(!result.IsSuccessful)
            {
                Print("Stoping cBot due to failure to execute market order");
                Stop();
            }
        }
        
        //...

    }
}
TRADERS FIRSTâ„¢

cprcrack since: 15 Feb 2015;

  16 Feb 2015, 19:29

How can I set only Take Profit or Stop Loss when executing the market order? Should I provide 0 or -1 as parameter or alike?

cprcrack since: 15 Feb 2015;

  16 Feb 2015, 19:52
RE:

cprcrack said:

How can I set only Take Profit or Stop Loss when executing the market order? Should I provide 0 or -1 as parameter or alike?

Oh I just saw it's a nullable type, so I guess the answer is pass null.

kienvu8888 since: 15 Nov 2015;

  24 Apr 2018, 19:39

How can I set Stop Loss or Take Profit with points (1 point = 1/10 pip)? When I try to set SL/TP with a decimal (i.e: 10.3, 25.3, etc.,), it always round the decimal value to nearest integer. So I cannot set SL/TP with more precise price. Can you help me?

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  25 Apr 2018, 09:20

Hi kienvu8888,

Thanks for posting in our forum. Which version of cTrader are you using? This issue has been resolved in cTrader 3.0.

Best Regards,

Panagiotis

Head of Community Management at cTrader

kienvu8888 since: 15 Nov 2015;

  25 Apr 2018, 16:42
RE:

Panagiotis Charalampous said:

Hi kienvu8888,

Thanks for posting in our forum. Which version of cTrader are you using? This issue has been resolved in cTrader 3.0.

Best Regards,

Panagiotis

I'm using ICMarkets cAlgo 2.01. I cannot set the precise SL/TP at the beginning. I must set them with raw value, then modify it right after the order filled.