About open a market order and limit order at the same time, and close

Created at 31 Jul 2017, 19:42
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!
AL

alpha_austin

Joined 31.07.2017

About open a market order and limit order at the same time, and close
31 Jul 2017, 19:42


Hello there, I'm new here, developing my cBot.

I have a concept and wanna develop it, hope some people and the Spotware team can help.

Here is my thought:

once RSI higher than 70, execute a sell market order and place a few sell limit pending orders at the smae time;

likewhile, once RSI is lower than 30, execute a buy market order and place a few buy limit pending orders at the same time).

Moreover, I wanna add conditions for closing all currents and all pending orders when either order hit TP.

Can someone tell me how to code correctly.

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 RSI_Test : Robot

       [Parameter("Source")]
        public DataSeries Source { get; set; }
 
        [Parameter("Periods", DefaultValue = 14)]
        public int Periods { get; set; }
 
        [Parameter("Volume", DefaultValue = 10000)]
        public int Volume { get; set; }
 
        private RelativeStrengthIndex rsi;
 
        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
        }
 
        protected override void OnTick()
        {
            if (rsi.Result.LastValue >70)
            {
                    ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Position 1", 30, 10);
                    PlaceLimitOrder(TradeType.Sell, Symbol, Volume*2, Symbol.Ask + 10*Symbol.PipSize, "Position 2", 20, 10);
                    PlaceLimitOrder(TradeType.Sell, Symbol, Volume*4, Symbol.Ask + 20*Symbol.PipSize, "Position 3", 10, 10);
            {

           else if (rsi.Result.LastValue > 70)
            {       ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Position 1", 30, 10);
                    PlaceLimitOrder(TradeType.Buy, Symbol, Volume*2, Symbol.Bid - 10*Symbol.PipSize, "Position 2", 20, 10);                                                       PlaceLimitOrder(TradeType.Buy, Symbol, Volume*4, Symbol.Bid - 20*Symbol.PipSize, "Position 3", 10, 10);

 


@alpha_austin