Filter manual positions after timeframe
Filter manual positions after timeframe
05 Dec 2013, 12:47
Hi ,
for a semi-automatic solution I want to know if it's possible to filter manual positions after relevant timeframe in a robot. So a separate strategy for manual positions with the time frame M30, H1 etc.
It could possibly succeed with Position.Comment, but then I had to comment each manual order. Is there another / simple solution?
Thanks
Replies
atrader
05 Dec 2013, 14:10
Why filter positions by timeframe? Or how does timeframe relate to a position?
You can filter positions by label, symbol and trade type with FindAll.
// pass the empty string as the label argument to find positions entered manually // and assign a label to positions opened by the robot var positions = Positions.FindAll("", Symbol); foreach (var position in positions) { }
@atrader
Cerunnos
05 Dec 2013, 14:19
Thanks for reply. The use of labels is already known to me. In this case I'm using no labels because only manual positions to be processed by my Robot. I want to filter manual positions by timeframe in one robot, because I have different exit strategies for each timeframe.
M30-position in XAU/USD -> m30-exit strategy in robot
H1-position in XAU/USD -> H1-exit strategy in robot
@Cerunnos
virtuesoft
05 Dec 2013, 14:34
RE:
Cerunnos said:
Thanks for reply. The use of labels is already known to me. In this case I'm using no labels because only manual positions to be processed by my Robot. I want to filter manual positions by timeframe in one robot, because I have different exit strategies for each timeframe.
M30-position in XAU/USD -> m30-exit strategy in robot
H1-position in XAU/USD -> H1-exit strategy in robot
I see what you mean. I can't see a way of identifying the timeframe other than manually updating the label after the manual trade has been made.
@virtuesoft
Cerunnos
05 Dec 2013, 14:53
RE:
atrader said:
Why not create those positions by another robot (used just to open the positions) assigning the respective labels to them?
That would be a possibility. But then every time I'd have to log in on my VPS starting one of the two robots (m30 / H1) ...
@Cerunnos
Cerunnos
05 Dec 2013, 16:41
( Updated at: 21 Dec 2023, 09:20 )
Perhaps there is a better solution - but it works :-) With Position.Comment it is possible to communicate between cTrader and cAlgo. With a comment such as "m30" in cTrader a special routine "m30" in cAlgo can be executed. The following simple code can be used for semi-automatic system:
protected override void OnStart()
{
Positions.Opened += OnPositionsOpened;
}
private void OnPositionsOpened(PositionOpenedEventArgs args)
{
if (args.Position.Comment == string.Empty) // manual positions without comment in cTrader
{
Print("Manual Position #{0} is open", args.Position.Comment);
// Exit-Strategy 1 ...
}
else if (args.Position.Comment == "m30") // manual positions in timeframe m30 - comment in cTrader "m30"
{
Print("Manual Position in m30 #{0} is open", args.Position.Comment);
// Exit-Strategy 2 ...
}
else if (args.Position.Comment == "h1") //only manual positions in timeframe m30 - comment in cTrader "h1"
{
Print("Manual Position in h1 #{0} is open", args.Position.Comment);
// Exit-Strategy 3 ...
}
}
@Cerunnos
virtuesoft
05 Dec 2013, 14:00
In your robot add a label to each position. With your manual orders do not add a label. That way you can differentiate between the two. In the robot you can keep a list of the positions and fill it using the code below...
@virtuesoft