You need a variable to store the old value, and another variable to remember when you stored it. You could use a structure if you prefer.
The variables need to be either static or globally-scoped.
Simple example:
static double OldValue = Ask;
static datetime OldTime = TimeCurrent();
if(TimeCurrent() >= OldTime + 300) // 300 seconds == 5 minutes
{
if(Ask > OldValue) Print("Current Ask price is greater than Ask price 5 minutes ago");
else Print("Current Ask price is less than or equal to Ask price 5 minutes ago");
OldValue = Ask;
OldTime = TimeCurrent();
}
static datetime OldTime = TimeCurrent();
if(TimeCurrent() >= OldTime + 300) // 300 seconds == 5 minutes
{
if(Ask > OldValue) Print("Current Ask price is greater than Ask price 5 minutes ago");
else Print("Current Ask price is less than or equal to Ask price 5 minutes ago");
OldValue = Ask;
OldTime = TimeCurrent();
}
honest_knave:
Thank you
You need a variable to store the old value, and another variable to remember when you stored it. You could use a structure if you prefer.
The variables need to be either static or globally-scoped.
Simple example:
static double OldValue = Ask;
static datetime OldTime = TimeCurrent();
if(TimeCurrent() >= OldTime + 300) // 300 seconds == 5 minutes
{
if(Ask > OldValue) Print("Current Ask price is greater than Ask price 5 minutes ago");
else Print("Current Ask price is less than or equal to Ask price 5 minutes ago");
OldValue = Ask;
OldTime = TimeCurrent();
}
static datetime OldTime = TimeCurrent();
if(TimeCurrent() >= OldTime + 300) // 300 seconds == 5 minutes
{
if(Ask > OldValue) Print("Current Ask price is greater than Ask price 5 minutes ago");
else Print("Current Ask price is less than or equal to Ask price 5 minutes ago");
OldValue = Ask;
OldTime = TimeCurrent();
}
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
Hi All,
I did some research but could not find what I need. Hence, I hope anyone can help me.
I am trying to store value A for X minutes until the value change and compare the current A value. So I am comparing a X min ago A value and the current value.
I am not looking for the current and previous bar value.
Any help is appreciated.