
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 know the problem is staring me right in then face, but I can't see it...
The problem I have though; I am trying to partial close the same "OP_BUY" or "OP_SELL" up to 4 times at different prices... I think the question I should be asking is, can I get a way, where by I have a rule that ALL partial closes (of any lots and price on ONE given trade) will only partially close ONCE at their predefined "OrderClose()" parameters set...
This way I am looking at doing it now with comparing the OrderOpenTime() will essentially only work once, and will restrict any other type of OrderClose() function from happening at all... I am wanting to find a way where I can have one rule applied to 4 OrderClose() functions... (if that makes sense?)
I know people are suggesting open 4 orders, but without going too deep, it's less efficient for me doing it that way.
Why not simply have a two-dimensional array that stores the ticket number and the number of available partial closes left to perform.
Outline/Pseudocode:
1. define static two-dimensional array: cOrders[][2].
2. for each new order entered: resize cOrders' first dimension to size+1, put new order's ticket number in [x][0] and number of partial closes left to perform (in this case, 4) in [x][1].
3. at whatever time interval (e.g., each start()), loop through the array, select each order using the stored ticket number, and determine if a partial close needs to be performed.
4. if partial close needs to be performed (see step 3), partially close order using OrderClose() and update cOrders[x][0] to reflect new ticket number and reduce cOrders[x][1] by 1.
5. remove from cOrders any orders that have been closed or that their number of partial closes left to perform is 0.
The only issue is what to do upon platform/computer restarts. You could store that information in a file and read the file in init() upon platform restart.
Why not simply have a two-dimensional array that stores the ticket number and the number of available partial closes left to perform.
Outline/Pseudocode:
1. define static two-dimensional array: cOrders[][2].
2. for each new order entered: resize cOrders' first dimension to size+1, put new order's ticket number in [x][0] and number of partial closes left to perform (in this case, 4) in [x][1].
3. at whatever time interval (e.g., each start()), loop through the array, select each order using the stored ticket number, and determine if a partial close needs to be performed.
4. if partial close needs to be performed (see step 3), partially close order using OrderClose() and update cOrders[x][0] to reflect new ticket number and reduce cOrders[x][1] by 1.
5. remove from cOrders any orders that have been closed or that their number of partial closes left to perform is 0.
The only issue is what to do upon platform/computer restarts. You could store that information in a file and read the file in init() upon platform restart.
I have not a clue how to use parts of the magic number to define different parameters? I think using OrderOpenTime() is not going to be a logical route... I can't believe how long this thread is getting. Lol.
I swear to god I am going to do a thread on this once I (with a lot of help from everyone else!) have cracked it.
I think the easiest way of doing this is with Magic Numbers . . . use parts of the number to define different parameters, for example: number of parts, order number, day, month, EA number . . . all parts would have the same Magic Number and could be traced easily in the History. I assume that the closed part and open part left both have the same Magic Number . . .
The use of the Magic Number to encode pieces of information is quite possible, but I see a couple of possible limitations. First, the Magic Number is an int and therefore is 10 digits long where the left-most digit can only be a 1 or 2 (and if the left-most digit is a 2, the second most-left digit must be 7 or less). Second, it might take more time per start() to review all of the history to find all the parts of each order just to determine if the current order needs (or can be) partially closed. Just not sure if that more time would be trivial or not.
Wait, can't I just have several magicnumbers? Use one for the initial OrderSend(), one for the OrderModify(), after half of the position is closed at the first target of 1:1, modify the order to change the MagicNumber? Therefore, when I am first looking to close half off at 1:1, it will only close off 1:1 as long as the current open "OP_BUY" corresponds to the magic number I first gave it? After it has then partially closed, modify and change that magic number?!
Lol? Is that not really simple?!
UPDATE: I obviously need to stop looking at this today - you can't modify a MagicNumber - wish you fucking could though... (facepalm) - Could you imagine how much easier this would all be...
Wait, can't I just have several magicnumbers? Use one for the initial OrderSend(), one for the OrderModify(), after half of the position is closed at the first target of 1:1, modify the order to change the MagicNumber? Therefore, when I am first looking to close half off at 1:1, it will only close off 1:1 as long as the current open "OP_BUY" corresponds to the magic number I first gave it? After it has then partially closed, modify and change that magic number?!
Lol? Is that not really simple?!
No. First, after the initial OrderSend(), you can't add/modify the Magic Number using OrderModify(). Second, when you do a partial order close using OrderClose(), the new order (I assume) gets the same Magic Number as the old order.
No. First, after the initial OrderSend(), you can't add/modify the Magic Number using OrderModify(). Second, when you do a partial order close using OrderClose(), the new order (I assume) gets the same Magic Number as the old order.
Yes. I realised how retarded I am being. Long day!
Yes, after the first partial close, the remaining position is still assigned the same magic number it first started with.
It's really frustrating me now... If only I could modify the magicnumber, it would be too easy!? There has to be a logical way to partially close a position ONCE - and do it multiple times at any given predefined price specified within the OrderClose() - There needs to be an update to allow us to modify the MagicNumber()!
You are not thinking logically at all.
1. How would modifying the magic number help you more than knowing the OrderOpenTime() ? It amounts to the exact same thing as an identifier to that order.
2. why are you converting it to day/hour/minutes format with timetostr ? OrderOpenTime() is already in the timestamp format it looks like this: 1375356521 it represents the exact time to the second when the order was opened.
if you could change the magic number you would compare the magic number of the order to make sure it does not have the magic number that means it was already part closed right ?
If you could do that, why cant you compare the OrderOpenTime of the order with the timestamp that you know means it is one that was already part closed ?
static datetime alreadypartclosed;
if part close order is successful
alreadypartclosed = OrderOpenTime();
when order meets criteria for part closing
if(OrderOpenTime() != alreadypartclosed )
If you are managing multiple open orders at the same time use an array[] to hold each timestamp of part closed orders.