complete noob. how do i place a buy stop at a specific time

Created at 29 Jan 2020, 15:29
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!
$1

$11119040.96

Joined 16.06.2019

complete noob. how do i place a buy stop at a specific time
29 Jan 2020, 15:29


I wish to place buy and sell stop at a specific time (date hh:mm:ss) and a specific pip distance from whatever the current market price is.

So example the current time could be 13.05;

but i want to set buy+stop entry order on spx

x pips away from the cmp

at 14.30

 

 

does anyone know if this is possible to code?


@$11119040.96
Replies

bishbashbosh
29 Jan 2020, 20:17

You can create a cBot and then override the OnBar method and then within that check if MarketSeries.OpenTime.LastValue is the time you want; if it is, submit your order. 

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.None)]
    public class OrderAtFixedTime : Robot
    {
        [Parameter(DefaultValue = 9)]
        public int Hour { get; set; }

        [Parameter(DefaultValue = 30)]
        public int Minute { get; set; }

        [Parameter(DefaultValue = TradeType.Buy)]
        public TradeType Side { get; set; }

        [Parameter]
        public double Volume { get; set; }

        [Parameter(DefaultValue = 10, MinValue = 0)]
        public double TriggerPipOffset { get; set; }

        [Parameter(DefaultValue = 5, MinValue = 0)]
        public double StopLimitRangePips { get; set; }

        protected override void OnBar()
        {
            var openTime = MarketSeries.OpenTime.LastValue;
            if (openTime.Hour != Hour || openTime.Minute != Minute) 
                return;

            var targetPrice = MarketSeries.Close.LastValue + (Side == TradeType.Buy ? 1 : -1) * TriggerPipOffset * Symbol.PipSize;
            var label = "AUTO_" + SymbolName + "_" + openTime.ToString("s");
            PlaceStopLimitOrder(Side, SymbolName, Volume, targetPrice, StopLimitRangePips, label);
            Stop();
        }
    }
}

 


@bishbashbosh

$11119040.96
04 Feb 2020, 15:52

RE:

thanks bbb!

Fancy compiling some more lines for me?!

Will send you a tip via paypal!!


@$11119040.96