You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I do it by OrderModify() add 1 pip to the broker SL before it is part closed. That way there is no need for recovery etc, the Order itself contains the information about how many times it was part closed already. (OpenPrice + SL) - (OpenPrice + Original SL) = nPartCloses.
In most cases this would work. And I use this already. The problem I have is that I have up to 3 partial closes on one open position via the use of OrderClose() function. The 2R target exit, for example, cannot use if(OrderOpenPrice() > OrderStopLoss()...) then use OrderClose() and move the StopLoss to 3 pips above the OrderOpenPrice, because in my case, 100% of the time, the stoploss will already be ABOVE the entry price once it reaches the 2R target through a trailing stop....
Therefore (assuming that makes sense to you), I can use what you're saying already, but it won't work with every OrderClose() function in play as it stands... I need something fairly robust in all contexts to use....
well if you are going to use a global variable, instead of naming it partclosedonce and putting the open time in it, why dont you name it with the open time, and put the amount of part closes in it ? Or you could put the time in it plus 0.1 for one part close plus 0.2 for 2 part closes. the time is an integer so adding 0.1 to it would make an easy calcuation to get both the time out of it and the number of closes
well if you are going to use a global variable, instead of naming it partclosedonce and putting the open time in it, why dont you name it with the open time, and put the amount of part closes in it ? Or you could put the time in it plus 0.1 for one part close plus 0.2 for 2 part closes. the time is an integer so adding 0.1 to is would make an easy calcuation to get both the time out of it and the number of closes
you dont need to make a string, just do GlobalVariableSet( GV1,OrderOpenTime() );
Remember a datetime is just like an integer value.
so you can store it as a double in a GV and it doesnt matter if you add 0.1 to it because when you convert a double to a datetime it drops the DP.
... that does not return a datetime format though.... It just gives you numbers.... OrderOpenTime() is a datetime and that parameter where you've put it is asking for a double....
Yes Raptor knows what I mean, it doesnt matter that the datetime is a string of numbers it is supposed to be a string of numbers just put it in the GV.
Ok - I think I got it working now! Finally... coding takes longer when you have 101 other things going on at the same time!
does it actually work as GlobalVariableSet(" GV1 ", OrderOpenTime()); ?
When I wrote that I wrote it rather flippantly, what I actually meant was to do,
double time = OrderOpenTime();
GlobalVariableSet("GV1",time);
because then when you part close an order you can do
time += 0.1
GlobalVariableSet("GV1",time);
so then you have the time plus the amount of part closes in the GV.
so to get the time out you can do
datetime GVopentime = GlobalVariableGet("GV1"); (because the conversion from double to datetime drops the decimal places.)
then to get the number of part closes out you can do
double PartCloses = (GlobalVariableGet("GV1") - GVopentime)*10
that idea assumes you dont part close an order more than 9 times. Probably it would be more robust to do time+=0.01 so it allows for 99 part closes without affecting the datetime.
Secondly, how am I using this: double PartCloses = (GlobalVariableGet("GV1") - GVopentime)*10 -- In the equality statements I am wanting to use, before the OrderClose() function?
i.e. -- If (OrderOpenTime() != FetchDateOfFirstClose ) -- "FetchDateOfFirstClose" being the GlobalVariableGet(" GV1 "); ?