how is history indexed?

 
My history data shows the last closed position below the table while all the previous were above it. Total=OrdersHistoryTotal() " for(int i=0;i =0;i--) " Please which of this will select the last close order if the table is as above or can someone explain how the history table is arranged.
 

This should look though history going backwards from most recent to earliest trades:

         for(i=0;i<Total;i++){  
            OrderSelect(OrdersHistoryTotal()-i-1,SELECT_BY_POS,MODE_HISTORY);
 
    static datetime lastClose;  datetime lastClosePrev = lastClose;
    for(int pos=0; pos < HistoryTotal(); pos++) if (
        OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders w/ 
    &&  OrderCloseTime()    > lastClosePrev             // not yet processed,
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  OrderType()         <= OP_SELL){    // Avoid cr/bal forum.mql4.com/32363
 
WHRoeder:


thanks for your timely response.

This has been the problem with my EA ever since. i have even posted this problem earlier before now @ https://forum.mql4.com/39521

as

"my Ea keeps opening same type position when it opens one and make profit it will
open another one on this same direction after takeprofit point even if trade is about
to go the other way. Pls i need a simple order management code that will prevent
this from happening. i want the one that will wait until opposite signal is

available before making the next trade after it has finished with the current order by takeproft."

when i finish with this info you have given me, i will attach the EA for you to see if there is any other error.

Thanks once again for your help.

 
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
if (AccountBalance()>10.00)
{

OrderSelect(0,SELECT_BY_POS,MODE_HISTORY);
if (OrderCloseTime()>TimeCurrent()+60)
{

Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}


}
}

 

  1. OrderSelect(0,SELECT_BY_POS,MODE_HISTORY);
    if (OrderCloseTime()>TimeCurrent()+60)
    {
    If there is no history, this code breaks. If there is, this checks if the oldest order (whatever pair, whatever EA) closed one minute in the future.
 
WHRoeder:

  1. If there is no history, this code breaks. If there is, this checks if the oldest order (whatever pair, whatever EA) closed one minute in the future.

please what will be the right code if i don't want the same order type with same symbol to open one after another!

pls help me out.

 
ayogbenga2003:

please what will be the right code if i don't want the same order type with same symbol to open one after another!

pls help me out.


for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
 
what does this mean
if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {

int OrderType( )
Returns order operation type for the currently selected order. It can be any of the following values:
1 OP_BUY - buying position,
2 OP_SELL - selling position,
3 OP_BUYLIMIT - buy limit pending position,
4 OP_BUYSTOP - buy stop pending position,
5 OP_SELLLIMIT - sell limit pending position,
6 OP_SELLSTOP - sell stop pending position.

1<2 means OP_BUY<OP_SELL. Is this what the above means? "OrderType() <=OP_SELL"


pls help me out
 
Is this what the above means? "OrderType() <=OP_SELL"
Means it is a BUY (1) or a SELL (2). Both are <= 2. It is not a cr/bal entry. I posted the link had you bothered to look.
Reason: