Sidechair

by

Browse the reference

Sets the step of a for loop: for i = 0 to 100 by 25 counts 0, 25, 50, 75, 100.

Try it in the editor

by follows the end value of a for loop and gives the amount the counter changes after each pass. Without it the step is 1. The step must not be zero.

Write the step as a positive number. The direction comes from the start and end values, so for i = 100 to 0 by 25 counts down and by -25 is not needed.

Remarks

  • A step larger than the distance between start and end means the loop runs once, for the start value.
  • On Sidechair: the sign of the step is ignored and the step 0 counts as 1.

Example

Pine ScriptSample every fifth barOpen in editor
//@version=6
indicator("Loop step", overlay = true)
sum = 0.0
count = 0
for i = 0 to 24 by 5
    sum += nz(close[i])
    count += 1
plot(sum / count, "Every fifth close", color.purple, 2)
plot(close, "Close", color.gray)

See also

Runs on Sidechair