Topic: Is it bug with Williams %R when running EA in MT4?

Hello guys,
I really appreciate the great work that Popov and everyone here does to make Forex Strategy builder better everyday.
I have been watching this forum for some time but recently started trying out the strategies creation myself from the software. Yesterday I created a strategy that showed a great potential and mainly utilises Williams %R indicator. I have attached the MQL herewith for you to have a look and confirm if this is a bug.
The MQL4 for expert adviser gets compiled without issues in MT4 but when this expert is ran for back testing Zero divide error is shown and it does not run.
I tried attaching this EA to live chart and although it runs and shows smiley after some time it reports the same error.

I also tried using alternative indicator in FSB called  Amplified Williams %R but get the same error. I don't get this kind of error when using any other indicators so I guess I am not making any fundamental mistakes.

Can you have a look please?
Thanks
RK

Post's attachments

RK WPR 20 02 18.mq4 260.56 kb, 8 downloads since 2018-02-21 

You don't have the permssions to download the attachments of this post.

Re: Is it bug with Williams %R when running EA in MT4?

Any thoughts? Any ideas to overcome this issue?

Re: Is it bug with Williams %R when running EA in MT4?

Hello,

On line 2584 you might try changing the code from:

adR[bar]=-100*(max-Data.Close[bar])/(max-min);

to

adR[bar] = 0;
if ((max-min) > 0)
    adR[bar]=-100*(max-Data.Close[bar])/(max-min);

I couldn't really test it because the strategy you uploaded isn't realistic and never trades.  I'm not sure what a good default value for adR[bar] would be in the case where (max-min) is zero.

Re: Is it bug with Williams %R when running EA in MT4?

Sleytus you are an absolute genius and an extremely good-hearted person which is a fantastic combination to have. Thanks a lot. Your code change worked in first go and it allowed EA to progress in MT4 strategy tester. The EA does open positions fine but will need some tweaking as although it showed profit in FSB,  in MT4 the graph went down. I will work on it further. If it proves any profitable I will share it in this thread.
Your solution will also help anyone who tries to use the WPR indicator and generates a MT4 EA.
Thanks again.
RK

Re: Is it bug with Williams %R when running EA in MT4?

Thanks for the good word -- though genius would probably be stretching it a bit.  I'm glad to hear the fix worked.

Re: Is it bug with Williams %R when running EA in MT4?

I'm fixing this error in both FSB Pro and the exported code.

The William's Percent Range value will be set to -50 when min = max for the particular range.