How find Min SL of position Sell?
- Kid68: But return a value is SL of Last Position.
You set your variable to zero and, thus, will never find a lower stop loss. You don't return the last position SL, you return zero.
double MinSLSell = DBL_MAX;
-
if(PositionSelectByTicket(PositionGetTicket(i)))
You call getTicket. That selects that position. Why are you selecting it again?
I already fix.
Thanks.
Hello,
I want find minium SL of Positions sell. I have code:
But return a value is SL of Last Position.
Help me.
double SLSell(string type, int magicNumber) { double MinSLSell = 0; for(int i= PositionsTotal() - 1; i >= 0 ; i--) { if(PositionSelectByTicket(PositionGetTicket(i))) { string _symbol = PositionGetString(POSITION_SYMBOL); long PositionType = PositionGetInteger(POSITION_TYPE); if(_symbol == _Symbol && PositionGetInteger(POSITION_MAGIC) == magicNumber) { if(PositionType == POSITION_TYPE_SELL && type =="sell" ){ if( MinSLSell>=PositionGetDouble(POSITION_SL)) MinSLSell=PositionGetDouble(POSITION_SL); } } } } return MinSLSell; }