65 lines
		
	
	
		
			No EOL
		
	
	
		
			1.5 KiB
		
	
	
	
		
			MQL5
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			No EOL
		
	
	
		
			1.5 KiB
		
	
	
	
		
			MQL5
		
	
	
	
	
	
#property strict
 | 
						|
 | 
						|
#include "Channel_Unit.mqh"
 | 
						|
 | 
						|
#ifdef __MQL5__
 | 
						|
  #ifndef TICKET_TYPE
 | 
						|
    #define TICKET_TYPE long
 | 
						|
  #endif // TICKET_TYPE
 | 
						|
#else // __MQL5__
 | 
						|
  #ifndef TICKET_TYPE
 | 
						|
    #define TICKET_TYPE int
 | 
						|
  #endif // TICKET_TYPE
 | 
						|
#endif // __MQL5__
 | 
						|
 | 
						|
struct TRADECHANNEL
 | 
						|
{
 | 
						|
private:
 | 
						|
  static int OrderScan( const int Type )
 | 
						|
  {
 | 
						|
    int Res = -1;
 | 
						|
 | 
						|
    for (int i = OrdersTotal() - 1; i >= 0; i--)
 | 
						|
      if (OrderSelect(i, SELECT_BY_POS))
 | 
						|
        if (OrderType() == Type)
 | 
						|
        {
 | 
						|
          Res = Type;
 | 
						|
 | 
						|
          break;
 | 
						|
        }
 | 
						|
 | 
						|
    return(Res);
 | 
						|
  }
 | 
						|
 | 
						|
  static TICKET_TYPE Trade( const int Type, const double dLots, const double Price, const int Slip = 100 )
 | 
						|
  {
 | 
						|
    return((TRADECHANNEL::OrderScan(Type) == Type) ? false :
 | 
						|
           ((TRADECHANNEL::OrderScan(1 - Type) == -1) || OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slip)) &&
 | 
						|
           (OrderSend(_Symbol, Type, dLots, Price, Slip, 0, 0) > 0));
 | 
						|
  }
 | 
						|
 | 
						|
public:
 | 
						|
  const double Lots;
 | 
						|
 | 
						|
  TRADECHANNEL( const double dLots = 1 ) : Lots(dLots)
 | 
						|
  {
 | 
						|
  }
 | 
						|
 | 
						|
  void Trade( const CHANNEL_UNIT &ChannelUnit ) const
 | 
						|
  {
 | 
						|
    if (ChannelUnit.Check())
 | 
						|
    {
 | 
						|
      MqlTick Tick;
 | 
						|
 | 
						|
      if (SymbolInfoTick(_Symbol, Tick))
 | 
						|
      {
 | 
						|
        if (Tick.bid >= ChannelUnit.High)
 | 
						|
          TRADECHANNEL::Trade(OP_SELL, this.Lots, Tick.bid);
 | 
						|
        else if (Tick.ask <= ChannelUnit.Low)
 | 
						|
          TRADECHANNEL::Trade(OP_BUY, this.Lots, Tick.ask);
 | 
						|
      }
 | 
						|
    }
 | 
						|
 | 
						|
    return;
 | 
						|
  }
 | 
						|
}; |