Close Positions
-
Greetings,
Just a quick questions, assumingly a position is opened, how do we close the position when the candle closes. I am not sure how to explain it. But in simple terms, you are opening and closing the position on the same candle. However, the difference is that your are closing the position when the candle closes.
Shared Project: https://fxdreema.com/shared/eMildxlRb
Your response is much appreciated
-
@ramimoujaes That is not possible. MT4 doen not know when the candle is closed until a new candle is open. We human traderr see a closed candle, but MT4 just organizes quotes visually. The only way for an EA to know when a candle is closed is be waiting for the first tick of the next candle.
-
Greetings @l-andorrà ,
I see. Well, how about the following:
Let's assume, the EA opened a position, and I want the EA to close on the next candle's opening price. How do we do that?
-
@ramimoujaes It depends. Do you want it to be closed the exact candles AFTER it was open or later?
-
Greetings,
I am not sure I understand. Why don't you show me both ways.
My logic is that if it opened a position on the first candle, then close the position on the second candle opening price.

If you notice from the picture above, it opened a selling position on a candle based on the condition, and it took a while for it to close. I do not want that. I want when any position is opened, if it did not take profit, then I want it to close on the next candle's opening price.
Your response is much appreciated
-
@ramimoujaes So essentially you need the EA to make some profit at the exact candle the trade opened at. Right? If I understand it correctly, if the trade is in profit, do nothing but if in loss close the trade at the open of the next candle. Correct?
-
Greetings @l-andorrà,
Well essentially, the ea has a take profit, but if it did not take profit, then just close at the next candle's opening price.
I'm going to assume, yes you are correct.
-
@ramimoujaes This means you give the EA just on candle to determine if the trade should be closed or open. Right? Are you sure is that the criteria you need to implement?
-
Greetings @l-andorrà,
Yes I am sure
-
@ramimoujaes You will need to create a variable to count bars. Try this:
-
Greetings @l-andorrà,
FYI, I use mt5

-
Kindly explain more, where can I find this on mt5, and how and where do I place it in my project?
The shared project is below:
https://fxdreema.com/shared/Lv7W7Crzd
Where would I place your answers in my project.
- A screenshot would be very helpful
-
Greetings,
Please understand that I am not expert. So, you might want to baby-step me through the procedure.
I shared my project so that you can see where I am at, and in order for you to visually assist me.
-
@ramimoujaes You can use the equivalen blocks for MT5 :). My explanation:
a) Blocks 1 and 6 are those supposed to open buys. You need to add a 'Modify Variables' block at the bottom of it to count the number of candles after the one opening the trade.
b) All blocks headed by block ID 2 are those counting eavery new candle after the first one. The variable adds +1 every time a new bar is open. Then it is compared to check if there is profit and if so, closeing immediately the trade. If not, a new candle is counted.
c) Both blocks on the 'on trade' tab are used to reinitialize the variable every time the trade is closed.
d) You need to replicated this same structure for the sells.
-
Greetings @l-andorrà,
Thank you for your response. I would like you to have a look and help me fix the following errors.

I kindly request from you to help fix these errors, but please tell me the solution in details.
Also, if you can have a look at the entire project, and have a look if I did anything wrong that would be great.
Shared Project: https://fxdreema.com/shared/IIJb4XA0d
-
@ramimoujaes Those errors are not my fault. You need to create 2 variables. You can call them 'counter_buys' and 'counter_sells', for example. Here you will learn how to create them:
https://fxdreema.com/instructions/builder/constants-and-variables
Then you insert 'counter_buys' in block 7 (in the same place where you typed that name) and 'counter_sells' in block 8. Same with blocks 17 and 18 on the 'on trade' tab.
Finally you duplicate the tree structure headed by block 9. That structure is for buys only. Now you need to duplicate it for sells. Obviously you need to modify the content of blocks 10, 11 and 12 for sells. Try it and let me know.
-
Greetings @l-andorrà ,
I read it. And I still do not understand. When you open variable. What do you type in the " type", "name", "value", "description" section. I read the link you provided previously and I am still lost.
As mentioned previously, if you can literally tell me, word for word, step by step what to type in, that would be great.
As mentioned previously, I am not a programmer, and I still have no idea what to type in.
-
@ramimoujaes Both variables should be of a 'double' type. Then you type the name you want (I suggested those but you can choose any one) in the 'Name' box. And finally you type number zero in the 'value' box. You can the position them as explained in the Intructions page I suggested.
-
Greetings @l-andorrà,
Once again, thank you for your cooperation.
Kindly notice the errors found in the image below:

Below you can find the shared project:
https://fxdreema.com/shared/DtccIOdjc
As you can see, I pretty much did everything you asked for, unless I am mistaken (which I am positive, I did a mistake).
Can you please tell me:
*How to fix the errors?
*Are the block ID's correct?
*If you could please check if I did everything right, and not miss something or type in something by mistake.
Thank you so much for your kindly response
-
Greetings @l-andorrà ,
Apologies for the previous post. I figured it out.
Kindly have a look at the image below:

It is suppose to close the position immediately on the next candle opening. But it did not do that.
Below, you can find my shared project:
https://fxdreema.com/shared/j7AF17Qxc
Your kindly earliest response is much appreciated.