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

Back to topics list To post a new topic, please log in or register
avatar
3
Macalan 2015.06.17 16:09
 

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 

  

avatar
735
honest_knave 2015.06.17 16:56 #
 

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. 

 

avatar
3
Macalan 2015.06.17 17:18 #
 
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. 

avatar
313
JD4 2015.06.24 05:52 #
 
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)?
Back to topics list  

To add comments, please log in or register