Hi all,
Intro
I started learning MQL4 3 years ago to write some tools and EAs. Not a fantastic programmer by any long shot, but I get by.
Why Do I Need This
Seeing a lack of CloseOrder scripts that utilise the OrderCloseBy function, i decided to write one myself.
What is OrderCloseBy()?
It is a function that closes two opposite tickets, saving on spread and commission. If you were to close both tickets normally, you would incur double spread and commission. If you do any kind of hedging, you would want to use this function to effectively half those costs.
This function is also present in the MT4/MT4 close order panel.
What is this?
It is a script that:
Intro
I started learning MQL4 3 years ago to write some tools and EAs. Not a fantastic programmer by any long shot, but I get by.
Why Do I Need This
Seeing a lack of CloseOrder scripts that utilise the OrderCloseBy function, i decided to write one myself.
What is OrderCloseBy()?
It is a function that closes two opposite tickets, saving on spread and commission. If you were to close both tickets normally, you would incur double spread and commission. If you do any kind of hedging, you would want to use this function to effectively half those costs.
This function is also present in the MT4/MT4 close order panel.
What is this?
It is a script that:
- Resolves opposite tickets using OrderCloseBy().
- Closes remaining open orders
- Closes pending orders
in this order.
Why Am I Sharing This
I thought it might help someone. I'm also not the best of coders. I try to write cleanly and efficiently as possible. Maybe people can find a more efficient way to do this. I also try to annotate my code clearly so other people can learn from it and use it in their own code.
You are free to use/modify the code in any way. E.g. You might just want to close all opposite open orders only. The code is easy enough to figure out.
Final Thoughts
Hope it helps someone out
Attached File(s)
CloseHedgeByCliffJaded.mq4
24 KB
|
502 downloads
Leave the Gun, Take the Armani