Help with a Loop

 

hej guys ,,i need little help with my EA 

the idea is to open a new order when an exciting order hits TP 

B =OrderSend(Symbol(),OP_BUY,lot,Ask,Slippage,0,Ask+TP*pte,"",MagicNumber,0,Green);    //entry orders
   
        
 
 //+-------------------***********************-----------------------------------------------+
 
 

 for( k = (OrdersTotal()-1); k >= 0; k --)
    {
    if (OrderSelect(k, SELECT_BY_POS, MODE_TRADES)) if(OrderSymbol()==Symbol())     {
       tp=OrderTakeProfit();
       cl=OrderClosePrice();
           if(tp == cl)     B2 =OrderSend(Symbol(),OP_BUY,3*lot,Ask,Slippage,0,Ask+TP*pte,"",MagicNumber,0,Green);    
   }
   }                                                                                 // in this loop i'm trying to open a new order when  order "B"   hits Takeprofit
                                                                                    

so my question is : what kind of parameters should i fill in the "for loop "  so it will do the job ,,thanks  in advance 

 
Amin0xy:

hej guys ,,i need little help with my EA 

the idea is to open a new order when an exciting order hits TP 

so my question is : what kind of parameters should i fill in the "for loop "  so it will do the job ,,thanks  in advance 

Documentation

https://docs.mql4.com/


Book & Tutorial

https://book.mql4.com/


Suggestion

If you want a new ticket to be opened when the previous is closed via the takeprofit, then you will need to reference the trade history and evaluate why the ticket closed.

Take a look at the OrderSelect() and MODE_HISTORY. The following page provides an example of how to properly select tickets.

https://docs.mql4.com/trading/orderselect

- Jack


MQL4 Reference
MQL4 Reference
  • docs.mql4.com
MetaQuotes Language 4 (MQL4) is a built-in language for programming trading strategies. This language is developed by MetaQuotes Software Corp. based on their long experience in the creation of online trading platforms. Using this language, you can create your own Expert Advisors that make trading management automated and are perfectly suitable...
 
The problem is not in the loop.
If order B hits its Take Profit, then it will no longer appear in the list of open orders (MODE_TRADES), but in the list of historical orders (closed) (MODE_HISTORY). For the loop you will have to use OrdersHistoryTotal () instead of OrdersTotal ().

On the other hand, you should not compare doubles in this way (if (tp == cl)), and also you have to take into account that the order will not always be closed at the exact price established in the Take Profit (if it is a buy order, it will be closed at that price or above and if it is a sell order it will be closed at that price or below).

You can start with this.