Hi,
I would like some help to create an indicator which can show monthly/weekly profit. I've got only basics on programming and found some similar topics but none of them really helped me. I found out that the best way to do it is to use iTime() which i struggle to get my head around. Can anyone give me some advice on this please ? I would be really grateful, I don't really want to use a pre-made indicator, I really want to get a way to do it.
Thank you.
Here's what I use. Hope this helps.
//+------------------------------------------------------------------+ //| Get Monthly Profits | //+------------------------------------------------------------------+ double GetMonthProfits() { double wp = 0; datetime starttime = iTime(Symbol(), PERIOD_MN1, 0); for(int i=(OrdersHistoryTotal()-1); i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { if(OrderCloseTime() >= starttime && OrderType()!=6 && OrderType()!=7) //&& OrderSymbol() == Symbol() wp += OrderProfit()+OrderCommission()+OrderSwap(); } } return(wp); }
-
if(OrderCloseTime() >= starttime && OrderType()!=6 && OrderType()!=7) //&& OrderSymbol() == Symbol()
That selects deleted pending orders also. You want just buys and sells.
OrderType() == 6, 7 in the history pool? - MQL4 programming forum 2017.11.30 -
datetime starttime = iTime(Symbol(), PERIOD_MN1, 0);
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 2019.05.20 -
wp += OrderProfit()+OrderCommission()+OrderSwap();
Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
"balance" orders in account history - Day Trading Techniques - MQL4 programming forum 2017.11.01Broker History FXCM Commission - <TICKET>
Rollover - <TICKET>>R/O - 1,000 EUR/USD @0.52 #<ticket> N/A OANDA Balance update
Financing (Swap: One entry for all open orders.)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I would like some help to create an indicator which can show monthly/weekly profit. I've got only basics on programming and found some similar topics but none of them really helped me. I found out that the best way to do it is to use iTime() which i struggle to get my head around. Can anyone give me some advice on this please ? I would be really grateful, I don't really want to use a pre-made indicator, I really want to get a way to do it.
Thank you.