No. of Lots

 

Hi,

Here I am trying to find out how many 0.1 (SYMBOL_VOLUME_MIN) lots are there in a position. I am using below given code to find it.

Only BUY-Instant orders are used here.

Lot Size is maintained as 0.1 while opening, adding and closing of the position.

Position Volume  is working good.

But Total no of Minimum Lots keeps on varying time to time.

In practical it should match with the Position volume. But sometimes it matches and sometimes it's not.

Please help me with this. My next calculations depend on this.

double arr_open_prices[1000] = {0};
int Maximum_Lots_Allowed = 1000;
int TotalLots = 0;
bool flag = true;
long Position_ID;
int OnInit()
  {
     return(INIT_SUCCEEDED);
  }

void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
{
   if(PositionSelect(_Symbol))
      {
         TotalLots = PositionGetDouble(POSITION_VOLUME)/SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
         Position_ID = PositionGetInteger(POSITION_IDENTIFIER);
         Print("Total no of Minimum Lots = " + TotalLots);
         Print("Position Volume = " + PositionGetDouble(POSITION_VOLUME));
         Print("Symbol Minimum Volume = " + SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN));
            if(HistorySelectByPosition(Position_ID))
               Print("History Total = " + HistoryOrdersTotal());
         Print("______________________________");
     }
}

 Output:

