- 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.
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
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; }