Problem using a certain indicator in an expert advisor

 

Hello,

I need help with a problem that I'm experiencing. I made an indicator based on many indicators, to filter out bad trades. At the bottom you can see the indicator, it is a bar chart, red for short, blue for long and yellow for stay out,

Now the problem, I cannot get to simulate the indicator right in an expert advisor. Below is a test I did with the strategy tester, vertical lines of same color are drawn at each bar, the color of the vertical line is extracted from the indicator, to test if the values are what they should be.

As you can see, about 1/20 of the colors are wrong. This is problematic because the wrong signals are used to calculate if a trade should be made or not.

Any idea why something like this happens and how can I fix it? Is this a strategy tester problem?

Thanks