- Help you with what? You haven't stated a problem. Show us your attempt and state the nature of your problem.
- Find the last closed order, test it.
bool hasHitSL = MathAbs( OrderClosePrice() - OrderStopLoss() ) < MathAbs( OrderClosePrice() - OrderTakeProfit() );
- Not a good idea to use comments, brokers can change comments, including complete replacement and some do not mark closed orders with a reason.
Hello guys!
Im struggling with function which gives true when the latest closed order had been closed by stop loose. Could you help me ?
Thanks in adnvance!!!
As you neglected to show us your source code, I would surmise that you don't know how to code and that you are looking for others to do the work for you.
If that is the case, then perhaps you can hire someone from the freelance section to assist you.Freelance
If you don't wish to hire someone, then you will need to learn to code.
What you are trying to do can be done using an EA.
For that you can read over the documentation.
Documentation
For working examples of how to code, you can review the code base.
CodeBase
- www.mql5.com
I meant I need to write such a function.
More precisely:
OrderSelect(0,SELECT_BY_POS,MODE_HISTORY);
if(????????) <------- (I cant figure out what condition
{ checks if it was close by stop loose)
a=1;
}
First thing....
Second thing...
I told you what you can do. You can learn to code, look over the code base and find something similar for an example to work from, or hire someone to do it properly for you.
You've made no attempt to show your actual work. If you want help, you have to put forth an effort.
If you do show your work, please include a FULL copy of your code and not just a random snippet so that we can properly evaluate what you've done.
Third thing...
You mentioned you needed to create a function.
Here is the documentation page for functions.
https://www.mql5.com/en/docs/basis/function
bool LastOrderClosedByStop() { int ticket =-1; datetime last_time = 0; for(int i=OrdersHistoryTotal()-1;i>=0;i--) if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)&&OrderSymbol()==_Symbol&&OrderCloseTime()>last_time) { last_time = OrderCloseTime(); ticket = OrderTicket(); } if(!OrderSelect(ticket,SELECT_BY_TICKET)) { Print("OrderSelectError: ",GetLastError()) return false; } // credit to whroeder --> return fabs(OrderClosePrice()-OrderStopLoss()) < fabs(OrderClosePrice()-OrderTakeProfit()); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Im struggling with function which gives true when the latest closed order had been closed by stop loose. Could you help me ?
Thanks in adnvance!!!