Take Profit

Created at 29 May 2015, 11:52
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!
96

9607367

Joined 15.03.2015

Take Profit
29 May 2015, 11:52


I want to reduce "Take Profit" if the loss.

Please tell me how it will look this condition:

 

If a loss then "Take Profit" / 2


@9607367
Replies

tradermatrix
31 May 2015, 16:45

RE:

9607367 said:

I want to reduce "Take Profit" if the loss.

Please tell me how it will look this condition:

 

If a loss then "Take Profit" / 2

hello
 like that;

 
        [Parameter(DefaultValue = 20)]
        public double TakeProfit1 { get; set; }

       [Parameter(DefaultValue = 10)]
        public double TakeProfit2 { get; set; }

       

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

  private void OnPositionsClosed(PositionClosedEventArgs args)
        {


            if (takeprofit2 == true)
            {

                Print("Closed");

                var position = args.Position;

                if (position.Label != label || position.SymbolCode != Symbol.Code)
                    return;




                if (position.GrossProfit < 0)
                {




                    ExecuteMarketOrder(position.TradeType, Symbol, Volume , label, StopLoss, TakeProfit2);
                }

            }
        }

if you want the operation is only performed just once;
we must add label2.

exemple;

 private const string label1 = "Sample Trend cBot";

private const string label2 = "TakeProfit 2";

      ExecuteMarketOrder(position.TradeType, Symbol, Volume , label2, StopLoss, TakeProfit2);

 

 


 if you have a problem, write your code I would correct you.


 cordially


@tradermatrix

9607367
31 May 2015, 20:41

RE: RE:

Thank you very much tradermatrix! I will test

9607367 said:

I want to reduce "Take Profit" if the loss.

Please tell me how it will look this condition:

 

If a loss then "Take Profit" / 2

hello
 like that;

 
        [Parameter(DefaultValue = 20)]
        public double TakeProfit1 { get; set; }

       [Parameter(DefaultValue = 10)]
        public double TakeProfit2 { get; set; }

       

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

  private void OnPositionsClosed(PositionClosedEventArgs args)
        {


            if (takeprofit2 == true)
            {

                Print("Closed");

                var position = args.Position;

                if (position.Label != label || position.SymbolCode != Symbol.Code)
                    return;




                if (position.GrossProfit < 0)
                {




                    ExecuteMarketOrder(position.TradeType, Symbol, Volume , label, StopLoss, TakeProfit2);
                }

            }
        }

if you want the operation is only performed just once;
we must add label2.

exemple;

 private const string label1 = "Sample Trend cBot";

private const string label2 = "TakeProfit 2";

      ExecuteMarketOrder(position.TradeType, Symbol, Volume , label2, StopLoss, TakeProfit2);

 

 


 if you have a problem, write your code I would correct you.


 cordially

 


@9607367