orders always zero

 

Hi guys, Im running my EA in tester and OrdersHistoryTotal(), OrderClosePrice() and OrderTakeProfit()

are all showing zeros even after orders are Open and Closed.Here is the code.

Thanks for your help.

 
      double PriceTP;
    int Total_History = OrdersHistoryTotal();
  for (int pos = 0; pos >= Total_History; pos++)
    {
    if (OrderSelect (pos, SELECT_BY_POS, MODE_HISTORY) == true &&
        OrderClosePrice() == OrderTakeProfit())
        {
        Print ("We have the winner :) ");
              PriceTP = OrderTakeProfit();
        }
        Print ("              1  OrdersHistoryTotal()",OrdersHistoryTotal());
        Print ("          2 -- OrderClosePrice() ",OrderClosePrice());
        Print ("          2a --  OrderTakeProfit() ", OrderTakeProfit());
   if ( OrdersHistoryTotal() == 0) break; 
       }  
        //---- Moving Average Cross System
        
     if ( OrdersHistoryTotal() == 0 ){ PriceTP = Close[1]-1; }           
         if ( Close[1] > bb && Close[1] > PriceTP ) { GoLong(); }
           
     if ( OrdersHistoryTotal() == 0 ){ PriceTP = Close[1]+1;}            
         if ( Close[1] < cc && Close[1] < PriceTP ) { GoShrt(); }

         Print ("              3  ");
      }

 

Aren't this

for (int pos = 0; pos >= Total_History; pos++)

supposed to be this

for (int pos = 0; pos <= Total_History; pos++)

...???

Please report back the result :)

 
onewithzachy:

Aren't this

supposed to be this

...???

Please report back the result :)


That did it Thanks. Question ( pos=0, pos <= Total_History ) will always be true

What happens after the highest pos is reached.

 

Did you mean ...

Question ( pos=0; pos <= Total_History; pos ++ ) will always be true

What happens after the highest pos is reached.

After the highest pos reached, the for loop terminates it self and the next code block get executed, in your case, it's the 'Moving Average Cross System' gets executed. :)
 
onewithzachy:

Did you mean ...

After the highest pos reached, the for loop terminates it self and the next code block get executed, in your case, it's the 'Moving Average Cross System' gets executed. :)


Ya I didnt add the increment thanks for the explanation,

trying to make my EA consistantly profitable difficult.

 
  1.   int Total_History = OrdersHistoryTotal();
      for (int pos = 0; pos >= Total_History; pos++)
    Always count down.
  2.  if ( OrdersHistoryTotal() == 0) break; 
    This will never be true inside the for loop. It also makes the EA incompatible with every other including itself on other charts and manual trading.
  3. Always filter by magic number and pair
    bool hasHistory=false;
        for(int iPos=OrdersHistoryTotal()-1; iPos >= 0; iPos--) if (
            OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)  // Only orders w/
        &&  OrderMagicNumber()  == Magic.Number             // my magic number
        &&  OrderSymbol()       == chart.symbol             // and my pair.
        &&  OrderType()         <= OP_SELL//Avoid cr/bal forum.mql4.com/32363#325360
        ){
            hasHistory  = true;
            Print ("We have the winner :) ");
            :
            break; // Process one only
        }
    if (!hasHistory){
        //---- Moving Average Cross System
        :
    }
  4. See also Order History sort by closing date - MQL4 forum
 
     if ( OrdersHistoryTotal() == 0 ){ PriceTP = Close[1]-1; }           
         if ( Close[1] > bb && Close[1] > PriceTP ) { GoLong(); }
           
     if ( OrdersHistoryTotal() == 0 ){ PriceTP = Close[1]+1;}            
         if ( Close[1] < cc && Close[1] < PriceTP ) { GoShrt(); }

So you can only ever have one trade for this system. As soon as you have done one trade you can never ever trade again. Shouldn't this test be OrdersTotal() rather than OrdersHistoryTotal()

Of course just using OrdersTotal() is pretty lame for a real EA due to the possible existence of other EAs trading this account, but it will work enough to test a strategy.