Community of Expertise - page 2

 
For stops, it would be better to introduce a "cooldown" (I don't know what to call it correctly).

If you trace a stop with an accuracy of a pip, the broker will howl and cut off the Expert Advisors :)

I think this is better:
   if (MathAbs(CurrentStopLoss - NewStopLoss) > (Ask - Bid)*Koef) { // Modify stop loss ................ }


I.e. we modify the order if the new stop differs from the old one by a given number of spreads (1 - 2).
Your problem is automatically solved here.

 
Mak, thanks for the advice. Will do.
Only here the problem is different - it tries to set _to_the_ same_value_... I.e. such check will not save from error, but just reduce its probability =)
 
Only here the problem is different - it tries to set _to_the_ same_value_... i.e. such check will not save from error, but just reduce its probability =)

It's most likely a glitch in the EA's text.
I had a similar one, I don't remember how it was fixed.

But the example above ensures that any errors in the script
there will be no attempts to set to the same value.
 
Только тут проблема в другом - оно пытается установить _на_то_же_значение_... т.е. такая проверка не спасёт от ошибки, а просто уменьшит её вероятность =)

It's most likely a glitch in the expert's text. I had a similar one, how it was fixed, I don't remember. But the example above ensures that any errors in the script will not try to set to the same value.





Mak, there is 1 line of text there =
)_TrailingStop( orderticket, 50 );



I wrote the function precisely to avoid such errors, and the check is the same, with the difference that every pip is worked out.
If the value is the same (distance from the price to the stop is equal to 50 in this case) trailing stops should not work.
Moreover, in most cases it does not work =)))), and sometimes it slips through for some reason ....

 
Maybe NormalizeDouble works differently sometimes?
Does it round off or discard?

Generally speaking, it is better never to compare floating types for equality.
The only exception:
double A,B; .......... A = .......; ............. B = A; ........... if (B == A) ........



And about one line ...
In _TrailingStop there are a lot of lines,
and if there are even 2, there is already a reason for errors :)

 
Does
it do what, discard or round it off?
I'm curious too ;)

I've already partially corrected it here: instead
( orderstoploss == 0.0 ........ )


made

if ( orderstoploss <= 0 ......... )

and the rest seemed fine:

.... orderstoploss < ( bid - TrailingStop * point ) 





Renat, I'm generally pinning my hopes on you =) there's probably something as simple as an angle here - and I just don't notice...

 
I'll see if I can help at the weekend.
 
I'll try to take a look at it this weekend and see if I can help.
I've got to get it right...
 
It's probably something as simple as an angle - and I just don't notice...

komposter, you're wrong :) As the spoon-bending girl said, "things are not what they seem".
For example, the following loop prints 5 numbers:
for (double d = 0.1; d <= 0.5; d += 0.1) Print(d);


How much will the next cycle print with the boundaries increased by 1.0?

for (double d = 1.1; d <= 1.5; d += 0.1) Print(d);



You could expect to print 5 numbers too, but it only prints 4 (four). Isn't that great?
If another line is added after the loop:

Print("d=" + d + "(d <= 1.5)=" + (d <= 1.5));


we get:

d=1.50000000 (d <= 1.5)=0



Almost like yours with a stop, but more fundamental :). The problem is as old as the first computer chip:
Computers use binary arithmetic and humans use decimal arithmetic. When rounding, artefacts appear.

"Rounding up", which Mak suggested, helps if you have a fundamental problem with rounding, not a trivial bug.

Many people think that financial calculations MUST USE special decimal arithmetic libraries, but even these can contain errors, sometimes
which can sometimes have serious consequences. By the way, Renat, which implementation of arithmetic do you use?

 
komposter

Had a quick look (haven't done any digging yet), found the point reference that you're calculating.
Try to "discard" it and put Point. Probably that's the problem (point in MarketInfo may not always come out the way you want it?).