I want to build a simple martingale strategy to practice with, but i am confused as to how i can check the result of the last trade, whether it hit t.p or s.l. I'd really appreciate it if anyone can help me with the code to use. Thanks in advance :)
- what happened to the last order?
- How to get the open price of the last open trade?.. the last open trade is not yet closed.
- Help: Determine closed order if profit or loss
double deal_profitY() { ulong ticket; datetime closeTime=0; bool found=false; double deal_profit=0; //ulong order_magic; string symbol; if(HistorySelect(0,TimeCurrent())) { for(int i=HistoryDealsTotal()-1; i>=0; i--) { ticket=HistoryDealGetTicket(i); symbol=HistoryDealGetString(ticket,DEAL_SYMBOL); if((HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_OUT)&&symbol==Symbol()) { found=true; deal_profit=HistoryDealGetDouble(ticket,DEAL_PROFIT); break; } } } return ( deal_profit); }
This sample returns only the result of the last deal, not the last position, nor the last trade. To get the result of the position, you have to loop through all the deals which belong to a specific position ticket. And regarding a trade, assuming that in such a strategy the definition of a trade is not just one position, you have to do this for every position in a loop as well.
Unfortunately it´s a pity that there are no standard-classes which handle this for you and no standard-structs which simply return all informations about a deal. Functions like HistoryDealGetInteger() make the code really unreadable imho, but thats how it is. You should create some own libs if you want to create code which you will be able to read after a longer time without any headache.
Unfortunately it´s a pity that there are no standard-classes which handle this for you and no standard-structs which simply return all informations about a deal. Functions like HistoryDealGetInteger() make the code really unreadable imho, but thats how it is. You should create some own libs if you want to create code which you will be able to read after a longer time without any headache.
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