Please run this code: ListPositions
ListPositions
- votes: 12
- 2017.03.28
- Vladimir Karputov
- www.mql5.com
Список всех позиций. Пример работы с CPositionInfo.
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.
Files:
PositionsTotal.mq5
2 kb
managertop40:
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.
If you are calling PositionsTotal() right after opening a position, try Inserting a Sleep() statement just before calling PositionsTotal() and see if that fixes the problem.
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.
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.
Documentation on MQL5: Trade Functions / PositionsTotal
- www.mql5.com
PositionsTotal - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
It's working fine !!! Thanks very much for this
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
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