All options welcome
Thanks
matrixebiz wrote:Hello All, just wondering what your techniques are for selecting specific orders on the same pair that have multiple orders currently open without using MagicNumbers or Comments. I was thinking of using something like OrderOpenTime() but haven't checked this Return to see what type of value it spits out and how to implement this type of checking with EA's that use the Recovery System.
All options welcome
Thanks
No, I will actually need to check every open order for the pair as I have a CloseAll function that calculates the profit of all the orders and closes them when a total profit is hit.gaheitman wrote:Do you need to get just the first or the last order, or will you need to find one in between? For the first or the last, you can just iterate through the orders list forwards or backwards (respectively) and just take the first match.
Yes, you are correct but I'm not using pending orders so this should not affect megaheitman wrote:Doesn't OrderOpenTime() change after the order is actually filled, if you start with a pending order? I seem to remember running across that at some point. Not sure if it matters anyway, but it might change the order if you suspected the order was on when you placed them. And if I am remembering wrong, it really doesn't matter.![]()
This sounds like a viable option but I'm not advanced enough in my coding abilities do do something like this unless you feel like elaborating on this with examplesgaheitman wrote:You could also keep track of the orders in an array as you place them. If you use a multi-dimensional array you can keep track of additional data you want for each order (as long as you map it to integers).
Code: Select all
double target = 100; //target profit in money not pips
double profit = 0; //hold the profit as we go through the list
//scan open trades
int total=OrdersTotal();
for(int i=0; i<total; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if (OrderSymbol() == Symbol())
profit += OrderProfit();
}
//scan closed trades
total=OrdersHistoryTotal();
for(i=0; i<total; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
if (OrderSymbol() == Symbol())
profit += OrderProfit();
}
if (profit >= target)
//made it, now close all the orders
CloseOpenOrders(); //the procedure to close all the matching open orders
matrixebiz wrote:No, I will actually need to check every open order for the pair as I have a CloseAll function that calculates the profit of all the orders and closes them when a total profit is hit.gaheitman wrote:Do you need to get just the first or the last order, or will you need to find one in between? For the first or the last, you can just iterate through the orders list forwards or backwards (respectively) and just take the first match.
Yes, you are correct but I'm not using pending orders so this should not affect megaheitman wrote:Doesn't OrderOpenTime() change after the order is actually filled, if you start with a pending order? I seem to remember running across that at some point. Not sure if it matters anyway, but it might change the order if you suspected the order was on when you placed them. And if I am remembering wrong, it really doesn't matter.![]()
This sounds like a viable option but I'm not advanced enough in my coding abilities do do something like this unless you feel like elaborating on this with examplesgaheitman wrote:You could also keep track of the orders in an array as you place them. If you use a multi-dimensional array you can keep track of additional data you want for each order (as long as you map it to integers).
Thank you
Ok, that seems easy enough but it's an older EA of mine so I'll have to scan though it to see if that is all I was trying to do with the multiple orders. It uses a Recovery system in it as well, so not sure if that was also the reason I was using MagicNumbers to also keep track of those orders also. I'll get back to you on that. Thank you for the codegaheitman wrote:If you are just trying to close all the open orders when you hit a threshold of profit, something like this should work:
If you aren't interested in including closed trades, just strike the second loop.Code: Select all
double target = 100; //target profit in money not pips double profit = 0; //hold the profit as we go through the list //scan open trades int total=OrdersTotal(); for(int i=0; i<total; i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if (OrderSymbol() == Symbol()) profit += OrderProfit(); } //scan closed trades total=OrdersHistoryTotal(); for(i=0; i<total; i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) if (OrderSymbol() == Symbol()) profit += OrderProfit(); } if (profit >= target) //made it, now close all the orders CloseOpenOrders(); //the procedure to close all the matching open orders
This isn't finished code, just a quick example of the looping you would need.
George
Code: Select all
void OrderNeedsRecovery()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()
&& OrderOpenPrice() - Point*ReEntryLinePips > Bid) RecoveryInProgress = true;
if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber+1 && OrderSymbol() == Symbol()
&& OrderOpenPrice() - Point*ReEntryLinePips > Bid) RecoveryInProgress1 = true;
if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber+2 && OrderSymbol() == Symbol()
&& OrderOpenPrice() - Point*ReEntryLinePips > Bid) RecoveryInProgress2 = true;
if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()
&& OrderOpenPrice() + Point*ReEntryLinePips < Ask) RecoveryInProgress = true;
if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber+1 && OrderSymbol() == Symbol()
&& OrderOpenPrice() + Point*ReEntryLinePips < Ask) RecoveryInProgress1 = true;
if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber+2 && OrderSymbol() == Symbol()
&& OrderOpenPrice() + Point*ReEntryLinePips < Ask) RecoveryInProgress2 = true;
}}
return;
}matrixebiz wrote:Hi, looks like I was using the extra magic numbers to find out if the first order was in DD so many pips hence needing a recovery order then if profit was still not hit, needed to check if the second order is now also in DD by so many pips to place another recovery order, etc.Code: Select all
void OrderNeedsRecovery() { int totalorders = OrdersTotal(); for(int i=totalorders-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); { if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() && OrderOpenPrice() - Point*ReEntryLinePips > Bid) RecoveryInProgress = true; if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber+1 && OrderSymbol() == Symbol() && OrderOpenPrice() - Point*ReEntryLinePips > Bid) RecoveryInProgress1 = true; if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber+2 && OrderSymbol() == Symbol() && OrderOpenPrice() - Point*ReEntryLinePips > Bid) RecoveryInProgress2 = true; if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() && OrderOpenPrice() + Point*ReEntryLinePips < Ask) RecoveryInProgress = true; if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber+1 && OrderSymbol() == Symbol() && OrderOpenPrice() + Point*ReEntryLinePips < Ask) RecoveryInProgress1 = true; if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber+2 && OrderSymbol() == Symbol() && OrderOpenPrice() + Point*ReEntryLinePips < Ask) RecoveryInProgress2 = true; }} return; }
... but the problem here is that if you see in the recovery code, I'm not actually looking for it to check the profit and close them all at this moment in time, I need it to check specific orders to see if an order is at a certain amount of DrawDown so I can tell the EA to open another order. So basically what I need for example is for the EA to check on lets say the third order I've opened and see how many pips it is in the negative and if it is -200pips then the EA will determine if I will open another order. This is why I was using MagicNumber + 2 on the third order opened so I could check on that order specifically.gaheitman wrote:The code to go through them all and close them would still be appropriate.
Code: Select all
if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber+2 && OrderSymbol() == Symbol()
&& OrderOpenPrice() - Point*ReEntryLinePips > Bid) RecoveryInProgress2 = true;
matrixebiz wrote:... but the problem here is that if you see in the recovery code, I'm not actually looking for it to check the profit and close them all at this moment in time, I need it to check specific orders to see if an order is at a certain amount of DrawDown so I can tell the EA to open another order. So basically what I need for example is for the EA to check on lets say the third order I've opened and see how many pips it is in the negative and if it is -200pips then the EA will determine if I will open another order. This is why I was using MagicNumber + 2 on the third order opened so I could check on that order specifically.gaheitman wrote:The code to go through them all and close them would still be appropriate.
Sorry if this is getting confusing.
I wrote the code so you are correct in what I'm trying to do heregaheitman wrote:I'm reading the code out of context, but I thought that this was a test to see if we need to enter a new trade. For example, in this test:
the code is checking to see if the order we entered with MagicNumber+2 has gone far enough against us that we need to enter another recovery trade. I assumed this code was followed by a test to see that if RecoveryInProgress2 = true, enter recovery trade #3.Code: Select all
if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber+2 && OrderSymbol() == Symbol() && OrderOpenPrice() - Point*ReEntryLinePips > Bid) RecoveryInProgress2 = true;
... Ok, now to the solution of getting rid of MagicNumber trackinggaheitman wrote:Another way of looking at the test is to just examine the first trade. If it goes against us ReEntryLinePips, enter a trade. If it then goes against us ReEntryLinePips*2, enter a trade. You want to stop when the number of open trades exceeds the max number of recovery trades you are willing to enter + 1. Your code just has to keep track of the first ticket number and re-select it after you enter a trade. Or, if you are just trading one currency, one direction at a time, you can just select the first trade in the list with OrderSelect(0, SELECT_BY_POS)