raindrop: Which means if one position is 10 pips in profit, I want to consider it as only 10 pips of profit
That isn't what you are doing. You are computing the sum of pip lots. Find the order with the largest profit remember that and it's lotsize.
@raindrop I am asnwering you a bit late (2 years :D), I read your code, it was good but needed some editings, I think new code should calc all profit
after spread (spread is paid twice during opening and close of the trade). Hope you can use it:
double CalculateProfit() { double CurrentProfit=0; for(int i = OrdersTotal()-1; i >= 0; i--) { double GuessProfit; double DesProfit; OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_BUY && OrderMagicNumber()==MagicNumGen(Symbol())) GuessProfit=(Ask-OrderOpenPrice()-Spread()*2); // Calculate the Profit in Pips. else if(OrderType()==OP_SELL && OrderMagicNumber()==MagicNumGen(Symbol())) GuessProfit=(OrderOpenPrice()-Bid-Spread()*2); //spread is twice in forex CurrentProfit+=GuessProfit; } return(CurrentProfit); }
raindrop
- www.mql5.com
Added topic Account statement is not accurate Hello, I have a question about printing the correct account statement in MT4 so that I can submit it for tax purposes. I am running MT4 build 1170 on Windows 7. I want to print account statement for the year 2018 so I have selected 'custom Added topic How to properly...
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
Hello,
I am trying to write a grid trading EA which opens 4 or 5 trades at one time and I am planning to set profit target in Pips. So I have written a snippet of code to calculate the profit of all the open trades in Pips (regardless of the lot size). Which means if one position is 10 pips in profit, I want to consider it as only 10 pips of profit regardless whether the lot size is 0.01 or 2.5 lots.
However my code has been reaching the wrong profit target if more than one trade is involved in calculation. More the trades open at one time the worse is error in the calculation. I am attaching my code. I would appreciate if some one can pint me in right direction as what is wrong with my code?
Thanks for reading.