Calculation in custom indicator give wrong result

 

I created a custom indicator where one of the lines is the result of a subtraction of another line  i.e. L2= L1[i]-L1[i-1]. The indicator works fine most of the time but occasionally gives a large +/- value. This is creating havoc to my EA and it is entering into trades spontaneously. Has anyone experienced this and found a solution. I am trying to shift the indicator to -1 and -2 values but this prevents me from entering at the better moment. Thanks

bartv001 

 
bartv001: L2= L1[i]-L1[i-1]. The indicator works fine most of the time but occasionally gives a large +/- value. 
i-1 is a future value. What do you think you get when i==0
 
WHRoeder:
i-1 is a future value. What do you think you get when i==0

Many thanks WHRoeder- I'm a novice and appreciate your help. I will try i+1 !!

Reason: