extern double ChannelH, ChannelL; extern double Lots = 0.1; extern int MagicNumber = 859489; int TradeDirection; int init() { TradeDirection = 0; return(0); } int deinit() { TradeDirection = 0; return(0); } int start() { if (TradeDirection == 0) //0 means the break-out hasn't happened yet, so look for it and note its //direction once it happens. And then apply the OpenPosition() function. { if (Bid >= ChannelH) { TradeDirection = 1; OpenPosition(); } else if (Bid <= ChannelL) { TradeDirection = 2; OpenPosition(); } } Comment(TradeDirection); return(0); } void OpenPosition() { int ticket; if (TradeDirection == 1) { ticket = OrderSend(Symbol(), OP_BUYSTOP, Lots, ChannelH, 0, OrderStopLoss(), 0, "Long", MagicNumber, 0, Green); if (ticket <= 0) Print("Error opening long order: ", GetLastError()); } else if (TradeDirection == 2) { ticket = OrderSend(Symbol(), OP_SELLSTOP, Lots, ChannelL, 0, OrderStopLoss(), 0, "Short", MagicNumber, 0, Red); if (ticket <= 0) Print("Error opening short order: ", GetLastError()); } }