@William Nascimento @nicholish en @kei yakushiji@David Diez @Ahmed Ahmed @AHMED KHALIFA AHMED ABULFATEH ALI ABULFATEH
Hi Programmers, am new in mql5 language and i was trying to make an EA that would calculate TotalProfits in History either Buy || sell Trades, even both ..... But ended up failing
Here is my code below!
double HistoryTotalProfit_Func() { uint TotalNumberOfDeals=HistoryDealsTotal();
TotalNumberOfDeals will be 0 because you have not first called HistorySelect() or HistorySelectByPosition().
TotalNumberOfDeals will be 0 because you have not first called HistorySelect() or HistorySelectByPosition().
Thanks it worked..... But i tried to calculate TotalDealProfitInHistory Based on TradeComments but i failed... gives 0... seems like deals with profit dont have Tradecomments i.e buy,out and sell,out!
whats your sugggestion? here is my code below
#include <Trade\Trade.mqh> CTrade trade; input string TradeCommentBuy="v25_BuyStop"; input string TradeCommentSell="v25_SEllStop"; double Ask,Bid; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); HistoryTotalProfit_Func(); Comment(" HistoryTotalProfit : ", HistoryTotalProfit_Func()); }//ontick double HistoryTotalProfit_Func() { uint TotalNumberOfDeals=HistoryDealsTotal(); ulong TicketNumber; double DealProfit; double DealCommission,DealSwap; string DealComment; double TotalProfit=0; HistorySelect(0,TimeCurrent()); for(uint i=0; i<TotalNumberOfDeals; i++) { TicketNumber=HistoryDealGetTicket(i); ENUM_DEAL_TYPE DealType=(ENUM_DEAL_TYPE)HistoryDealGetInteger(TicketNumber,DEAL_TYPE); DealComment=HistoryDealGetString(TicketNumber,DEAL_COMMENT); if(TicketNumber>0) { if(DealComment==TradeCommentBuy || DealComment==TradeCommentSell)//when i use DealComment it gives 0 as TotalProfitInHistory! why? { DealProfit=HistoryDealGetDouble(TicketNumber,DEAL_PROFIT); DealCommission=HistoryDealGetDouble(TicketNumber,DEAL_COMMISSION); DealSwap=HistoryDealGetDouble(TicketNumber,DEAL_SWAP); TotalProfit=TotalProfit+DealProfit+DealSwap+DealCommission; } } } return(TotalProfit); }// HistoryProfit_Func()
- Ifadatty999: But ended up failing
“Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
How To Ask Questions The Smart Way. 2004
When asking about code -
Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
- Don't know about MT5, but on MT4 you can't modify comments.
Metaquotes language: OrderComment() is not able to be modified - Expert Advisors and Automated Trading - MQL5 programming forum 2013.08.10Not a good idea to use comments, brokers can change comments, including complete replacement.
Thanks it worked..... But i tried to calculate TotalDealProfitInHistory Based on TradeComments but i failed... gives 0... seems like deals with profit dont have Tradecomments i.e buy,out and sell,out!
whats your sugggestion? here is my code below
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
@William Nascimento @nicholish en @kei yakushiji@David Diez @Ahmed Ahmed @AHMED KHALIFA AHMED ABULFATEH ALI ABULFATEH
Hi Programmers, am new in mql5 language and i was trying to make an EA that would calculate TotalProfits in History either Buy || sell Trades, even both ..... But ended up failing
Here is my code below!