This is what happens
void lossCalculation() { int total=OrdersTotal(); // Example OrdersTotal == 5 OrderSelect(5,SELECT_BY_POS,MODE_TRADES); //there is no number 5 OrderSelect(4,SELECT_BY_POS,MODE_TRADES); //OrderLots()==0.16 OrderSelect(3,SELECT_BY_POS,MODE_TRADES); //OrderLots()==0.08 OrderSelect(2,SELECT_BY_POS,MODE_TRADES); //OrderLots()==0.04 OrderSelect(1,SELECT_BY_POS,MODE_TRADES); //OrderLots()==0.02 OrderSelect(0,SELECT_BY_POS,MODE_TRADES); //OrderLots()==0.01 This trade is now selected double Loss1=Step*OrderLots(); double Loss2=Step*OrderLots()+Loss1; double Loss3=Step*OrderLots()+Loss2; double Loss4=Step*OrderLots()+Loss3; double Loss5=Step*OrderLots()+Loss4; double Loss6=Step*OrderLots()+Loss5; double Loss7=Step*OrderLots()+Loss6; double Loss8=Step*OrderLots()+Loss7; double Loss9=Step*OrderLots()+Loss8; double Loss10=Step*OrderLots()+Loss9; if (OrderLots()==0.01) {Loss=Loss1;} //true if (OrderLots()==0.02) {Loss=Loss2;} if (OrderLots()==0.04) {Loss=Loss3;} if (OrderLots()==0.08) {Loss=Loss4;} if (OrderLots()==0.16) {Loss=Loss5;} if (OrderLots()==0.32) {Loss=Loss6;} if (OrderLots()==0.64) {Loss=Loss7;} if (OrderLots()==1.28) {Loss=Loss8;} if (OrderLots()==2.56) {Loss=Loss9;} if (OrderLots()==5.12) {Loss=Loss10;} Print ( 0.01); //Print ( OrderLots()); }
look to what you coded
First step to improve your code is to get an understanding of the OrderSelect function, what you can do with it and how to do it.
Second step is to understand the "pool" of orders notion.
Closed orders are kept in a "pool" of closed orders and open orders are in a pool of open orders.
If an open order is closed, get's passed into the history pool or the closed orders pool.
So, if you look for the profit / loss of a closed order, you need to select the order from the history pool.
You can read here about it and if you have any questions or need some more examples, no problem, just ask.
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 calculate my prievious trades losses using a function of the open lots. But it seems there is something wrong because every time I try to read Print ( OrderLots()); I got the initial lot which is 0.01.