A little help with a closing position time function, please
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.
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)
- 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.
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.