Help me please. I need code when positon hit stoploss robot just wait 24 hours and return to next trade.

Created at 14 Nov 2023, 04:02
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!
MA

maxxx2532

Joined 11.10.2023

Help me please. I need code when positon hit stoploss robot just wait 24 hours and return to next trade.
14 Nov 2023, 04:02


Help me please. I need code when positon hit stoploss robot just wait 24 hours and return to next trade. Thank you.

 


@maxxx2532
Replies

PanagiotisCharalampous
14 Nov 2023, 07:01

Hi there,

Here is some code to start with

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class NewcBot2 : Robot
    {
        DateTime _lastStopLoss;

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

        private void Positions_Closed(PositionClosedEventArgs obj)
        {
            if(obj.Reason == PositionCloseReason.StopLoss) 
            {
                _lastStopLoss = Server.Time;
            }
        }

        protected override void OnTick()
        {
            if(_lastStopLoss.AddHours(24) > Server.Time) 
            {
                // Trade
            }
        }

        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}

@PanagiotisCharalampous