closing an order based on EA of another chart

 

Hello boys,

So my setup is as follows: one chart (with its own EA) is opening the primary order, while a second EA runs on another chart (same symbol) - for hedging and other purposes. The bit below is part of the secondary (hedging) chart and EA, and tries to close the primary order in the hedging EA based on "some conditions"....

I already checked that the conditions provide the correct trigger (ie, I got it to print a message etc), however the order in the primary chart is not closing. What can be wrong with it?? I also checked for circularity of logic, as some of the conditions go back and forth between the two EAs (it seems OK, and compilation returns no errors, but will check again if you think that may cause it..)

Thanks in advance for your insights!

Dan (scratching my head..)


if (.... /////some conditions///////.....) {
               for (int i = OrdersTotal()-1; i >=0; i--){
               		if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && 
			OrderSymbol()== HedgedSYMBOL && 
			OrderMagicNumber()== HedgedMAGIC && 
			OrderType() == OP_BUY)
               			{OrderClose(OrderTicket(),OrderLots(),Bid,_slippage_close,CLR_NONE);
               			}
            }
           }
 
1.) RefreshRates()

2.) MarketInfo ( OrderSymbol(), MODE_FREEZELEVEL )

3) There exists TradeSemaphore() in the EA's?

4) Optional: Bid = OrderClosePrice()

5) Optional : separate if ( ! OrderSelect(... or if ( Ord..

better approach is :

if ( ! OrderSelect(...) ) continue;
if ( conditions == true ) ClTickets[n] = OrderTicket();// orderTicket is stored for later
n++;
// in same task, or another can because tickets are known
// if ( OrderSelect( ClTickets[n-1..  
// .. proceed OrderClose(ClTickets[n-1...

 

thanks! works just fine now - I made some changes and also incorporated your suggestion to separate ifs and use the "if (!...) continue" instead - I havent really used that before but looks solid. many thanks!

Reason: