Triangle function (derived from Sawtooth)
Here is a generalization of the sawtooth() function, that creates a triangle wave. The optional asymmetry argument, v, makes the triangle segments asymmetrical to the right or left. If v=1, the function is the same as a sawtooth, and if v=0 the function is the oppositely directed sawtooth. If the optional argument is omitted, the default v=0.5, and a symmetrical trangle is created. Values of v outside the range [0,1] are pinned to the nearest limit. See the sawtooth() help file for general usage details.
function tri(x, [v]) variable x, v if (ParamIsDefault(v)) v = 0.5 endif if (v>=1) return sawtooth(x) elseif (v<=0) return 1 - sawtooth(x) else return sawtooth(x) * ((v - sawtooth(x))>=0) / v + sawtooth(-x) * ((1-v) - (sawtooth(-x)) >=0) / (1-v) endif end
Attached is a graph with v=0.8