To select a position that is young in time, use:
bool SelectLastPosition()
by the way, look at pliz, what can be improved in it.
{
datetime time_last = 0;
for (int i=PositionsTotal()-1; i>=0; i--)
if (iposition.SelectByIndex(i))
if (iposition.Symbol() == isymbol.Name() && iposition.Magic() == Magic)
if(iposition.Time()>time_last)
{
time_last = iposition.Time();
}
for (int i=PositionsTotal()-1; i>=0; i--)
if (iposition.SelectByIndex(i))
if (iposition.Symbol() == isymbol.Name() && iposition.Magic() == Magic)
if(iposition.Time()==time_last)
{
return(true);
}
return(false);
}
i tried to use the same f-y to select the oldest position, just changing the condition to:
if(iposition.Time() but since initially we set the time to zero datetime time_last = 0, then you will not find anything less than this time, i tried to assign the value 999999999999999, but it does not work, which value is better to assign?
choosing a young or old position
Share
sysmart
yeah, no answer, nothing)
In short, to capture the old position, it turned out like this:
bool SelectFirstPosition()
{
datetime time_first = 32535244799;
for (int i=PositionsTotal()-1; i>=0; i--)
if (iposition.SelectByIndex(i))
if (iposition.Symbol() == isymbol.Name() && iposition.Magic() == Magic)
if(iposition.Time()for (int i=PositionsTotal()-1; i>=0; i--)
if (iposition.SelectByIndex(i))
if (iposition.Symbol() == isymbol.Name() && iposition.Magic() == Magic)
if(iposition.Time()==time_first)
{
return(true);
}
return(false);
}
that is, i set datetime time_first = 32535244799 – this is the maximum number that corresponds to december 31, 3000-year, time 23: 59:59