history trades are mixed to trading pool somehow

 

Strange thing, an old short piece of code of mine is not working now.

i do it on build 482 

A simple code to check whether are there open trades, and if there were, then looks for the biggest lot size to double it.

In backtesting it does something else: even if there were no trades open, this code also mixes the history (Closed) trades somehow and doubles the lot size of the last closed trade to get lot size for the next position. Of coure this causes ordersend error 134 after a while.  I could not figure it out. The select_by_pos by default should take only trades from trading pool.

 

double maxlot;
int _total=OrdersTotal(); // number of trades  

// look for any open trades
for (int g=_total;g>=0;g--)

    {

     if(OrderSelect(g,SELECT_BY_POS))

     if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;

     if(OrderLots()>maxlot) maxlot = OrderLots();

     Lot= maxlot*2; 

     

     }

                    

    
 
Szilar:

Strange thing, an old short piece of code of mine is not working now.

i do it on build 482 

A simple code to check whether are there open trades, and if there were, then looks for the biggest lot size to double it.

In backtesting it does something else: even if there were no trades open, this code also mixes the history (Closed) trades somehow and doubles the lot size of the last closed trade to get lot size for the next position. Of coure this causes ordersend error 134 after a while.  I could not figure it out. The select_by_pos by default should take only trades from trading pool.

It does,  but your code is bad . . .  the first position in the pool is 0 the last is OrdersTotal() - 1 

Some info here:  Loops and Closing or Deleting Orders 

Reason: