how should I code so that the first order has tp 40 and if it doesn't close it and open another order so that the second order has tp 30 and closes the first one too??

 
how should I code so that the first order has tp 40 and if it doesn't close it and open another order so that the second order has tp 30 and closes the first one too??
 
Matej Cehelsky:
how should I code so that the first order has tp 40 and if it doesn't close it and open another order so that the second order has tp 30 and closes the first one too??

Inside a grid system? 

Or close all previous similar open orders when the tp of the latest one hits ?

 
Lorentzos Roussos # :

Vo vnútri mriežkového systému? 

Alebo uzavrieť podobné otvorené objednávky, keď dosiahnete všetky predchádzajúce tp najnovšieho?

it is martingale yes all trades
 
Matej Cehelsky #:
it is martingale yes all trades

But you are not keeping them all on the same entry level ( i mean the buys are not on the same reentry price )

 
Lorentzos Roussos # :

Ale nedrží ich všetky na rovnakej vstupnej úrovni (myslím tým, že nákupy nie sú za rovnakú cenu opätovného vstupu)

nie, väčšina z nich má medzi sebou vzdialenosť 10 pipov
 
Matej Cehelsky #:
nie, väčšina z nich má medzi sebou vzdialenosť 10 pipov

You will need to retain the latest order ticket (or deal ticket) in memory . 

Then you will check on tick if that order has closed in profit , if it has you will call your closer and close all the orders with that magic number

Note the following does not assign a ticket # to the ticket retention variable which you should do everytime you open a new trade 

#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
bool checkContextBusy=false;
int latestOrderTicket=-1;//you store the latest opened order ticket here 
int magicNR=316;
int OnInit()
  {
//looks for the latest opened order in case of reinit
  latestOrderTicket=find_latest_open_order(_Symbol,magicNR);
  checkContextBusy=false;
//---
   return(INIT_SUCCEEDED);
  }
  
int find_latest_open_order(string _symbol,int _magic_nr){
int found=-1;
datetime latest=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
if(OrderMagicNumber()==_magic_nr&&OrderSymbol()==_symbol){
if(OrderOpenTime()>latest){
latest=OrderOpenTime();found=i;
}}}}
return(found);
}
void OnTick()
  {
  //if check context not busy 
    if(!checkContextBusy){
    //set busy 
      checkContextBusy=true;
      check_latest(latestOrderTicket);
    //unset
      checkContextBusy=false;
    }
  }
void check_latest(int &_ticket){
//if theres a ticket 
  if(_ticket!=-1){
  //select the order 
    if(OrderSelect(_ticket,SELECT_BY_TICKET)){
  //if it is no longer open
    if(OrderCloseTime()!=0){
  //and it closed in profit 
    if((OrderProfit()+OrderSwap()+OrderCommission())>0.0){
  //then dump the ticket 
    _ticket=-1;
  //and close all order 
    //call closer here         
  }}}}
}
void OnDeinit(const int reason)
  {
   
  }
 
This code will flood the CPU and will result in  delays or freezing of the platform it’s a redundant way of coding besides such a strategy is based on a grid system I am sure you need to go through examples here on mql5 
 
Amos Tsopotsa # :
This code will kill the CPU and result in lag or freeze of the platform, it is a redundant way of coding except that such a strategy is based on a grid system. I'm sure it's necessary to use the examples here on mql5
and where can I find examples?
 
Amos Tsopotsa #:
This code will flood the CPU and will result in  delays or freezing of the platform it’s a redundant way of coding besides such a strategy is based on a grid system I am sure you need to go through examples here on mql5 

Which part will flood the CPU ?