Hello.
I'm just done coding an expert, having done extensive tests on the strategy tester to ensure it works as expected, and it did. Today, I have placed the expert on a demo account, and that is where all my trouble came in.
The EA is supposed to calculate a new position size depending on the outcome of the previous trade. Non of that is being done, despite the fact that it is working quite well in the strategy tester. Tried installing another build, all in vain.
I'm totally lost. I'm beginning to develop doubts on the strategy tester and mt5 as a whole, after spending a whole year learning mql5.
This is urgent pls.
Any help or advice will be appreciated.
Hello Nelson , how are you acquiring the latest trade outcome and how (and are you) storing it ?
Hello.
I'm just done coding an expert, having done extensive tests on the strategy tester to ensure it works as expected, and it did. Today, I have placed the expert on a demo account, and that is where all my trouble came in.
The EA is supposed to calculate a new position size depending on the outcome of the previous trade. Non of that is being done, despite the fact that it is working quite well in the strategy tester. Tried installing another build, all in vain.
I'm totally lost. I'm beginning to develop doubts on the strategy tester and mt5 as a whole, after spending a whole year learning mql5.
This is urgent pls.
Any help or advice will be appreciated.
Don't be discouraged, sometimes it's just about a buggy line in the code. Could you share a piece of code, so one can help ?
Hello Nelson , how are you acquiring the latest trade outcome and how (and are you) storing it ?
double LossCheck() { uint TotalNumberOfDeals=HistoryDealsTotal(); ulong TicketNumber=0; long OrderType, DealEntry; double OrderProfit=0; string MySymbol=""; long DealMagicNumber=0; int count_losses=0; int last_count=0; double NetLoss=0; double LastLoss=0; double balance=0; //get hist HistorySelect(StartTime,TimeCurrent()); //go through all deals for(uint i=0; i<TotalNumberOfDeals; i++) { //look for ticket number if((TicketNumber=HistoryDealGetTicket(i))>0) { //get the profit OrderProfit=HistoryDealGetDouble(TicketNumber,DEAL_PROFIT); //get the type OrderType=HistoryDealGetInteger(TicketNumber,DEAL_TYPE); //get currency pair MySymbol=HistoryDealGetString(TicketNumber,DEAL_SYMBOL); //get deal entry type to check for close types DealEntry=HistoryDealGetInteger(TicketNumber,DEAL_ENTRY); //Deal magic no. DealMagicNumber=HistoryOrderGetInteger(TicketNumber,ORDER_MAGIC); //if currency pair fits if(MySymbol==_Symbol && DealMagicNumber==Magic) //if it is abuy or a sell order if(OrderType==ORDER_TYPE_BUY || OrderType==ORDER_TYPE_SELL) //if the order was closed if(DealEntry==1) if(DealMagicNumber==Magic) { if(OrderType==ORDER_TYPE_BUY || OrderType==ORDER_TYPE_SELL) { if(OrderProfit<0 && last_count!=count_losses+1) { count_losses++; last_count=count_losses; NetLoss=NormalizeDouble(LastLoss+OrderProfit,2); LastLoss=NetLoss; } if(OrderProfit>0) { balance=NormalizeDouble(NetLoss+OrderProfit,2); if(balance>0) { count_losses=0; last_count=0; NetLoss=0; LastLoss=0; balance=0; } else { NetLoss=balance; LastLoss=NetLoss; balance=0; } } } } } } return(NetLoss); }
Don't be discouraged, sometimes it's just about a buggy line in the code. Could you share a piece of code, so one can help ?
Problem is, I cannot figure out the problem in strategy tester as it works just fine.
This line
uint TotalNumberOfDeals=HistoryDealsTotal();
should be AFTER
HistorySelect(StartTime,TimeCurrent());
And by the way on a live account you need to use something like
HistorySelect(StartTime,INT_MAX);
As otherwise you could
miss deals.
This line
should be AFTER
And by the way on a live account you need to use something like
As otherwise you could miss deals.Thank you. My faith is restored. Let me rewrite the code.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello.
I'm just done coding an expert, having done extensive tests on the strategy tester to ensure it works as expected, and it did. Today, I have placed the expert on a demo account, and that is where all my trouble came in.
The EA is supposed to calculate a new position size depending on the outcome of the previous trade. Non of that is being done, despite the fact that it is working quite well in the strategy tester. Tried installing another build, all in vain.
I'm totally lost. I'm beginning to develop doubts on the strategy tester and mt5 as a whole, after spending a whole year learning mql5.
This is urgent pls.
Any help or advice will be appreciated.