Download MetaTrader 5

How to set TP on next candle close once it closes above the OrderOpenPrice

To add comments, please log in or register
Macalan
11
Macalan  

Hello,

Can anyone help me with the following? I'm currently learning the MQL4, but so far I've never seen anyone talk about how to set a take profit once the candle closes in profit. 

for example: EA opens a buy order at a certain price, after a few candles we are finally in profit and I'd like to set a take profit once the candle closes. 

Any advice or hints on how to code this is much appreciated 

Many thanks

Richard 

honest_knave
Moderator
2405
honest_knave  

You can't reliably detect the end of a candle. But you can ascertain the start of a new candle.

 So view your query more as:  

after a few candles we are finally in profit and I'd like to set a take profit once the next candle opens.    

Luckily, most of the key ingredients for what you want have already been extensively covered in previous threads. 

First of all, have a search for how you run code once per bar (rather than every tick).

Then you'll need to search for how to loop through all the open orders  (so you can find the ones that have moved into profit). Make sure you use code that loops backwards through the orders (i--).

Then you'll need to add the code to close an order when necessary. 

Macalan
11
Macalan  
honest_knave:

You can't reliably detect the end of a candle. But you can ascertain the start of a new candle.

 So view your query more as:  

Luckily, most of the key ingredients for what you want have already been extensively covered in previous threads. 

First of all, have a search for how you run code once per bar (rather than every tick).

Then you'll need to search for how to loop through all the open orders  (so you can find the ones that have moved into profit). Make sure you use code that loops backwards through the orders (i--).

Then you'll need to add the code to close an order when necessary. 

 

Excelent, I can't thank you enough. That's exactly what I needed as I couldn't wrapped my head around on how to code it. I was trying to find this topic in the previous threads but couldn't find it. Going to try and dig a bit more.

 

Thanks again. 

JD4
1101
JD4  
honest_knave:

You can't reliably detect the end of a candle. But you can ascertain the start of a new candle.

 So view your query more as:  

Luckily, most of the key ingredients for what you want have already been extensively covered in previous threads. 

First of all, have a search for how you run code once per bar (rather than every tick).

Then you'll need to search for how to loop through all the open orders  (so you can find the ones that have moved into profit). Make sure you use code that loops backwards through the orders (i--).

Then you'll need to add the code to close an order when necessary. 

 

Sort of follow up question from someone else.  In regards to the detecting the end of the candle, can't you just look for the close of the candle (or bar in case of bar chart)?
To add comments, please log in or register