PositionsTotal() function doesn't get the number of the opened positions
Please run this code: ListPositions
- votes: 12
- 2017.03.28
- Vladimir Karputov
- www.mql5.com
This is just the final part:
int num_position=PositionsTotal(); if(buy_sign==1 && PositionSelect(Symbol())==0 && num_position==0) { OrderCheck(request,resultCheck); OrderSend(request,result); } // }but num_position is always equal to zero. Even if OrderSend is processed many times
Here is the simplest code. He works. Hedge account.
MetaTrader 5 x64 build 1596 started (MetaQuotes Software Corp.)
//+------------------------------------------------------------------+ //| PositionsTotal.mq5 | //| Copyright 2017, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2017, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { static long count=0; //--- Comment(count,", PositionsTotal()=",IntegerToString(PositionsTotal())); count++; } //+------------------------------------------------------------------+
Look for errors in your code.
Maximally reduce your code - throw out as much as possible - until you find an error.
Hi all,
I'm using the function PositionsTotal() to get the number of open positions, due to I'm using a hedge system.
but at each iteration it returns always 0, even if I opened two positions.
What's wrong?
Thanks
Did you solve this issue? I still have the same problem with version 5.0 build 2690.
The duration of the Sleep() call is trial and error, maybe start at 50 ms ie Sleep(50) and if that fixes things reduce the duration until the problem comes back.
- www.mql5.com
Hi all,
I'm using the function PositionsTotal() to get the number of open positions, due to I'm using a hedge system.
but at each iteration it returns always 0, even if I opened two positions.
What's wrong?
Thanks