first of all, thanks to anyone reading this that replied to my previous topic.
This time I'm struggling with time management: I need to check (every 60 seconds) if the trade has reached TP or SL.
For this I'm using the TimeLocal();function: each tick I store the new value in a variable (carrenttl); then (inside the while op) saving the TimeLocal in a different variable (taimlocal). And I'm trying to run the loop as long as the difference between the second variable and the first one is smaller than 60 (as datetime variables like the two mentioned above are equivalent to the second elapsed from 1/01/1970).
It compiles without errors but when I look at the log it does everything in about 7 seconds, as opposed to the 60 that I'm expecting.
Would you have any suggestion on why this is not working or if there's a way that this can be done more efficiently?
Thank you for your time
E.
//+------------------------------------------------------------------+//| cheduecoglioni.mq5 |//| Gianni Esperti |//| https://www.gianniesperti.come? |//+------------------------------------------------------------------+#property copyright"Gianni Esperti"#property link"https://www.gianniesperti.come?"#property version"1.00"//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+#include <Trade\Trade.mqh>
CTrade trade;
uint s;
int r;
datetime taimlocal;
datetime carrenttl;
intOnInit()
{
MathSrand( GetTickCount() );
s = GetTickCount();
r = MathRand();
doubleAsk = NormalizeDouble ( SymbolInfoDouble (_Symbol, SYMBOL_ASK), _Digits );
if (r <= 16383)
{
Print(r, " bitches in my Lex");
trade.Buy (0.01, NULL, Ask, 0, ( Ask + 100 * _Point ), NULL);
taimlocal = TimeLocal();
}
else
{
Print(r, " of my beats in yo stereo");
trade.Sell (0.01, NULL, Ask, 0, ( Ask - 100 * _Point ), NULL);
taimlocal = TimeLocal();
}
return (INIT_SUCCEEDED);
}
voidOnTick()
{
carrenttl = TimeLocal ();
do
{
Print ("Still not 60 sec?");
}
while ( (carrenttl - taimlocal) < 60 );
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi all,
first of all, thanks to anyone reading this that replied to my previous topic.
This time I'm struggling with time management: I need to check (every 60 seconds) if the trade has reached TP or SL.
For this I'm using the TimeLocal(); function: each tick I store the new value in a variable (carrenttl); then (inside the while op) saving the TimeLocal in a different variable (taimlocal). And I'm trying to run the loop as long as the difference between the second variable and the first one is smaller than 60 (as datetime variables like the two mentioned above are equivalent to the second elapsed from 1/01/1970).
It compiles without errors but when I look at the log it does everything in about 7 seconds, as opposed to the 60 that I'm expecting.
Would you have any suggestion on why this is not working or if there's a way that this can be done more efficiently?
Thank you for your time
E.