Category Trend  Published on 28/06/2023

Tic Tac ! !

Description

TIME YOUR POSITIONS

 

Close your positions after a given amount of time. You can order this cBot to close your deals after 30sec, 3min, 2h... you decide. 


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(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class CloseOldPositionsBot : Robot
    {
        protected override void OnStart()
        {
            CloseOldPositions();
        }

        protected override void OnTick()
        {
            // Check and close old positions on each tick
            CloseOldPositions();
        }

        private void CloseOldPositions()
        {
            foreach (var position in Positions)
            
                         // Feel free to modify the time, can be seconds, hours, days, etc. all you have to do
                         // is deleted addminutes and replace it for your preferred timeframe
            {
                if (position.EntryTime.AddMinutes(1) <= Server.Time)
                {
                    ClosePosition(position);
                }
            }
        }
    }
}


is.villaescusa's avatar
is.villaescusa

Joined on 23.02.2023

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Close positions after a certain amount of time.algo
  • Rating: 0
  • Installs: 487
  • Modified: 26/06/2023 12:01
Comments
Log in to add a comment.
No comments found.