How should I use PositionsTotal() to return the number of operations at the symbol (chart) applied and not the total? (MQL5 code)
For several reasons I need you to be as well. I don't want the total, as I do not wish to take into account manual trades in other symbols.
Thank you in advance.
int b=0,s=0,n=0;
for(int i=total-1; i>=0; i--)
I think PositionSelect("the symbol you need") will help you...
Does not work, because what true/false is returned, not the number of open positions in that time and symbol.
Thanks anyway. ;)
Why people who are selling products on the Market want to get free help on the forum ?
You have never had a doubt? That lucky...
By the way...issue resolved.
for(int i=PositionsTotal()-1; i>=0; i--)
{
string CounterSymbol=PositionGetSymbol(i);
if(Symbol()==CounterSymbol && m_position.Magic()==MagicNumber)
{
PosCounter+=1;
You have never had a doubt? That lucky...
By the way...issue resolved.
for(int i=PositionsTotal()-1; i>=0; i--)
{
string CounterSymbol=PositionGetSymbol(i);
if(Symbol()==CounterSymbol && m_position.Magic()==MagicNumber)
{
PosCounter+=1;
You have never had a doubt? That lucky...
By the way...issue resolved.
for(int i=PositionsTotal()-1; i>=0; i--)
{
string CounterSymbol=PositionGetSymbol(i);
if(Symbol()==CounterSymbol && m_position.Magic()==MagicNumber)
{
PosCounter+=1;
Quite easy Miguel, I use TotalPos++.
int LongPos=0,ShortPos=0,TotalPos=0; for(int i=0;i<PositionsTotal();i++){ ulong iTicket=PositionGetTicket(i); if(PositionGetString(POSITION_SYMBOL)==_Symbol &&PositionGetInteger(POSITION_MAGIC)==MagicNumber){ if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){LongPos++;} if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL){ShortPos++;} TotalPos++; } }
Interesting twist - me thinks.
I have been trying to track down why my 'deletes' don't seem to be working properly. Then using loads of test statements I think I have an answer.
int Positions_Total = PositionsTotal(); if ( Direction_of_Trade == "DN" ) { for ( int i = 0; i< Positions_Total; i++)
I now think the above gets over the problem ... because....
Positions_Total is now fixed at the value of PositionsTotal().
If I delete records in the loop PositionsTotal() reduces and I does not reach the 'end value' and consequently does not delete all expected records.
Hope - a) this is correct & b) helps someone
Interesting twist - me thinks.
I have been trying to track down why my 'deletes' don't seem to be working properly. Then using loads of test statements I think I have an answer.
I now think the above gets over the problem ... because....
Positions_Total is now fixed at the value of PositionsTotal().
If I delete records in the loop PositionsTotal() reduces and I does not reach the 'end value' and consequently does not delete all expected records.
Hope - a) this is correct & b) helps someone
Thats not correct....
Here is why: (Has been explained multiple times)
When you have a list and you delete the record, you are looking at right now, then the next record will take the place in the list which you are looking at.
Since you are done with this line in your list, you will go to the next line, but the record from that line had been moved to the one you are now coming from... so you will miss that entry.
Clear?
EDIT:
The solution is to start at the end of the list, so your "for()-loop" must count backwards...
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How should I use PositionsTotal() to return the number of operations at the symbol (chart) applied and not the total? (MQL5 code)
For several reasons I need you to be as well. I don't want the total, as I do not wish to take into account manual trades in other symbols.
Thank you in advance.
int b=0,s=0,n=0;
for(int i=total-1; i>=0; i--)