2 stoploss and takeprofit

Created at 19 Oct 2012, 12:48
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

2 stoploss and takeprofit
19 Oct 2012, 12:48


hello
I want to know if he can put 2 different TakeProfit and stoploss.

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

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

        [Parameter("Take Profit", DefaultValue = 5)]

        public int TakeProfit { get; set; }

 

 protected override void OnStart()

ExecuteOrder(InitialVolume, TradeType.Sell);

    ......................................................................................................


 
         private double GetAbsoluteStopLoss(Position position, int StopLoss)
        {
           return position.TradeType == TradeType.Buy
                ? position.EntryPrice - Symbol.PipSize * StopLoss
                : position.EntryPrice + Symbol.PipSize * StopLoss;
              } 
       
        private double GetAbsoluteTakeProfit(Position position, int takeProfit)
        {
            return position.TradeType == TradeType.Buy
                ? position.EntryPrice + Symbol.PipSize * TakeProfit
                : position.EntryPrice - Symbol.PipSize * TakeProfit;
                }
}
}

or

 protected override void OnPositionOpened(Position openedPosition)
        {
             if(openedPosition.TradeType==TradeType.Buy)
             Trade.ModifyPosition(openedPosition,Symbol.Ask-StopLoss*Symbol.PipSize,Symbol.Ask+TakeProfit*Symbol.PipSize);
            if(openedPosition.TradeType==TradeType.Sell)
             Trade.ModifyPosition(openedPosition,Symbol.Bid+StopLoss*Symbol.PipSize,Symbol.Bid-TakeProfit*Symbol.PipSize);
         position = openedPosition;

____________________________________________________________________________________________________

I would for example:

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

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

        [Parameter("Take Profit", DefaultValue = 5)]

       public int TakeProfit { get; set; }

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

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

        [Parameter("Take Profit", DefaultValue = 10)]

       public int TakeProfitInPips { get; set; }

protected override void OnStart()

ExecuteOrder(InitialVolume, TradeType.Sell); ................(initialvolume 10000..stoploss 5...takeprofit  5)

ExecuteOrder(Volume, TradeType.Sell); ................(volume 20000.........stoplossInPips 10  takeprofitInPips  10 )

even combining (volume ... initialvolume) or (take profit .. takeprofitInPips) .......
I end up having toujour 2 trades with stop loss and take profit identical

thank you

 

 

 

 

 

 


@tradermatrix
Replies

admin
19 Oct 2012, 13:20

You can define as many parameters as you like but you have to make sure to reference them by their unique name.

The stop loss and take profit are not passed in to the ExecuteOrder function. Only volume and trade type.

 

ExecuteOrder(InitialVolume, TradeType.Sell);

ExecuteOrder(Volume, TradeType.Sell);

 

Trade.ModifyPosition is the method that modifies stop loss and take profit. Therefore OnPositionOpened is what needs to be modified.

You probably need to have an if statement to check the volume of the position.

 

        protected override void OnPositionOpened(Position openedPosition)
        {
            if (openedPosition.Volume == InitialVolume)
            {
                if (openedPosition.TradeType == TradeType.Buy)
                    Trade.ModifyPosition(openedPosition, Symbol.Ask - StopLoss*Symbol.PipSize,
                                         Symbol.Ask + TakeProfit*Symbol.PipSize);

                else if (openedPosition.TradeType == TradeType.Sell)
                    Trade.ModifyPosition(openedPosition, Symbol.Bid + StopLoss*Symbol.PipSize,
                                         Symbol.Bid - TakeProfit*Symbol.PipSize);
                
            }

            else
            {
                if (openedPosition.TradeType == TradeType.Buy)
                    Trade.ModifyPosition(openedPosition, Symbol.Ask - stoplossInPips * Symbol.PipSize,
                                         Symbol.Ask + takeprofitInPips * Symbol.PipSize);

                else if (openedPosition.TradeType == TradeType.Sell)
                    Trade.ModifyPosition(openedPosition, Symbol.Bid + stoplossInPips * Symbol.PipSize,
                                         Symbol.Bid - takeprofitInPips * Symbol.PipSize);
                
            }
            position = openedPosition;
        }



 

 

 


@admin

tradermatrix
19 Oct 2012, 16:00

thank you very much


@tradermatrix