HELP in - stop opening multiple order after takeprofit was hit.

 

i have more than 5 open trades in 1 bar and i want the ea to stop opening order after takeprofit was hit.

bool NewBar()
  {
  /* Update with a new bar and reset BarTraded if it's new */
   static datetime lastbar;
   datetime curbar = Time[0];
   if(lastbar != curbar)
    {
     BarTraded = 0;
     lastbar=curbar;
     return (true);
    }
   else
    {
     return(false);
    }
  }

  i try to insert this to my ea but its only opening 1 order per bar but i prepare to put multiple order in 1 bar. is there other mean to stop opening multiple order after takeprofit was hit?

 

Why did you post once per bar code and then expect it do to anything other than once per bar?

Where is your test for takeprofit was hit? (I assume you mean initial target as there is no open order once takeprofit is hit.)

Where is your test to stop opening multiple orders?


Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.

 
WHRoeder:

Why did you post once per bar code and then expect it do to anything other than once per bar?

Where is your test for takeprofit was hit? (I assume you mean initial target as there is no open order once takeprofit is hit.)

Where is your test to stop opening multiple orders?


Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.


i try this but not working. so that i try the code above.

 

for (int a=OrdersTotal(); a>0; a--)
  {if (OrderSelect(a,SELECT_BY_POS,MODE_HISTORY)==true)
    {if (!OrderMagicNumber()==magic && !OrderSymbol()==symb) continue;
     datetime closeT=OrderCloseTime();
    }
  }

if((buy==true || sell==true) && closeT==Time[0]){buy=false; sell=false;}

 any other suggestion please. thanks

 
05121981:


i try this but not working. so that i try the code above.

 

 any other suggestion please. thanks

If you have 5 open orders  OrdersTotal() will return 5  and their positions will be at  4, 3, 2, 1  and 0   so your loop is wrong.  And OrdersTotal() is the number of open orders,  if you want to check the closed orders you need to use something else . . 
 
RaptorUK:
If you have 5 open orders  OrdersTotal() will return 5  and their positions will be at  4, 3, 2, 1  and 0   so your loop is wrong.  And OrdersTotal() is the number of open orders,  if you want to check the closed orders you need to use something else . . 


thanks i will try search other option.
 
Your code
!OrderMagicNumber()==magic && !OrderSymbol()==symb
A nonzero magic number
!True==magic && !OrderSymbol()==symb
OR
False==magic && !OrderSymbol()==symb
Never true
0==magic && !OrderSymbol()==symb
And what a !string translates to I'm not sure (probably zero.)
 
RaptorUK:
If you have 5 open orders  OrdersTotal() will return 5  and their positions will be at  4, 3, 2, 1  and 0   so your loop is wrong.  And OrdersTotal() is the number of open orders,  if you want to check the closed orders you need to use something else . . 


 i try this code but still not working..

for (int a=OrdersHistoryTotal(); a>0; a--)
  {if (OrderSelect(a,SELECT_BY_POS,MODE_HISTORY)==true)
    {if (!OrderMagicNumber()==magic && !OrderSymbol()==symb) continue;
     datetime closeT=OrderCloseTime();
    }
  }

if((buy==true || sell==true) && closeT==Time[0]){buy=false; sell=false;}

 

for (int a=OrdersHistoryTotal(); a>0; a--)
  {if (OrderSelect(a,SELECT_BY_POS,MODE_HISTORY)==true)
    {if (!OrderMagicNumber()==magic && !OrderSymbol()==symb) continue;
     datetime closeT=OrderCloseTime();
     if((buy==true || sell==true) && closeT==Time[0]){buy=false; sell=false;}
    }
  }
 
05121981:


 i try this code but still not working..

If you have 5 closed orders  OrdersHistoryTotal() will return 5  and their positions will be at  4, 3, 2, 1  and 0   so your loop is still wrong.  Also read what WHRoeder wrote above . . .
 
WHRoeder:
Your code
A nonzero magic number
OR
Never true
And what a !string translates to I'm not sure (probably zero.)


i dont know what you trying to say, but i found that useful in selecting orders.. https://www.mql5.com/en/forum/139654 

but i dont know if it is ok when selecting history orders. 

i try this and not working.

for (int a=OrdersHistoryTotal()-1; a>=0; a--)
  {if (OrderSelect(a,SELECT_BY_POS,MODE_HISTORY)==true)
    {if (OrderMagicNumber()==magic && OrderSymbol()==symb) continue;
     datetime closeT=OrderCloseTime();
     if((buy==true || sell==true) && closeT==Time[0]){buy=false; sell=false;}
    }
  }
 
05121981:


i dont know what you trying to say, but i found that useful in selecting orders.. https://www.mql5.com/en/forum/139654 

but i dont know if it is ok when selecting history orders. 

i try this and not working.

 

What does this line do ?  can you explain it ?

if (OrderMagicNumber()==magic && OrderSymbol()==symb) continue;
 
RaptorUK:

What does this line do ?  can you explain it ?

 it will continue to next process.

i try other code.. https://www.mql5.com/en/forum/138894

still not working. 

static datetime closeT;
  for(int a=OrdersHistoryTotal()-1; a>=0; a--)
  {if(OrderSelect(a,SELECT_BY_POS,MODE_HISTORY)==true)
    {if(OrderMagicNumber()==magic && OrderSymbol()==symb && closeT>OrderCloseTime())
      {
       closeT=OrderCloseTime();
       if((buy==true || sell==true) && closeT==Time[0]){buy=false; sell=false;}
      }
    }
  }

 

Reason: