Returns zero for some unknown reason - page 2

 
Ernest Klokow #: Anyone?

Answer #7 ignored.

 
Ernest Klokow #: I have made some changes to the code (see below) but still get a "0" result.

I have already asked so will ask again - where exactly is the result "0"?

 
William Roeder #:

Answer #7 ignored.

I don't use MQL4 so cannot debug/analyze, but in addition to answer #7, detailed debugging seems to be the next step.

It is difficult with the way the statements are written, so simplify it by collecting the logic results into variables and print out to get a trace.

Here is an example (not compiled - adjust as needed) - this way you can figure out each true/false evaluation

   Count = 0;

   bool boolSelect, boolMagic, boolSym, boolOrdTyp, boolProfit, boolLoss, boolClose;

   for(Count = OrdersTotal() - 1; Count >= 0; Count--)
     {
      boolSelect = OrderSelect(Count, SELECT_BY_POS,MODE_TRADES);
      boolMagic  = OrderMagicNumber() == MagicNumber;
      boolSym    = OrderSymbol() == Symbol();

      PrintFormat("ordSel = %s | OrderMagicNumber(%d) == MagicNumber(%d)=%s | boolSym = %s"
                  string(boolSelect),
                  OrderMagicNumber(),
                  MagicNumber,
                  string(boolMagic),
                  string(boolSym)
                 );
      if(boolSelect && boolMagic && boolSym)
        {
         boolOrdTyp = (OrderType() == OP_BUY);
         PrintFormat("boolOrdTyp = %s", string(boolOrdTyp));
         if(boolOrdTyp)
           {
            BuyProfit += OrderProfit();
           }

         boolProfit = (BuyProfit >= ProfitDollarValue);
         boolLoss   = (BuyProfit <= LossDollarValue);
         PrintFormat("boolProfit = %s  boolLoss   = %s", string(boolProfit), string(boolLoss));

         if(boolProfit || boolLoss)
           {
            boolClose =   OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), UseSlippage, Blue);
            PrintFormat("boolClose = %s", string(boolClose));
           }
        }
     }
  }