if(TimeCurrent() >= PositionGetInteger(POSITION_TIME) - 300) if(UltimaPosAberta <= TimeCurrent() + 300)
Current time will always be greater than position time. Your condition is always true.
Don't you want current time greater than position time by 5 minutes? THINK.
William Roeder:
Current time will always be greater than position time. Your condition is always true.
Don't you want current time greater than position time by 5 minutes? THINK.
You're right.
I kept reading stuff, changed a little, but still it's not getting "TRUE" for my if
long update_time_msc=PositionGetInteger(POSITION_TIME_UPDATE_MSC); if(TimeToString(update_time_msc/1000+300) <= TimeToString(TimeCurrent())) { Print("Limite de Tempo da Operação"); FecharPosicao(); }
- Why are you converting time to string for comparison? Just compare.
- Your original want was 5 minutes after position time. Just do that.
if(TimeCurrent() - PositionGetInteger(POSITION_TIME) >= 300) if(TimeCurrent() - UltimaPosAberta >= 300)
William Roeder:
- Why are you converting time to string for comparison? Just compare.
- Your original want was 5 minutes after position time. Just do that.
I tried it.
long UltimaPosAberta = PositionGetInteger(POSITION_TIME); if(TimeCurrent() - UltimaPosAberta >= 300) { Print("Limite de Tempo da Operação"); FecharPosicao(); }
See that it only closes the position at 17:30 (only because there is another 'if' for that).
if(TimeToString(TimeCurrent(),TIME_MINUTES) == "17:30" && PositionSelect(_Symbol)==true) { Print("-----> Fim do Tempo Operacional: encerrar posições abertas!"); FecharPosicao();}
I don't know why it was not working, but... somehow it did:
if((datetime)PositionGetInteger(POSITION_TIME) <= TimeCurrent()-300) { FecharPosicao(); }
Thanks for all the assistence, buddy.

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, all.
I'm having an issue tiwh this part of my code:
OR
I want all positions to close after 5 minutes, be that with profit or not.
What am I missing?
Thank you!
**Note:
The "FechaPosicao()" function is working fine to close it all.