You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
@Mohamad Zulhairi Baba I modified your trade closer function to work with mine. I believe the idea you were implying was to use the tick.bid/tick.ask correct? I tried that and it did not work. Funny thing is that I don't get an error in the backtester Journal either. Any thoughts on this?
You didn’t loop it correctly.
OK! But you will never be able to align two orders in the same direction in such a way that you will be able to close of the first trade at exactly the same price as the open of the second order, every time 100% of the time.
You will be only able to do it some of the times but not on every attempt. If there is a Spread, then that is simply impossible, even if you use pending orders!
The only way to achieve that is with Zero Spread, but such accounts then have commission associated with it.
So, you can attempt to code this as much as you want. It will never be possible as long as there is a spread. And slippage only makes it worst!
I know. That is why I deleted that comment because I quickly realized I hadnt called the tradecloser in my main script. I did now and it does the same thing as before. It does not close the last trade on the exact same price as the next open. Here is the code for the function reposted below:
Your code have many loopholes.
OK! But you will never be able to align two orders in the same direction in such a way that you will be able to close of the first trade at exactly the same price as the open of the second order, every time 100% of the time.
You will be only able to do it some of the times but not on every attempt. If there is a Spread, then that is simply impossible, even if you use pending orders!
The only way to achieve that is with Zero Spread, but such accounts then have commission associated with it.
So, you can attempt to code this as much as you want. It will never be possible as long as there is a spread. And slippage only makes it worst!
Fernando, I appreciate this comment! The problem is that, with spread, I was able to replicate this when trading manually on a live account. I sold one lot first then opened a pending order of 2 lots 3 pips above the first trade and it closed the first trade and opened the second trade at the exact same price--with spread being taken account of of course.
Mohamad, I appreciate the positive feeback. I am a newbie at mql4 but I am trying to learn.
Fernando, I appreciate this comment! The problem is that, with spread, I was able to replicate this when trading manually on a live account. I sold one lot first then opened a pending order of 2 lots 3 pips above the first trade and it closed the first trade and opened the second trade at the exact same price--with spread being taken account of of course.
No, you were only able to replicate this because conditions were favorable to you during the test. Had the price continued against you indefinitely, you would never have been able to close the first order at the same price as the open of the second order. Again I repeat, your math is faulty.
EDIT: How can a pending order automatically close the first order? That is not possible on MT4!
No, you were only able to replicate this because conditions were favorable to you during the test. Had the price continued against you indefinitely, you would never have been able to close the first order at the same price as the open of the second order. Again I repeat, your math is faulty.
EDIT: How can a pending order automatically close the first order? That is not possible on MT4!
Sorry, but what you have described is simply not possible! A pending order can only trigger a market open, it cannot trigger the close of another order.
Plus, it cannot also do this at the same price at exactly the same time, because it is just impossible for orders in the same direction.
A Buy order opens at the Ask and closes at the Bid, and a Sell order opens at Bid and closes at Ask.
The only time two orders can open/close (one opens while the other closes) at the exact same price and time is if they are opposite orders, one Buy and the other Sell.
EDIT: Plus, you have already been told this on your other thread, but continue to insist on it:
So perhaps there is a language barrier issue here so please correct me if I am wrong... You intend to open a trade in the same direction with more volume as the price moves against the position. So for example
1 lot Sell goes 3 pips underwater.
You open a 2 lot sell and immediately close the one lot sell? By all accounts of your description, that is what you intend to do, correct?
So what you're saying is that you want a position of 1 -- which you then open a different position of 2 while simultaneously closing 1 leaving you with 2. You just blew 1 spread and 1 commission for no reason. Why??? All you had to do was leave the original open and add 1 to it.