(TradeIsShort == IsShort) checks only long resp. short trades. This allows you to have a long and a short trade pending on any grid line. Otherwise you had only either a long or a short trade, whichever was placed first.