Can't figure why this doesn't work, indeed, it shows :
any help ?
Because symbol is a string, check also your indexation :
printf("Numbers of opened positions : %G", PositionsTotal()); for (int x=0;x<PositionsTotal();x++) { //numbers of position = index printf("Index of the position %G",x); printf("Symbol of the selected position : %s",PositionGetSymbol(x)); printf("Profit on the selected position : %G", PositionGetDouble(POSITION_PROFIT)); }
Because symbol is a string, check also your indexation :
for (int x=0;x<=PositionsTotal()-x;x++)
This works. Once all profit of current positions found, is there a way to compare each to the others to find the one with the bigger loss ?
EDIT : Arrays ?
This works. Once all profit of current positions found, is there a way to compare each to the others to find the one with the bigger loss ?
EDIT : Arrays ?
That doesn't work.
If you have PositionsTotal() positions, they are indexed from 0 to PositionsTotal()-1, so :
for (int x=0;x<PositionsTotal();x++)
If you have PositionsTotal() positions, they are indexed from 0 to PositionsTotal()-1, so :
Indeed. What about using array to compare profits of current opened position ?
Why not.
for (int x=0;x<=PositionsTotal()-1;x++) { //numbers of position = index printf("Index of the position %G",x); printf("Symbol of the selected position : %s",PositionGetSymbol(x)); MaxCurrentLoss[x] = PositionGetDouble(POSITION_PROFIT); <--- ERROR : array out of range printf("Profit on the selected position : %G", MaxCurrentLoss[x]); } }Because i'm trying to figure how. unfortunately .. :/
Because i'm trying to figure how. unfortunately .. :/
Hi blouf, try this quite simple change in your code, without arrays, since you just want to know the bigger loss value:
printf("Numbers of opened positions : %G", PositionsTotal()); double bigger_loss=0; int bigger_loss_index=-1; for (int x=0;x<PositionsTotal();x++) { //numbers of position = index printf("Index of the position %G",x); printf("Symbol of the selected position : %s",PositionGetSymbol(x)); printf("Profit on the selected position : %G", PositionGetDouble(POSITION_PROFIT)); if (PositionGetDouble(POSITION_PROFIT)<bigger_loss) { bigger_loss=PositionGetDouble(POSITION_PROFIT); bigger_loss_index=x; } } if (bigger_loss_index>=0) printf("Bigger loss : %G (Index of the position : %G)",bigger_loss,bigger_loss_index); else printf("No loss, yet! :-)");
Hi blouf, try this quite simple change in your code, without arrays, since you just want to know the bigger loss value:
yep. thank you it works like a charm.
Hi blouf, try this quite simple change in your code, without arrays, since you just want to know the bigger loss value:
Nope sorry it doesn't since in MT5 there's 1 position by symbol, it doesn't compare the loss on each symbol
EDIT : alright, when // debugs' printf forgot that PositionGetSymbol() ALSO select the position
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Can't figure why this doesn't work, indeed, it shows :
any help ?