GO      0       16:38.3 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 1
NG      0       16:38.3 test 2014 2 (EURUSD,H1) Position Volume = 0.1
GQ      0       16:38.3 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
GD      0       16:38.3 test 2014 2 (EURUSD,H1) History Total = 1
IM      0       16:38.3 test 2014 2 (EURUSD,H1) ______________________________
IR      0       16:48.7 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 2
DH      0       16:48.7 test 2014 2 (EURUSD,H1) Position Volume = 0.2
HO      0       16:48.7 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
QI      0       16:48.7 test 2014 2 (EURUSD,H1) History Total = 2
JS      0       16:48.7 test 2014 2 (EURUSD,H1) ______________________________
EK      0       16:53.2 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 2
GS      0       16:53.2 test 2014 2 (EURUSD,H1) Position Volume = 0.3
PE      0       16:53.2 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
NP      0       16:53.2 test 2014 2 (EURUSD,H1) History Total = 3
RI      0       16:53.2 test 2014 2 (EURUSD,H1) ______________________________
DM      0       16:58.3 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 4
IE      0       16:58.3 test 2014 2 (EURUSD,H1) Position Volume = 0.4
OS      0       16:58.3 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
LJ      0       16:58.3 test 2014 2 (EURUSD,H1) History Total = 4
QP      0       16:58.3 test 2014 2 (EURUSD,H1) ______________________________
KF      0       17:01.9 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 5
RL      0       17:01.9 test 2014 2 (EURUSD,H1) Position Volume = 0.5
CJ      0       17:01.9 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
CM      0       17:01.9 test 2014 2 (EURUSD,H1) History Total = 5
EF      0       17:01.9 test 2014 2 (EURUSD,H1) ______________________________
JH      0       17:05.3 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 5
FF      0       17:05.3 test 2014 2 (EURUSD,H1) Position Volume = 0.6
FP      0       17:05.3 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
OG      0       17:05.3 test 2014 2 (EURUSD,H1) History Total = 6
DM      0       17:05.3 test 2014 2 (EURUSD,H1) ______________________________
OR      0       17:08.7 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 6
MH      0       17:08.7 test 2014 2 (EURUSD,H1) Position Volume = 0.7
JN      0       17:08.7 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
HI      0       17:08.7 test 2014 2 (EURUSD,H1) History Total = 7
HS      0       17:08.7 test 2014 2 (EURUSD,H1) ______________________________
PK      0       17:12.3 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 8
MS      0       17:12.3 test 2014 2 (EURUSD,H1) Position Volume = 0.8
OE      0       17:12.3 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
HP      0       17:12.3 test 2014 2 (EURUSD,H1) History Total = 8
QI      0       17:12.3 test 2014 2 (EURUSD,H1) ______________________________
JM      0       17:16.4 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 9
CE      0       17:16.4 test 2014 2 (EURUSD,H1) Position Volume = 0.9
FS      0       17:16.4 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
RJ      0       17:16.4 test 2014 2 (EURUSD,H1) History Total = 9
DP      0       17:16.4 test 2014 2 (EURUSD,H1) ______________________________
RD      0       17:20.1 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 10
KM      0       17:20.1 test 2014 2 (EURUSD,H1) Position Volume = 1
DI      0       17:20.1 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
HO      0       17:20.1 test 2014 2 (EURUSD,H1) History Total = 10
PF      0       17:20.1 test 2014 2 (EURUSD,H1) ______________________________
JF      0       17:34.9 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 11
EM      0       17:34.9 test 2014 2 (EURUSD,H1) Position Volume = 1.1
GD      0       17:34.9 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
PQ      0       17:34.9 test 2014 2 (EURUSD,H1) History Total = 11
GH      0       17:34.9 test 2014 2 (EURUSD,H1) ______________________________
LN      0       18:12.1 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 11
FE      0       18:12.1 test 2014 2 (EURUSD,H1) Position Volume = 1.2
MS      0       18:12.1 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
OI      0       18:12.1 test 2014 2 (EURUSD,H1) History Total = 12
QP      0       18:12.1 test 2014 2 (EURUSD,H1) ______________________________
QD      0       18:19.4 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 11
RO      0       18:19.4 test 2014 2 (EURUSD,H1) Position Volume = 1.1
HI      0       18:19.4 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
EO      0       18:19.4 test 2014 2 (EURUSD,H1) History Total = 13
LF      0       18:19.4 test 2014 2 (EURUSD,H1) ______________________________
KO      0       18:19.4 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 11
PJ      0       18:19.4 test 2014 2 (EURUSD,H1) Position Volume = 1.1
NM      0       18:19.4 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
CH      0       18:19.4 test 2014 2 (EURUSD,H1) History Total = 13
NQ      0       18:19.4 test 2014 2 (EURUSD,H1) ______________________________
MJ      0       18:19.4 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 11
FF      0       18:19.4 test 2014 2 (EURUSD,H1) Position Volume = 1.1
LP      0       18:19.4 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
QD      0       18:19.4 test 2014 2 (EURUSD,H1) History Total = 13
PL      0       18:19.4 test 2014 2 (EURUSD,H1) ______________________________
GF      0       18:19.4 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 11
DM      0       18:19.4 test 2014 2 (EURUSD,H1) Position Volume = 1.1
RK      0       18:19.4 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
OQ      0       18:19.4 test 2014 2 (EURUSD,H1) History Total = 13
RG      0       18:19.4 test 2014 2 (EURUSD,H1) ______________________________
CQ      0       18:19.4 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 11
DH      0       18:19.4 test 2014 2 (EURUSD,H1) Position Volume = 1.1
NN      0       18:19.4 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
OJ      0       18:19.4 test 2014 2 (EURUSD,H1) History Total = 13
JS      0       18:19.4 test 2014 2 (EURUSD,H1) ______________________________
GL      0       18:24.1 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 10
RF      0       18:24.1 test 2014 2 (EURUSD,H1) Position Volume = 1
MQ      0       18:24.1 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
LG      0       18:24.1 test 2014 2 (EURUSD,H1) History Total = 13
MM      0       18:24.1 test 2014 2 (EURUSD,H1) ______________________________
NG      0       18:24.1 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 10
GS      0       18:24.1 test 2014 2 (EURUSD,H1) Position Volume = 1
HD      0       18:24.1 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
EP      0       18:24.1 test 2014 2 (EURUSD,H1) History Total = 13
DH      0       18:24.1 test 2014 2 (EURUSD,H1) ______________________________
RR      0       18:24.1 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 10
GH      0       18:24.1 test 2014 2 (EURUSD,H1) Position Volume = 1
DO      0       18:24.1 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
PJ      0       18:24.1 test 2014 2 (EURUSD,H1) History Total = 14
DS      0       18:24.1 test 2014 2 (EURUSD,H1) ______________________________
DL      0       18:24.1 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 10
JE      0       18:24.1 test 2014 2 (EURUSD,H1) Position Volume = 1
QQ      0       18:24.1 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
QG      0       18:24.1 test 2014 2 (EURUSD,H1) History Total = 14
EN      0       18:24.1 test 2014 2 (EURUSD,H1) ______________________________
EG      0       18:24.1 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 10
LS      0       18:24.1 test 2014 2 (EURUSD,H1) Position Volume = 1
OD      0       18:24.1 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
KP      0       18:24.1 test 2014 2 (EURUSD,H1) History Total = 14
OI      0       18:24.1 test 2014 2 (EURUSD,H1) ______________________________
FR      0       18:28.1 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 10
OH      0       18:28.1 test 2014 2 (EURUSD,H1) Position Volume = 1
PO      0       18:28.1 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
PM      0       18:28.1 test 2014 2 (EURUSD,H1) History Total = 14
LD      0       18:28.1 test 2014 2 (EURUSD,H1) ______________________________
DM      0       18:28.1 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 10
ME      0       18:28.1 test 2014 2 (EURUSD,H1) Position Volume = 1
RR      0       18:28.1 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
FF      0       18:28.1 test 2014 2 (EURUSD,H1) History Total = 14
RO      0       18:28.1 test 2014 2 (EURUSD,H1) ______________________________
RH      0       18:28.1 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 10
KR      0       18:28.1 test 2014 2 (EURUSD,H1) Position Volume = 1
DE      0       18:28.1 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
DS      0       18:28.1 test 2014 2 (EURUSD,H1) History Total = 14
PJ      0       18:28.1 test 2014 2 (EURUSD,H1) ______________________________
KP      0       18:29.4 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 9
RN      0       18:29.4 test 2014 2 (EURUSD,H1) Position Volume = 0.9
OH      0       18:29.4 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
PL      0       18:29.4 test 2014 2 (EURUSD,H1) History Total = 15
CE      0       18:29.4 test 2014 2 (EURUSD,H1) ______________________________
CJ      0       18:33.7 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 8
JP      0       18:33.7 test 2014 2 (EURUSD,H1) Position Volume = 0.8
HF      0       18:33.7 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
JR      0       18:33.7 test 2014 2 (EURUSD,H1) History Total = 16
LK      0       18:33.7 test 2014 2 (EURUSD,H1) ______________________________
OS      0       18:37.4 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 6
MK      0       18:37.4 test 2014 2 (EURUSD,H1) Position Volume = 0.7
JM      0       18:37.4 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
GK      0       18:37.4 test 2014 2 (EURUSD,H1) History Total = 17
NR      0       18:37.4 test 2014 2 (EURUSD,H1) ______________________________
PD      0       18:41.2 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 5
LR      0       18:41.2 test 2014 2 (EURUSD,H1) Position Volume = 0.6
HD      0       18:41.2 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
LP      0       18:41.2 test 2014 2 (EURUSD,H1) History Total = 18
LI      0       18:41.2 test 2014 2 (EURUSD,H1) ______________________________
CM      0       18:44.0 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 5
JE      0       18:44.0 test 2014 2 (EURUSD,H1) Position Volume = 0.5
KS      0       18:44.0 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
HI      0       18:44.0 test 2014 2 (EURUSD,H1) History Total = 19
GP      0       18:44.0 test 2014 2 (EURUSD,H1) ______________________________
LF      0       18:47.0 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 4
QL      0       18:47.0 test 2014 2 (EURUSD,H1) Position Volume = 0.4
CJ      0       18:47.0 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
JN      0       18:47.0 test 2014 2 (EURUSD,H1) History Total = 20
OG      0       18:47.0 test 2014 2 (EURUSD,H1) ______________________________
LO      0       18:50.5 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 2
RG      0       18:50.5 test 2014 2 (EURUSD,H1) Position Volume = 0.3
IQ      0       18:50.5 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
CG      0       18:50.5 test 2014 2 (EURUSD,H1) History Total = 21
MN      0       18:50.5 test 2014 2 (EURUSD,H1) ______________________________
KM      0       18:55.8 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 2
RE      0       18:55.8 test 2014 2 (EURUSD,H1) Position Volume = 0.2
JS      0       18:55.8 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
EI      0       18:55.8 test 2014 2 (EURUSD,H1) History Total = 22
NP      0       18:55.8 test 2014 2 (EURUSD,H1) ______________________________
QF      0       18:59.0 test 2014 2 (EURUSD,H1) Total no of Minimum Lots = 1
LL      0       18:59.0 test 2014 2 (EURUSD,H1) Position Volume = 0.1
EJ      0       18:59.0 test 2014 2 (EURUSD,H1) Symbol Minimum Volume = 0.1
IN      0       18:59.0 test 2014 2 (EURUSD,H1) History Total = 23
QG      0       18:59.0 test 2014 2 (EURUSD,H1) ______________________________
                                
 
krishna_gopal_2:

