Place re-entry orders with bigger lot size

Created at 04 Sep 2019, 10:19
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!
TO

tomopeov

Joined 18.05.2019

Place re-entry orders with bigger lot size
04 Sep 2019, 10:19


Hi, I have 2 questions here:

1- I'm trying to place re-entry orders(a buy and a sell) once a trade is stopped out but with a 10% increase in lot size.

For example: If I have a EUR/USD 10k sell at 1.10 with SL at 20 pips. If the price reaches 1.1020 I would like to place a sell order of EUR/USD 11k at 1.10 with SL 20 pips and a buy order of EUR/USD 11k at 1.10 with SL 20 pips. How can I do that?

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

        [Parameter("SLRP", DefaultValue = 50)]
        public int stopLimitRangePips { get; set; }

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

        [Parameter("Take Profit", DefaultValue = null)]
        public int TakeProfit { get; set; }

        [Parameter("Volume", DefaultValue = 10000, MinValue = 10000, Step = 1000)]
        public int Volume { get; set; }

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

        private void Positions_Closed(PositionClosedEventArgs obj)
        {
            if (obj.Reason == PositionCloseReason.StopLoss)
            {
                if (obj.Position.TradeType == TradeType.Buy)
                {
                    PlaceStopOrder(TradeType.Sell, Symbol, obj.Position.VolumeInUnits, obj.Position.EntryPrice, "reEntry", StopLoss, TakeProfit);
                    PlaceStopOrder(TradeType.Buy, Symbol, obj.Position.VolumeInUnits, obj.Position.EntryPrice, "reEntry", StopLoss, TakeProfit);
                }
                else
                {
                    PlaceStopOrder(TradeType.Buy, Symbol, obj.Position.VolumeInUnits, obj.Position.EntryPrice, "reEntry", StopLoss, TakeProfit);
                    PlaceStopOrder(TradeType.Sell, Symbol, obj.Position.VolumeInUnits, obj.Position.EntryPrice, "reEntry", StopLoss, TakeProfit);
                }

            }
        }
    }
 

2- Is it possible to close all open trades and orders once the price reaches a certain point?

 

Thanks

 


@tomopeov
Replies

firemyst
18 Sep 2019, 17:09

RE:

tomopeov said:

2- Is it possible to close all open trades and orders once the price reaches a certain point?

Thanks

This one is relatively simple to write pseudo-code (which may work) in a quick few minutes. In your OnTick method, do something similar to:

double closeThreshold = 1.02; //or whatever your price threshold is where you want to close everything

if (Symbol.Ask <= closeThreshold)
{
    CloseEverything(Symbol.Name);
}

Here's the supporting function:

private void CloseEverything(string theSymbol)
{
    foreach (Position p in Positions.FindAll(theSymbol)) //oryou could specify the "label" if you'll be labelling all your positions the same way
                {
                    TradeResult r = p.Close();
                            if (r.IsSuccessful)
                            {
                                Print("Successfully closed position \"{0} {1}\" to true.", p.Id, p.Label);
                            }
                            else if (!r.IsSuccessful)
                            {
                                Print("WARNING! Could not close position \"{0} {1}\"!", p.Id, p.Label);
                                Print("Error message: {0}", r.Error.Value);
                            }
                }
}

 


@firemyst