- Feature in StrategyTester
- MQL4 FileOpen function
- Simple test to determine if market is closed?
What is a simple method to figure out that the last trade done was a loss?
Look at the history, it shows you if the trade was a loss or profit.
it also tells you in the comments for that trade, if it was because of a stop-loss or take-profit (sl: xxx or tp: xxx)
Look at the history, it shows you if the trade was a loss or profit.
it also tells you in the comments for that trade, if it was because of a stop-loss or take-profit (sl: xxx or tp: xxx)
I tried that. I checked history after the trade had finished, the code was in progress to start a new trade. I had saved the ticket for the
completed trade. I found the trade. I could read a lot of info about the trade but profit was 0 even if the trade had gone to stoploss. So I took another route.
I work with TP and SL so I just keep tab that these leels are reached. Not perfect but will work for now (developing and running strategy tester). If someone has a piece of code I will try it
Code below always show zero profit even though the trade has finished
int TradeResult(ulong ticket,string symbol,string id)
{
Logger("TradeResult In:","Ticket",IntegerToString(ticket),"symbol:",symbol,"TradeId:",id);
if (!HistorySelect(0,TimeCurrent()))
return 0;
mydeal.Ticket(ticket);
ulong morder = mydeal.Ticket();
if(morder)
{
string msymbol = mydeal.Symbol();
double mprofit = mydeal.Profit();
double mprice = mydeal.Price();
string mid = mydeal.Comment();
int mtradetype = mydeal.Type();
string mtradedescr = mydeal.TypeDescription();
Logger("TradeResult Out","Ticket",IntegerToString(morder),"symbol:",msymbol,"Comment:",mid,mtradedescr,DoubleToString(mprofit,2),DoubleToString(mprice,5));
if(mprofit>0)
{
Logger("TradeResult","TradeId:",mid,"Profit");
return 1;
}
if(mprofit<0)
{
Logger("TradeResult","TradeId:",mid,"Loss");
return -1;
}
}
else
Logger("TradeResult","Ticket not found","Ticket",IntegerToString(ticket));
return 0;
}
Hi
What does this mean?
mydeal.Ticket(ticket); ulong morder = mydeal.Ticket(); if(morder) { //---
I think you should select the most recent order by its position's index and I think this is equal to the total history orders minus one.
Hi
What does this mean?
I think you should select the most recent order by its position's index and I think this is equal to the total history orders minus one.
I just save the ticket for the previous trade in "Ticket" and use that to retrieve the data for it. It works. Other data that I receive this way
are for the previous trade so its correct. It is just that mydeal.Profit() is always zero and that is incorrect. I have both SL and TP profit set
and the trade has ended.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use