Hi,

Here I am trying to find out how many 0.1 (SYMBOL_VOLUME_MIN) lots are there in a position. I am using below given code to find it.

Only BUY-Instant orders are used here.

Lot Size is maintained as 0.1 while opening, adding and closing of the position.

Position Volume  is working good.

But Total no of Minimum Lots keeps on varying time to time.

In practical it should match with the Position volume. But sometimes it matches and sometimes it's not.

Please help me with this. My next calculations depend on this.

 Output:

Try this :

double arr_open_prices[1000] = {0};
int Maximum_Lots_Allowed = 1000;
double TotalLots = 0;
bool flag = true;
long Position_ID;
int OnInit()
  {
     return(INIT_SUCCEEDED);
  }

void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
{
   if(PositionSelect(_Symbol))
      {
         double volume=PositionGetDouble(POSITION_VOLUME);
         TotalLots = volume/SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
         Position_ID = PositionGetInteger(POSITION_IDENTIFIER);
         Print("Total no of Minimum Lots = " + TotalLots);
         Print("Position Volume = " + volume);
         Print("Symbol Minimum Volume = " + SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN));
            if(HistorySelectByPosition(Position_ID))
               Print("History Total = " + HistoryOrdersTotal());
         Print("______________________________");
     }
}
 
angevoyageur:

Try this :

Thanks friend. Its working.
Reason: