Trying to build an 'always in the market' expert

 

Hi people.

I built an expert, trying to be always in the market, but for some reason it remains out from trade to trade.

This is the logic:

   //----------------------------------------- Internal variables ---!
   double SlowMAprev=iMA(NULL,0,SlowMAperiod,SlowMAshift,SlowMAmethod,PRICE_CLOSE,1);
   double SlowMAcurr=iMA(NULL,0,SlowMAperiod,SlowMAshift,SlowMAmethod,PRICE_CLOSE,0);
   double FastMAprev=iMA(NULL,0,FastMAperiod,FastMAshift,FastMAmethod,PRICE_CLOSE,1);
   double FastMAcurr=iMA(NULL,0,FastMAperiod,FastMAshift,FastMAmethod,PRICE_CLOSE,0);
   //------------------------------------------------------ Start ---!
   if(OrdersTotal()<1){
      //--- Check for LONG
      if(FastMAprev<SlowMAprev&&FastMAcurr>SlowMAcurr){
         if(Spread<=MaxSpread){
            if(AccountFreeMarginCheck(Symbol(),OP_BUY,LotsOptimized())>=MarketInfo(Symbol(),MODE_MARGINREQUIRED)*LotsOptimized()){
               if(!OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,LongSL,LongTP,BOTNAME,MAGICNUM,0,clrBlue)){
                  Print("OrderSend error ",GetLastError());
                  return;
   (THE SAME FOR SHORT)
   for(int i=0;i<OrdersTotal();i++){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false){break;}
      if(OrderMagicNumber()!=MAGICNUM&&OrderSymbol()!=Symbol()){continue;}
      //--- Exit LONG
      if(OrderType()==OP_BUY){
         if(FastMAprev>SlowMAprev&&FastMAcurr<SlowMAcurr){
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,clrGold)){
               Print("OrderClose error ",GetLastError());
               return;
   (THE SAME FOR SHORT)
 
if(!OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,LongSL,LongTP,BOTNAME,MAGICNUM,0,clrBlue))

OrderSend() does not return a bool. It returns the ticket number or -1 if it fails. If -1 is tested as a bool, it will show true.

Check it correctly

Reason: