Need help for complete my code

Dear Sirs,

I want write a function for my EA that after X continuous loose trades sleep for Y times and next starts.

After new start if we meet again X continuous loose trades sleep for Y times and next starts.

I want do this cycle when meet it.

I am tried and wrote below code:

extern int loose_step=2;

extern double time_sleep=0.03;

double last_ticket=0;

bool time_sleep(){

bool allow_trade=true;
int Trade_Count = 0;
int Idenn;
int loose_total=0;
double Last_order_profits[200];
double order_ticket[200];

datetime Last_Order_time[200];
for(Idenn=OrdersHistoryTotal()-1;Idenn>=0;Idenn–)
{
OrderSelect(Idenn, SELECT_BY_POS, MODE_HISTORY);
if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_Number )
{
Last_Order_time[Trade_Count]=OrderCloseTime();
Last_order_profits[Trade_Count] = OrderProfit();
order_ticket[Trade_Count]=OrderTicket();
Trade_Count++;
}
}
for(int j=0;j<loose_step;j++)
{
if(Last_order_profits[j]<0 && order_ticket[0]< last_ticket)loose_total++;
if(loose_total==loose_step)last_ticket=order_ticket[0];

}

if(loose_total>=loose_step && TimeCurrent()-Last_Order_time[0]<time_sleep*3600)
{
allow_trade=false;
}
else
{
allow_trade=true;
}

return(allow_trade);
}

anybody can help me?

Thanks.