Ошибка в советнике

 
Ошибка в советнике
Советник не хочет закрывать позиции в определенное время .
Где ошибка ?

/*[[
Name := test
Lots := 1.00
Stop Loss := 0
Take Profit := 0
Trailing Stop := 0
]]*/

var: cnt(0);
If FreeMargin<1000 then Exit;
If TotalTrades<1 then
{
if Hour = 0 then
{
if Ask > High[1] then
{
SetOrder(OP_BUYLIMIT, Lots,High[1],3,High[1]-StopLoss*Point,High[1]+TakeProfit*Point,Yellow);
Exit;
};
if Ask < High[1] then
{
SetOrder(OP_BUYSTOP, Lots,High[1],3,High[1]-StopLoss*Point,High[1]+TakeProfit*Point,Orange);
Exit;
};
Exit;
};
Exit;
};


if Hour = 22 then
{
for cnt = 1 to TotalTrades
{
if (Ord(cnt,VAL_TYPE))=OP_BUYLIMIT or OP_BUYSTOP then
{
DeleteOrder(OrderValue(cnt,VAL_TICKET),SkyBlue);
Exit;
};

if (Ord(cnt,VAL_TYPE))=OP_BUY then
{
CloseOrder (OrderValue(cnt,VAL_TICKET), OrderValue(cnt,VAL_LOTS), Bid, 3, Blue);
Exit;
};
Exit;
};
Exit;
};
Причина обращения: