Closing a position after time
Closing a position after time
19 Oct 2013, 23:50
Hi
How do i make a position close after a set amount of hours?
Thanks
Replies
Cerunnos
20 Oct 2013, 00:45
RE:
MRSV said:
Hi
How do i make a position close after a set amount of hours?
Thanks
Hi, you could use a timer. Have not tested it but it should work.
using System.Timers;
...
private Position pos;
private readonly Timer _timer = new Timer();
protected override void OnPositionOpened(Position openedPosition)
{
pos = openedPosition;
_timer.Elapsed += OnTimedEvent;
_timer.Interval = 3 * 3600 * 1000; // Timer will tick every Interval (milliseconds)-> in 3 hours close position
_timer.Enabled = true;
_timer.Start();
}
private void OnTimedEvent(object sender, ElapsedEventArgs e)
{
Trade.Close(pos);
_timer.Stop();
}
protected override void OnPositionClosed(Position position)
{
pos = null;
}
@Cerunnos
Kate
20 Oct 2013, 00:03
The only thing you can do now is to implement robot n cAlgo that will automatically close your position.
@Kate