checking the number of Lot's

 

Hi,


I would like to know how can I check the number of Lot's of each "security" that I have at the moment on may account. I was trying MarketInfo, but it not returns any direct information.


Any idea?


Thanks

Rodrigosm

 

you should use

OrderSelect() & OrderLots()

 

Thanks giol,

Like this?


Magic=1234;

if(OrderSelect(Magic, SELECT_BY_TICKET)==true)
    Print("lots",OrderLots());  
       else
          Print("OrderSelect returned error of ",GetLastError());
 

if 1234 is your ticket no., yes

 
qjol:

if 1234 is your ticket no., yes


It did not work, It´s showing: ERROR 0. It only works when I change the magic number for the ticket number.

I need to know the number of lots of all positions opened by the same expert.


Thanks again


Rodrigosm

 

I found my mistake. The looping was missing.


                        for(int i=1; i<=OrdersTotal(); i++) 
                        {      
                           if (OrderSelect(i-1,SELECT_BY_POS)==true)
                           Lot = Lot + OrderLots();
                        }
 

i told u that is working only if 1234 is your ticket no.

 

this code:

                        for(int i=1; i<=OrdersTotal(); i++) 
                        {      
                           if (OrderSelect(i-1,SELECT_BY_POS)==true)
                           Lot = Lot + OrderLots();
                        }
is going to give u the some Lots for all your open position
 
qjol:

this code:

is going to give u the some Lots for all your open position

It is better to add for "buys" and substract for "sells".

if ( OrderType() == OP_BUY ) { Lot += OrderLots(); }

if ( OrderType() == OP_SELL ) { Lot -= OrderLots(); }

Then it will give you the correct idea.

 

I do not understand what you're want to get, you need to know the sum of all the lots, or all buy's or all sales, explain.

 

I already got what I needed. It was the total number of lots generated by one expert for one currency. I need this to close all my positions when the market's scenario changes.


for(int i=1; i<=OrdersTotal(); i++) 
                        {      
                           if (OrderSelect(i-1,SELECT_BY_POS)==true)
                           Lot = Lot + OrderLots();
                        }
Reason: