Why won't this give me the value of Ask, every 60 seconds?

 

Why won't this give me the value of Ask, every 60 seconds?

double PeriodA;
int time;

int start()
{
PeriodA = (Ask);
int t=1;
while (t<60)
{
Sleep(999);
t++;

if (t==60)
{Alert (PeriodA," ",t);}

if (t==60)
{t=1;}

}

return(0);
}

 
Yellowbeard wrote >>

Why won't this give me the value of Ask, every 60 seconds?

double PeriodA;
int time;

int start()
{
PeriodA = (Ask);
int t=1;
while (t<60)
{
Sleep(999);
t++;

if (t==60)
{Alert (PeriodA," ",t);}

if (t==60)
{t=1;}

}

return(0);
}

try this

{Alert (DoubleToStr(Ask,Digits)," ",t);}

 
ronaldosim wrote >>

try this

{Alert (DoubleToStr(Ask,Digits)," ",t);}

No difference. I just keep getting the same value for Ask, every 60 seconds.

 

Works for me.


Put in a Print("t=",t); statement inside your loop and see what happens.

 
blogzr3 wrote >>

Works for me.

Put in a Print("t=",t); statement inside your loop and see what happens.

Not getting any different result. Print("t=",t); is the count of seconds. My problem isn't being able to see the value of every second; it's being able to capture the value of Ask, at 60 second intervals. Alll I get is the same value for Ask, at each 60 second interval. Even when my chart shows that Ask has changed.

 

You said: "Why won't this give me the value of Ask, every 60 seconds?"


So you actually meant it DOES gives you the Ask but the same value every time. It would help if you actually asked the right question.


The reason is because the variable is assigned once before the loop, and the same variable value is displayed again and again inside the loop. If you want to see the different value each time, just put " PeriodA = (Ask);" inside the loop or just "Alert (Ask," ",t);"

 
I have to take back what I said previously - the real reason is Ask is evaluated on a new tick - inside the loop there is no new tick. This time I'm pretty sure I got it right. I think ;)
 
blogzr3 wrote >>
I have to take back what I said previously - the real reason is Ask is evaluated on a new tick - inside the loop there is no new tick. This time I'm pretty sure I got it right. I think ;)

Tried several different placements of " PeriodA = (Ask);". Inside loop and outside. Made no difference. I think, like you said, it has to do with no tick inside loop. I have to assign Ask, because there is no way to make calculations with past and present values of Ask, if I don't.

 
Yellowbeard:

Tried several different placements of " PeriodA = (Ask);". Inside loop and outside. Made no difference. I think, like you said, it has to do with no tick inside loop. I have to assign Ask, because there is no way to make calculations with past and present values of Ask, if I don't.

You should've listened to blogzr3. He's made a very good point. One tick - one Bid & Ask - one call to start().

Use actual data:

void start()
{
    while (!IsStopped())
    {
        Print(TimeToStr(TimeLocal(), TIME_DATE | TIME_MINUTES | TIME_SECONDS), ": ", Symbol(), " Ask ", MarketInfo(Symbol(), MODE_ASK));
        Sleep(60000);
    }
}

or alternatively update Ask value by calling to RefreshRates():

void start()
{
    while (!IsStopped())
    {
        Print(TimeToStr(TimeLocal(), TIME_DATE | TIME_MINUTES | TIME_SECONDS), ": ", Symbol(), " Ask ", Ask);
        Sleep(60000);
        RefreshRates();
    }
}

 
Irtron wrote >>

You should've listened to blogzr3. He's made a very good point. One tick - one Bid & Ask - one call to start().

Use actual data:

or alternatively update Ask value by calling to RefreshRates():

Sorry for the misunderstanding. Sorry for the hassle. I figured out what I was doing wrong. Thanks!

Here's the correct code.

Had RefreshRates in the wrong place. I had taken it out thinking that it didn't matter that it was there.

double PeriodA;
int time;

int start()

int t=1;
while (t<60)
{

PeriodA = (Ask);
Sleep(999);
t++;

if (t==60)
{RefreshRates();
Alert (PeriodA," ",t);
}

if (t==60)
{t=1;}

}

Reason: