Half close position without repetition.
Half close position without repetition.
20 Mar 2018, 17:24
Dear Pangiotis,
I have code, where upon reaching a certain price the position is closed, let us say, 50%
Also, I am using
"...
protected override void OnBar()
{
OnStart();
}
....
''''
Tryin to figure out how to make the the rest of the order is not closed, upon reaching the same condtion.
I tryied to use position.comment, but it is read only.
There probably could be walk around like
if (condition)
{
var volumeToClose = Symbol.NormalizeVolume(position.Volume * PositionPartClosing);
ModifyPosition(position, newStopLoss, null);
}
and then use null in takeProfit as a flag, but I do think it is the best solution.
Can you suggest something?
Regards,
Alexander
Replies
alexander.n.fedorov
20 Mar 2018, 17:57
Half close
Panagiotis,
nice Idea, the problem would be if the robot stops for some reason, restarting it you are going to loose a list, cause on restart everything is reinitialized.
It has to be smth on the server, like position information. Can I keep the list on a server? Probably not, that's why I wanted to use the position comment
Regards.
Sasha
@alexander.n.fedorov
alexander.n.fedorov
21 Mar 2018, 06:12
Half close
Or maybe you mean that I have to keep list on a separate application list, like an Excel for example?
In my particular case after I close half, I do the trailing, so in this case position.Takeprofit equals to there could serve as a flag, I quesss, but it is not clean solution.
@alexander.n.fedorov
PanagiotisCharalampous
21 Mar 2018, 09:25
Hi Alexander,
Yes you could store this information in a file if you would like it not to be lost on a restart. I agree with you that using the TP is not a good idea.
Best Regards,
Panagiotis
@PanagiotisCharalampous
alexander.n.fedorov
21 Mar 2018, 09:39
Half close
If you could just give me an idea, how to get access to an Excel file, or even better - I store all of my trades there - to an SQL server.
Just small example will probably do
@alexander.n.fedorov
alexander.n.fedorov
21 Mar 2018, 09:41
As a matter of fact, If I new how to interface an SQL server with print messages, then I could have all the history reported and automated
@alexander.n.fedorov
PanagiotisCharalampous
21 Mar 2018, 09:44
Hi Alexander,
It doesn't need to be Excel or SQL. A simple csv would be enough. There are plenty of examples on how to do this like this one.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
20 Mar 2018, 17:34
Hi Alexander,
From what I understand you need to track which positions have been modified and not modify them again in case they have. You could hold all the modified positions in a separate list and before modifying a position check if the position is in the list or not.
Let me know what you think of this.
Best Regards,
Panagiotis
@PanagiotisCharalampous