//by ralph.ronnquist { checkTrades( -100 ); return( 0 ); } /** * Reviews currently open trades, to find pairs of long EURUSD and * short EURCHF such that their profit difference coincides with * a given "cut" value, and then close those trades. */ void checkTrades(double cut) { int eurusd[100]; int eucount = collectTickets( eurusd, "EURUSD", OP_BUY ); int eurchf[100]; int eccount = collectTickets( eurchf, "EURCHF", OP_SELL );; for ( int eu = 0; eu < eucount; eu++ ) { double euprofit = profit( eurusd[eu] ); for ( int ec = 0; ec < eccount; ec++ ) { if ( eurchf[ec] < 0 ) continue; double ecprofit = profit( eurchf[ec] ); double v = euprofit - ecprofit; if ( v == cut ) { close( eurusd[eu], Bid ); close( eurchf[ec], Ask ); eurchf[ec] = -1; break; } } } } /** * Collects all the tickets of the open trades of a given symbol and * type, into an array, and returns the number of tickets. */ int collectTickets(int &trades[],string symbol,int type) { int count = 0; for( int i = OrdersTotal()-1; i >= 0; i-- ) { if ( ! OrderSelect(i,SELECT_BY_POS,MODE_TRADES) ) continue; if ( OrderType() != type ) continue; if ( OrderSymbol() != symbol ) continue; trades[ count ] = OrderTicket(); count += 1; } return( count ); } /** * Closes an order given by ticket, with the given price. */ void close(int ticket,double price) { OrderClose( OrderTicket(), OrderLots(), price, 0, CLR_NONE ); } /** * Returns the profit of an order given by ticket. */ double profit(int ticket) { OrderSelect( ticket, SELECT_BY_TICKET ); return( OrderProfit() ); }