Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1383

 

How about this?

bool CheckSpr(int _sp)
{
   static int ts=0, res=0;
   static long tc=0;
   if(tc>50 && res*3<_sp) return(false);
   tc++;
   ts += _sp;
   res =ts/tc;
   if(tc>LONG_MAX-1) {
      tc=0;
      ts=0;
   }
   // Comment( res,"=",tc );
   if(tc<50) return(false);
   return(res>_sp?true:false);
}

Again the catch, if you run the code during the rollover and not before it, it will write a 50 tick huge spread and this line makes no sense.

How to fix the code?

 
Vitaly Muzichenko:

How about this?

Again the catch, if you run the code during the rollover and not before it, it will write a 50 tick huge spread and this line makes no sense.

How to fix the code?

The logic is not good. Why exactly average from 50 ticks with a counter to longmax, which can last a long time.

There is a declared spread in the symbol properties. It should be initially entered by an intput. And if it is not entered, it is received. And if we get an increased spread, we mistakenly consider it as average. We need the average value in a rather short range to detect the change.

If there is an intraday spread, we compare it on every tick and get the average value to the necessary one. The question is that we cannot calculate the average without remembering the interim values. I use so, I memorize all values, and when I get the last value plus one, I add it to the sum and subtract the first, and shift numbering (in the array A(n) = A(n+1)). It's cheaper than dialing up the counter to huge values. And up to 10 - 20 values I use variables.

I don't know which is more expensiveSymbolInfoInteger or the difference between Bid and Ask).

 
Valeriy Yastremskiy:

The logic is not good. Why exactly average from 50 ticks with a counter to longmax, which can last a long time.

There is a declared spread in the symbol properties. It should be initially entered by an intput. And if it is not entered, it is received. And if we get an increased spread, we mistakenly consider it as average. We need the average value in a rather short range to detect the change.

If there is an intraday spread, we compare it on every tick and get the average value to the necessary one. The question is that we cannot calculate the average without remembering the interim values. I use so, I memorize all values, and when I get the last value plus one, I add it to the sum and subtract the first, and shift numbering (in the array A(n)=A(n+1)). It's cheaper than dialing up the counter to huge values. And up to 10 - 20 values I use variables.

I don't know, what is more expensiveSymbolInfoInteger or difference between Bid and Ask).

Only the word "Floating", that's the problem.


 
Vitaly Muzichenko:

Just the word 'Floating', that's the challenge.


got a bit excited). Then the logic of believing the first values are correct. Or wait 10 minutes, collect statistics of spread change smoothness during this time, find the average minimum plot of 50 or 100 ticks, and take it as average. Control the start time, so that it does not fall on the time the exchanges are not working. If you want full protection from a fool too)

 
Valeriy Yastremskiy:

(I got a little excited.) Then the logic of believing the first values are correct. Or wait for 10 minutes, collect statistics of spread change smoothness during this time, find the average minimum plot of 50 or 100 ticks, and take it as the average. Control the start time, so that it does not fall on the time the exchanges are not working. If on full protection from a fool too).

This should be avoided somehow.

The algorithm works, if only we don't run the Expert Advisor on rollover, and it will work after weekend.

 
Vitaly Muzichenko:

This should be avoided somehow.

The algorithm works, as long as we don't run the Expert Advisor on a rollover, which will happen all the time after the weekend.

One control, which should be avoided anyway, should be replaced by something. The time between the ticks. Not too expensive. and if the time between ticks is more than 10 seconds, something is wrong.

 
Vitaly Muzichenko:

This should be avoided somehow.

The algorithm works, as long as we don't run the Expert Advisor on a rollover, which will happen all the time after the weekend.

We need to make separate time parameters for rollover: start/end.
And do nothing at that time (except the comment "rollover, wait").

 
Taras Slobodyanik:

You have to make separate time parameters for rollover: start/end.
And do nothing at that time (except the comment "rollover, wait").

There was a parameter "work by time", I changed dealing and started owls - the deal was opened on the rollover.

The dealing time turned out to be -1 gmt, instead of the usual +2gmt.

That's why there was a great desire to get away from time prescription.

 
Vitaly Muzichenko:

There was a "Work by time" parameter, I changed dealing and started owls - the trade was opened on rollover.

The dealing time turned out to be -1 gmt, instead of the usual +2gmt.

That's why I have a great desire to get away from time prescription.

Would replacing the "time value" with the difference between the incoming (new) time and the last calculated time work?

That is, we will know that the new time has arrived:

-from new day

-from a new week

-or with a difference of more than the specified

 
Vitaly Muzichenko:

There was a "Work by time" parameter, I changed dealing and started owls - the trade was opened on rollover.

The dealing time turned out to be -1 gmt, instead of the usual +2gmt.

That's why there was a great desire to get away from time prescription.

Make if the beginning of the week "rollover, waiting" and no matter the time of the server
Reason: