Replies

PanagiotisCharalampous
26 Nov 2019, 08:24

Hi Mr4x,

See below

            if (Positions.Where(x => x.TradeType == TradeType.Sell).Sum(p => p.NetProfit) > 150)
            {
                foreach (var position in Positions.Where(x => x.TradeType == TradeType.Sell))
                {
                    ClosePosition(position);
                }
            }

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
25 Nov 2019, 16:45

Hi Mr4x,

See below an example of how to check for Net Profit on sell positions only

            if (Account.Equity >= Account.Balance + Positions.Where(x => x.TradeType == TradeType.Sell).Sum(p => p.NetProfit))
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);
                }
            }

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
25 Nov 2019, 10:10

Hi Anonymous,

Please use the Suggestions section for suggestions.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
25 Nov 2019, 10:06

Hi chernish2,

It is not possible at the moment but new methods will be introduced in 3.7 that will allow you to do that.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
25 Nov 2019, 09:56

Hi edoardo.ferretto99,

I would suggest to check the current suggestions before posting a new one. The suggestion for cTrader Desktop on Mac exists and it has a lot of votes as well. There is no point of creating a another one.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
25 Nov 2019, 09:45

Hi hackmushroom,

DrawRectangle and generally all Draw methods take DateTime type as input for the X axis. So to achieve what you need, you need to plot the rectangle x dimensions on the exact time the bars starts/ends e.g. the h1 bar is drawn at approximately -25/+25 minutes.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
25 Nov 2019, 09:04

Hi clauberthsb,

We will need more information in order to help you. Do you run any custom cBots/indicators? Do you have any drawings on the chart? If yes, does the situation improve if you remove/stop all these added components?

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
25 Nov 2019, 08:49

Hi Nick,

Index is just an array index, nothing more. Since MarketSeries from different timeframes might have values for different times on the same index, you need to map the index of one Market series to the other. This is achieved with the following method

gbpusd.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index])

In this case, the method gets the opening time at an index of the current MarketSeries and returns the index for the same time for the gbpusd market series.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
22 Nov 2019, 15:06

Hi Nick,

The symbol is hardcoded

var gbpusd = MarketData.GetSeries("GBPUSD", Frame);

Do you change that before running on GBPJPY?

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
22 Nov 2019, 14:47

Hi Nick,

Can you please explain to us what is the problem? What did you expect to happen and what happens instead?

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
22 Nov 2019, 10:26

Hi Patrick,

See here.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
22 Nov 2019, 09:06

Hi Robert,

It in not a this way vs the other way case. It is just an extra feature that is missing. While we understand that this is a handy feature for traders, by adding this will we will have to load the server with even more tasks i.e. checking all positions if and when should the TSL kick in, which translates into having to allocate more resources on our side. It always boils down to finding the balance between features and efficiency. And since this is an easy feature to be programmed into a cBot and be managed on the client side, we chose not to include it as a built in feature for the moment. 

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
22 Nov 2019, 08:50

Hi all, 

This is coming in 3.7. Check here.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
22 Nov 2019, 08:46

Hi Samuel,

This happens because you are using the actual price as a stop loss. Stop loss should be set in pips instead.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
22 Nov 2019, 08:38

Hi chernish2,

You can save it as a default template.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
22 Nov 2019, 08:35

Hi Robert,

There is no such feature or plans at the moment.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
21 Nov 2019, 16:23 ( Updated at: 21 Dec 2023, 09:21 )

RE: RE:

robert.vanderlaan said:

Spotware said:

Dear Trader,

The Trailing Stop Loss now resides on the server, it works when cTrader is closed. You can apply it when creating an order. It has also been simplified, please enter the number of pips it should trail the spot price for, and it will move every pip.

 

Hi,

 

Are there any plans to have actual settings for the trailing SL, separate from the regular SL (as the whole point is with this,
as somebody explained in their example. So the trailing SL gets triggered once the regular SL price or % or pips change is hit)?

Right now, you have trailing giant stoploss at the size of your regular stoploss as there's only 1 stoploss setting..

 

Hi Robert,

We do not have such plans at the moment.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
21 Nov 2019, 14:33 ( Updated at: 21 Dec 2023, 09:21 )

Hi Eduardo_Cerejo,

Right click on your chart, go to Viewing Options > Deal Map and uncheck it. See below

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
21 Nov 2019, 12:01

Hi Jan,

See the example below

// -------------------------------------------------------------------------------------------------
//
//    This robot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk
//
//    The "Trailing Stop Loss Sample" Robot places a Buy or Sell Market order according to user input.  
//    When the order is filled it implements trailing stop loss.
//
// -------------------------------------------------------------------------------------------------

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 TrailingStopLossSample : Robot
    {
        [Parameter("Volume", DefaultValue = 1000)]
        public int Volume { get; set; }
        [Parameter("Buy")]
        public bool Buy { get; set; }
        [Parameter("Stop Loss", DefaultValue = 5)]
        public double StopLoss { get; set; }
        [Parameter("Trigger When Gaining", DefaultValue = 1)]
        public double TriggerWhenGaining { get; set; }
        [Parameter("Trailing Stop Loss Distance", DefaultValue = 1)]
        public double TrailingStopLossDistance { get; set; }
        [Parameter("Step (pips)", DefaultValue = 5)]
        public double Step { get; set; }

        private double _highestGain;
        private bool _isTrailing;

        protected override void OnStart()
        {
            //Execute a market order based on the direction parameter
            ExecuteMarketOrder(Buy ? TradeType.Buy : TradeType.Sell, Symbol, Volume, "SampleTrailing", StopLoss, null);
            //Set the position's highest gain in pips
            _highestGain = Positions[0].Pips;
        }

        protected override void OnTick()
        {
            var position = Positions.Find("SampleTrailing");

            if (position == null)
            {
                Stop();
                return;
            }
            //If the trigger is reached, the robot starts trailing
            if (position.Pips >= TriggerWhenGaining)
            {         
                //Based on the position's direction, we calculate the new stop loss price and we modify the position
                if (position.TradeType == TradeType.Buy)
                {
                    var newSLprice = Symbol.Ask - (Symbol.PipSize * TrailingStopLossDistance);
                    if (newSLprice > position.StopLoss)
                    {
                        ModifyPosition(position, newSLprice, null);
                    }
                }
                else
                {
                    var newSLprice = Symbol.Bid + (Symbol.PipSize * TrailingStopLossDistance);
                    if (newSLprice < position.StopLoss)
                    {
                        ModifyPosition(position, newSLprice, null);
                    }
                }
                TriggerWhenGaining += Step;
            }
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
21 Nov 2019, 10:21

Hi Ton,

Are there any steps to reproduce this behavior?

Best Regards,

Panagiotis


@PanagiotisCharalampous