I am trying to create an indicator that acts as a fixed distance trailing stop. The code that I have created is attached bellow. I don't have compilation errors or other error messages during execution but at some moments the indicator is calculated incorrectly. I attach a picture of the error. I spent many hours looking at the code but still I can't understand where is the error that produces that temporary miscalculation.
I should add that the error always appears in the real time display of the indicator and never in the part of the chart that represents historic values registered before the insertion of the indicator.
Also, after the error appears, if I right-click on indicator and select "edit indicator" than it seems that the indicator is automatically recalculated for the whole chart and the error disappears .... only to appear again in the future after a few minutes on another (subsequent) portion of the real time chart.
Thank you!
API Support
Post subject: Re: custom trailing stop indicator error
For unstable period you receive ~100 inputs, but on recalculation - ~4000. So that might be the cause of different values between standard calculation and recalculation.