FOR loop (processes all the values with an ascending “TO” or a descending order “DOWNTO”)
Syntax:
1 |
FOR |
Example 1:
1 2 3 4 5 6 7 |
a = 0 FOR i = 10 TO 20 DO a = average[i](open) + a NEXT RETURN a AS "compound averages direction" |
Example 2:
Build a moving average fishnet (guppy) dynamically with 2 loops:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
defparam drawonlastbaronly=true defparam calculateonlastbars=100 //--- settings lookback = 50 //periods to plot firstPeriod = 1 //first moving average Period lastPeriod = 30 //last moving average Period //--- end of settings b = 1 for i = max(1,firstPeriod) to max(1,lastPeriod) do for a = 0 to lookback do drawsegment(barindex[a],average[i][a],barindex[a+1],average[i][a+1]) coloured(0,191,max(1,255-b)) next b = b+5 next return |
It would be very nice to have the option STEP like in basic. That would allow to tailor the increase of the numbers
Use WHILE/WEND with your own step in this case.