credetarud:
Hi,
I can't seem to get this code to work. I want to know drawdown (ideally including swap+commission but I can live without those if needed) created by all running trades for a magic number.
Here is the code I'm using (the EA is bigger but I think that these are the relevant lines):
I have a manually placed trade (buy EURUSD) that is in $1.76 running profit (still open) and yet the Print statement prints 0.
What am I doing wrong? Thanks
I think that deal is only used when looping through history,
instead, replace DealInfo for PositionInfo.mqh
And since that you are looping through the positions anyway, i do not think your code would work anyway.
example: note not tested, just written.
#include <Trade\PositionInfo.mqh> CPositionInfo position; input int MagicNum=0; void OnTick() { Print("ProfitAllPositionsForMagic is " + DoubleToString(ProfitAllPositionsForMagic(),2)); } double ProfitAllPositionsForMagic(void) { double profit=0.0; for(int i=PositionsTotal()-1; i>=0; i--) if(position.SelectByIndex(i)) // selects the position by index for further access to its properties if(position.Symbol()==Symbol() && position.Magic()==MagicNum) profit+=position.Commission()+position.Swap()+position.Profit(); //--- return(profit); }
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
Hi,
I can't seem to get this code to work. I want to know drawdown (ideally including swap+commission but I can live without those if needed) created by all running trades for a magic number.
Here is the code I'm using (the EA is bigger but I think that these are the relevant lines):
I have a manually placed trade (buy EURUSD) that is in $1.76 running profit (still open) and yet the Print statement prints 0.
What am I doing wrong? Thanks