close all trades at a specific time
close all trades at a specific time
25 Jul 2017, 14:13
Hello, greetings to all
I have searched all over the forum and can not find a solution ...
I need to close all trades at a specific time, for example 8am.
Someone help me?
Thank you very much.
Replies
bolai_6@hotmail.com
25 Jul 2017, 18:18
( Updated at: 21 Dec 2023, 09:20 )
Thanks for answering,
I am not very expert sends me an error.
@bolai_6@hotmail.com
Spotware
26 Jul 2017, 09:23
Dear Trader,
Here is the code for the cBot
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 CloseAllPositions : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { // Put your initialization logic here } protected override void OnTick() { if (DateTime.Now.Hour == 8 && DateTime.Now.Minute == 0) foreach (var position in Positions) { ClosePosition(position); } } protected override void OnStop() { // Put your deinitialization logic here } } }
Best Regards,
cTrader Team
@Spotware
bolai_6@hotmail.com
26 Jul 2017, 14:55
Thank you very much, it works perfect!
Setting the time and everything works fine.
I will continue testing.
@bolai_6@hotmail.com
bolai_6@hotmail.com
28 Jul 2017, 19:48
Hi
I am sorry to say that it stopped working.
I copied the code again.
But nothing, not send any error.
It simply does not close operations.
Any solution or other code?
Thank you very much to all
@bolai_6@hotmail.com
ahadfirdosi
01 Sep 2022, 04:30
RE:
Spotware said:
Dear Trader,
Here is the code for the cBot
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 CloseAllPositions : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { // Put your initialization logic here } protected override void OnTick() { if (DateTime.Now.Hour == 8 && DateTime.Now.Minute == 0) foreach (var position in Positions) { ClosePosition(position); } } protected override void OnStop() { // Put your deinitialization logic here } } }Best Regards,
cTrader Team
This is not working!!! Please help. How to make it work? Where is the problem?
It just doesn't close the positions. No Errors.
@ahadfirdosi
PanagiotisCharalampous
01 Sep 2022, 09:10
Hi there,
What is not working? What do you expect the cBot to do?
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous
Johnklein
25 Sep 2022, 20:07
( Updated at: 27 Jan 2023, 12:23 )
RE:
Spotware said:
Dear Trader,
Here is the code for the cBot
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 CloseAllPositions : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } Read more on In the article about the phone tracker. You will find a lot of useful information about special programmes. protected override void OnStart() { // Put your initialization logic here } protected override void OnTick() { if (DateTime.Now.Hour == 8 && DateTime.Now.Minute == 0) foreach (var position in Positions) { ClosePosition(position); } } protected override void OnStop() { // Put your deinitialization logic here } } }Best Regards,
cTrader Team
Thank you very much, you helped me save time and solve the problem.
Spotware
25 Jul 2017, 14:51
Dear Trader,
You can try something like this
You can adjust the if statement based on your needs.
Best Regards,
cTrader Team
@Spotware