double MA=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,1);
datetime LastClosedOrderClosedTime=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)==true)
{
LastClosedOrderClosedTime=OrderCloseTime();
}
if(OrdersTotal()==0 && MA>0 && Time[0]>LastClosedOrderClosedTime && Bid>MA)
{
OpenBuyOrder();
}
if(OrdersTotal()==0 && MA>0 && Time[0]>LastClosedOrderClosedTime && Bid<MA)
{
OpenSellOrder();
}