I am trying to convert code to Amibroker for the RTI (Relative Trend Index) indicator. I can get the easy parts, but have always found the 'for' function hard to get to grips with.

Could someone give me information where to get information how to convert, or help explain how to convert this.

The following has the URL from where the code comes from.

I have converted the Parameter section, now to get the 'Relative Trend Index Calculation' section done.

// // Relative Trend Index (RTI) by Zeiierman — Indicator by Zeiierman — TradingView

// Inputs {

trend_data_count = Param( "Trend Length", 100, 10, 500, 4 );

trend_sensitivity_percentage = Param( "Sensitivity", 95, 50, 98, 1 );

signal_length = Param( "Signal Length", 20, 1, 200, 1 );//MA Period

ob = Param( "", 80, 0, 100, 1 ); //Overbought Line

os = Param( "", 20, 1, 100, 1 ); //Oversold Line

//trend_data_count = input.int(100, step=4, minval=10, title="Trend Length", inline = "RT", group="Relative Trend Index [RTI]", tooltip="")

//trend_sensitivity_percentage = input.int(95, step=1,minval=50, maxval=98,title='Sensitivity ', inline = "RT1", group="Relative Trend Index [RTI]", tooltip="")

//signal_length = input.int(20, step=1,minval=1, maxval=200,title='Signal Length', inline = "", group="Signal Line", tooltip="Set the Ma period.")

//ob = input.float(80, step=1, minval=0, maxval=100, title="", inline = "obos", group="Overbought/Oversold", tooltip="")

//os = input.float(20,step=1, minval=0, maxval=100,title="", inline = "obos", group="Overbought/Oversold", tooltip="Set the OB/OS levels.")

//~~~~~~~~~~~~~~~~~~~~~~~}

// Relative Trend Index Calculation {

upper_trend = close + StDev(close, 2);

lower_trend = close - StDev(close, 2);

upper_array = array.new(0);

lower_array = array.new(0);

for i = 0 to trend_data_count - 1

upper_array.push(upper_trend[i])

lower_array.push(lower_trend[i])

upper_array.sort()

lower_array.sort()

upper_index = math.round( trend_sensitivity_percentage / 100 * trend_data_count) - 1

lower_index = math.round((100 - trend_sensitivity_percentage) / 100 * trend_data_count) - 1

UpperTrend = upper_array.get(upper_index)

LowerTrend = lower_array.get(lower_index)

RelativeTrendIndex = ((close - LowerTrend) / (UpperTrend - LowerTrend))*100

//~~~~~~~~~~~~~~~~~~~~~~~}

Thank you in advance for any help offered.