wait 5 second????

 

please i wanna know the code i should tupe to perform this task

(wait 5 seconds)

because when it's always checking it entered closed loop and metatrader hangs....

thanx alot

 

If the code is in a Script or EA, use Sleep(5000);

If the code is in an Indicator, you can't loop, you can't Sleep(), you have to perform a check next time (meaning next tick).

Use GetTickCount() and compare to a saved value of GetTickCount() to see if at least 5 seconds has passed in an indicator.

If 5 seconds has not passed yet, either exit the indicator code or do whatever else is appropriate.

 
thanx
 

but i want to know why it hangs the meta trader,,

could any tell me or help me to make it a good indicator first then make it an expert

(it works nice with trending periods,,, and nutral in trading ones (sum of winning = sum of loosing )) then equal is winning

double x1=0;
double x2=0;
double price=0;
double w=0;
double x=0;
double y=0;
double z=0;
double c=0;
double b=0;
double n=0;
double m=0;
double l=0;
double p=0;
double q=0;
double j=0;


price=Close[0];
w=High[1];
x=High[2];
y=High[3];
z=High[4];
n=Low[1];
m=Low[2];
l=Low[3];
p=Low[4];
if(w>=x)
c=w ;
else
c=x;
if(y>=z)
b=y ;
else
b=z;
if(c>=b)
x1=c;
else
x1=b;
if(n<=m)
q=n;
else
q=m;
if(l<=p)
j=l;
else
j=p;
if(q<=j)
x2=q;
else
x2=j;
for(;;)
{
for(;;)
{
if(price>=x1)
break;
}
print("www\n");
for(;;)
{
if(price<=x2)
break;
}
print("mmm\n");
continue;
}

 

If you put a loop in your code (without a Sleep() ), the CPU will go to 100% until that loop exits.

You want to examine the status of the prices on "this tick" and perfrmm the necessary operations

if your criteria are met. Then, you repeat that process on the next tick, you don't go into a loop waiting

for price to come to you.

 

i modified it with the following code,,, but it still hangs,,,, help me please:)

//+------------------------------------------------------------------+
//| 3AMMARYAAA.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
double x1;
double x2;
double price;
double w;
double x;
double y;
double z;
double c;
double b;
double n;
double m;
double l;
double p;
double q;
double j;

price= Close[0];

w = High[1];
x = High[2];
y = High[3];
z = High[4];
n = Low[1];
m = Low[2];
l = Low[3];
p = Low[4];
if(w>=x)
c=w ;
else
c=x;
if(y>=z)
b=y ;
else
b=z;
if(c>=b)
x1=c;
else
x1=b;
if(n<=m)
q=n;
else
q=m;
if(l<=p)
j=l;
else
j=p;
if(q<=j)
x2=q;
else
x2=j;
for(;;)
{
int tickCount = GetTickCount();
while(GetTickCount() < tickCount + 1000) {}
for(;;)
{

while(GetTickCount() < tickCount + 1000) {}
if(price>=x1)
break;
}
Print("www\n");
for(;;)
{
while(GetTickCount() < tickCount + 1000) {}
if(price<=x2)
break;
}
Print("mmm\n");
continue;
}
//----
return(0);
}
//+------------------------------------------------------------------+

 

Change your logic.

Your code runs from start() with each tick received.

Examine the current price and decide if further action is necessary.

Get rid of the loops.

 

with each tick received.

THIS IS WHAT I NEED INSTEAD OF LOOPS,,, THANX ALOT FOR YOUR HELPING,,,,,

BUT COULD U PLEASE TELL ME HOW COULD I CHECK IT TICK BY TICK CUZ I AM NEW,, THANX AGAIN

 

It is the natural way that it works.

You write your code, compile it and attach it to a chart.

If a "tick" arrives from the "market", it usually means the dealing price has changed.

That change will go onto your chart.

The system will execute your EA or Indicator code beginning with the start() function.

Then your code goes idle.

The next tick arrives and your start() function is executed again. And so on.

Look at other code examples.

https://www.mql5.com/en/code

 

this is last version,,, many thanx again for your help

..........................................................................

it doesn't hang,, but will it work,, please give me ur review:)

//+------------------------------------------------------------------+
//| 3AMMARYAAA.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
double x1;
double x2;
double price;
double w;
double x;
double y;
double z;
double c;
double b;
double n;
double m;
double l;
double p;
double q;
double j;

price= Close[0];

w = High[1];
x = High[2];
y = High[3];
z = High[4];
n = Low[1];
m = Low[2];
l = Low[3];
p = Low[4];
if(w>=x)
c=w ;
else
c=x;
if(y>=z)
b=y ;
else
b=z;
if(c>=b)
x1=c;
else
x1=b;
if(n<=m)
q=n;
else
q=m;
if(l<=p)
j=l;
else
j=p;
if(q<=j)
x2=q;
else
x2=j;
for(;;)
{
start();
for(;;)
{

start();
if(price>=x1)
break;
}
Print("www\n");
for(;;)
{
start();
if(price<=x2)
break;
}
Print("mmm\n");
continue;
}

//----
return(0);
}
//+------------------------------------------------------------------+

 

There should be only one start() function in your code.

Please read documents and look at other examples.

https://www.mql5.com/en/code

Reason: