Market order and Limit order at the same time

Created at 26 Jul 2019, 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!
KH

khongkhongaaa

Joined 26.07.2019

Market order and Limit order at the same time
26 Jul 2019, 12:48


When RSI reaches 30 or below:

Open 1 Sell Trade & 3 Sell Limit Orders, at the same time.

Ex:

Open a Buy Position volume 10,000 (SL 40pips TP 10pips), and also

10 pips below the opened position, Place 1st Buy Limit Order volume 10,000  (SL 30pips TP 10pips), and also

20 pips below the opened position, Place 2nd Buy Limit Order volume 20,000  (SL 20pips TP 10pips), and also

30 pips below the opened position, Place 3rd Buy Limit Order volume 40,000   (SL 10pips TP 10pips).

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 SampleRSIcBot : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }
 
        [Parameter("Periods", DefaultValue = 14)]
        public int Periods { get; set; }
 
        [Parameter("Volume", DefaultValue = 10000)]
        public double Quantity { get; set; }
 
        private RelativeStrengthIndex rsi;
 
        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
        }
 
        protected override void OnTick()
        {
            if (rsi.Result.LastValue < 30)
            {
                Open(TradeType.Buy);
 
                PlaceLimitOrder(TradeType.Buy, Symbol, 10000, Symbol.Ask + 10 * Symbol.PipSize, "BuyLimit1", 30, 10);
 
                PlaceLimitOrder(TradeType.Buy, Symbol, 20000, Symbol.Ask + 20 * Symbol.PipSize, "BuyLimit2", 20, 10);
 
                PlaceLimitOrder(TradeType.Buy, Symbol, 40000, Symbol.Ask + 30 * Symbol.PipSize, "BuyLimit3", 10, 10);
            }
            private void Open(TradeType tradeType)
            {
            var position = Positions.Find("SampleRSI", SymbolName, tradeType);
            var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);

            if (position == null)
                ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleRSI", 10, 10);
            }
        }
    }
}

But,

The problem is very very very many PendingOrder.

How do I limit PendingOrder? (like ExecuteMarketOrder is limit)


@khongkhongaaa