Download MetaTrader 5

how to get total used lot size

To add comments, please log in or register
Vytautas
170
Vytautas  

Hello, i wrote my EA. now to finish it i need just to count how many lots is used total from active orders. So maybe you have ideas what function should i use to get the total lots used at the moment from active orders.

for exmp.

order nr:

1.0.01

2.0.02

3.0.03

4.0.05

so i need a sum of all theese, i need to get 0.11)

exmpl;


double usedlots = ???(help) ;

if(usedlots == 0.11)

then = dothat;

else

nothing;



Thank you, i hope you understand :)

Simon Gniadkowski
Moderator
18025
Simon Gniadkowski  
Loop through the open orders, OrderSelect() one by one, check Symbol() and Magic Number if applicable, keep a running total of OrderLots() for the orders that match Symbol & Magic Number. Done.
Vytautas
170
Vytautas  
If there are no way to "select all" function at orderselect() becouse, every time is unique and the number of order will not be the same, my ea working with the 10-30 orders in a day, so i have to count the lot size every new bar. If i should use orders numbers i would need to edit my ea everytime :/
Simon Gniadkowski
Moderator
18025
Simon Gniadkowski  
Vyckaa:
If there are no way to "select all" function at orderselect() becouse, every time is unique and the number of order will not be the same, my ea working with the 10-30 orders in a day, so i have to count the lot size every new bar. If i should use orders numbers i would need to edit my ea everytime :/

Maybe you can get someone to code it for you . . . I won't.

I'll try to help once more . . .

<pseudo code start>

Loop through the open orders by position. Read here and here

If an order matched the Symbol you want and the Magic Number you want

add iit's OrderLots() to a running total

When the loop is complete your running total is the total number of lots in all your open Orders.

<pseudo code end>

whroeder1
15917
whroeder1  
double totalOpenLots = 0;
    for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS)                    // Only my orders w/
    &&  OrderMagicNumber()  == Magic.Number                 // my magic number
    &&  OrderSymbol()       == chart.symbol                 // and my pair.
    ){  totalOpenLots += OrderLots(); }
Vytautas
170
Vytautas  
Thank you guys both. That was very usefull info :) WHRoeder i will try to integrate your code into my ea and see what happens
Vytautas
170
Vytautas  
WHRoeder it worked ! thank you . The problem is that i not very expieried at mq4 yet, i dont know how to use "for" so thats might be the problem i didnt figure it out how to code, but with your help i am starting to understand.
To add comments, please log in or register