[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 369

 

I am testing an EA and my Sleep() function is not working

I want my Expert Advisor to freeze for a long time after the order is closed but it keeps making false openings instead.


bool cl() {if (OrderSelect(0,SELECT_BY_POS)==true){ int t=OrderType();
double l=OrderLots();
int tik=OrderTicket();Alert("tik=", tik);
}
if (t==OP_BUY) OrderClose(tik,l,Bid,3,Red);
if (t==OP_SELL) OrderClose(tik,l,Ask,3,Green);
Sleep(300000000);
}

 

Sleep does not work on the tester.

 

I would like to know if it is possible for an EA to react to an indicator colour change, say green-buy red-sell

and on the appearance of different icons on the screen ... maybe there is a function in MT4 ?

 
unumi >> :

I would like to know if it is possible for the Expert Advisor to react to a change of indicator colour, say green-buy red-sell

And for the appearance of different icons on the screen...maybe there is a function in MT4 ?

If the indicator changes colour, then either a) its line is plotted on different buffers, so it is enough to poll them to understand the state (in MT4 dynamically buffer colour cannot be changed, unlike MT5), or b) the indicator line is plotted by grid objects - then you just need to read the ObjectGet(....).

The same applies to icons - they can be output as code via buffer or as objects.

 
Svinozavr >> :

If the indicator changes colour, then either a) its line is displayed by different buffers and it is enough to poll them to understand the state (in MT4 the buffer colour cannot be changed dynamically, unlike in MT5), or b) the indicator line is displayed by gr.objects - then you just need to read the ObjectGet(....) properties.

The same for icons - they can be drawn as a code using the buffer, or as objects.

>> thank you, I got it.

 

Good night.

Can you advise me, I have two related questions.

1. How to zero the array elements on each tick (if necessary according to the example).

2. How to add up the values of the array elements correctly.

For example:

On each tick the elements of the array are filled, can fill 1 or 2 or 3 or 4.... or 15 elements,

but each time I need the arithmetic sum of the array element values.

 
gvi2504 писал(а) >>

Good night.

Can you advise me, I have two related questions.

1. How to zero the array elements on each tick (if necessary according to the example).

2. How to add up the values of the array elements correctly.

For example:

On each tick the elements of the array are filled, can fill 1 or 2 or 3 or 4.... or 15 elements,

but each time I need the arithmetic sum of the array element values.

1. ArrayInitialize(ArrayName,0) function.

2. In the course of filling the array sum immediately. Declare a variable, for example sum, assign a value of 0 to it, then in the course of filling the array add a value to this variable.

 
Integer >> :

1. ArrayInitialize(ArrayName,0) function.

2. As the array is being filled, sum immediately. Declare a variable, such as sum, assign it a value of 0, then add a value to this variable as the array is being filled.

Great.

Just what you need. >>Thank you very much.

 
Bion писал(а) >>

Sleep(300000000);

Such a long sleep is not an option, even if Sleep() would work in the tester. After it is opened, the time can be memorized:

LastTime=TimeCurrent();

At the beginning of the start() function do check:

if(TimeCurrent()<LastTime+Pause)return(0);

Pause - time of "sleeping" after the opening (in seconds).

 
Integer писал(а) >>

Such a long sleep time is not an option, even if Sleep() would work in the tester. After opening, you can remember the time of opening:

LastTime=TimeCurrent();

At the beginning of the start() function do a check:

if(TimeCurrent()<LastTime+Pause)return(0);

Pause - time of "sleeping" after opening (in seconds).

I did as you advised.

datetime LastTime;
datetime Pause=3600;

int start()
{
if(TimeCurrent()<LastTime+Pause)return(0);

...

bool cl() {if(OrderSelect(0,SELECT_BY_POS)==true){ int t=OrderType();
double l=OrderLots();
int tik=OrderTicket();Alert("tik=", tik);
}
if (t==OP_BUY) OrderClose(tik,l,Bid,3,Red);
if (t==OP_SELL) OrderClose(tik,l,Ask,3,Green);
LastTime=TimeCurrent();
}

However, in the tester, the order opens in accordance with the condition but does not react to the time.

In addition, the tester shows no reaction to the parameter "time the pending order exists", i.e., the order is not deleted when it is time to delete it.

Is it supposed to be like that?

How can we make the tester consider the time passed since the order has been closed?