Last Open Order after take profit

 

Hi there,

I am studying to learn about E.A. and I came across a problem that is beyond my knowledge, I have already tried and I have not been able to find a solution.

The think is,  I need to know what the last opening price is, after the last take profit, I'm doing this loop, but after the last order successfully makes profit, the price does not decrease in the E.A, for exemple:


orderpricet/pCurrent price
3800750 700
2700650 700
1 500450 700

         {

             if (OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==True)

                  {

                     if(OrderType()==1)

                        {

                              if(OrderOpenTime()> LastOrderTime)

                                   {

                                       LastOrderTime   = OrderOpenTime();

                                       LastOrderPrice  = OrderOpenPrice();

                                   }

                              else     continue;    

                         }

                     else   continue;

                  }

               else continue;

         }

         Alert("LastOrder",LastOrderPrice);


This loop is looking for the last value, for example the order 3, but if the last order (order 3) reaches the take profit, and is closed, the loop continues showing the value of the highest in case the order 3, instead of reduce the value to the last order (in this case order 2). If I stop and start It again, the E.A. return the order 2.

Best Regards 

 
FORMAT YOUR CODE
 
for(invisible loop){
   if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)){
      if(OrderType()==OP_SELL){
         if(OrderOpenTime()>LastOrderTime){
            LastOrderTime   = OrderOpenTime();
            LastOrderPrice  = OrderOpenPrice();
            Alert("LastOrder",LastOrderPrice);
         }
      }
   }
}
 
Chad Magruder:
Hi, thank you for your help, but unfortunately it's working the same way I did, like you show, keeping return me the last value, after this order is closed by take profit.

I wonder if I need to put something parameter to clean last close order? I really don't know if its needed.

My objective is to put order sells, for exemplo with  100 pips, and take profit with 20 pips, far from the last order, so, imagine I'm starting now, putted sell order EURUSD, with 1.14000, next sell order will be 1.14100, order will close when take profit is 1.14080, next one is 1.14200 and close with 1.14180, and so on, the think is, when last order 1.14200, reaches take profit 1.14180, because the price know is 1.14150, this loop continues show me last open sell order is 1.14200, and will put next order on 1.14300, but my intention is to put the same last order closed at 1.14200 again, for this I need to know last open order is 1.14100 and put the 1.14300 just in next time, if the order 1.14200, take profit 10 times, I'd like to put this same order 10 times either.

If I stop(remove) my E.A code form MT, or I recompile my code on ME. I take the last value, 1.14100, like this I can put my next order on 1.14200, but I have to close it severals times.

My code (I removed some tests), but the part of I need to make work is this (I changed the values to simplify and print):

//Váriaveis movéis 
 
extern int TakeProfit = 20; //LUCRO
extern double Lote = 0.02; //Valor padrão do lote que será inserido
extern double NextOrder = 0.00050; //Pips para inserir a proxima ordem, baseado no valor da ultima aberta

//Variaveis fixas

extern int Slippage   =  3; //Order slippage
datetime LastOrderTime;
extern int LastOrderTicket;
extern double LastOrderPrice = 0.00000;
extern double NextOrderPrice = 0.00000;
extern double ValorOrdem;
double closeprice;
double Price = 0;
double PriceBid = Bid;
datetime  OrderCloseTime();

int OnInit()
  {
//--- create timer
   EventSetTimer(60);
   OrderSend(Symbol(),OP_SELL,Lote,Bid,Slippage,0,Ask-TakeProfit*Point,"teste",0,0,Red);
   return(INIT_SUCCEEDED);
  }

void OnTick()
{
      for(int j=0;j<OrdersTotal();j++) 
       if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)){
       if(OrderType()==OP_SELL){
         if(OrderOpenTime()>LastOrderTime){
            LastOrderTime   = OrderOpenTime();
            LastOrderPrice  = OrderOpenPrice();
     //       Alert("LastOrder",LastOrderPrice);
         }
      }
        NextOrderPrice=LastOrderPrice+NextOrder;
        if (NextOrderPrice<Bid)
            {
            OrderSend(Symbol(),OP_SELL,Lote,Bid,Slippage,0,Ask-TakeProfit*Point,"teste",0,0,Red);
            }
   }
}


https://i.postimg.cc/90YRnp43/MT4.jpg

Reason: