// --------------------------------------------------------------------------- // Рассчёт RSI по книге Ч.Лебо и Д.Лукаса, для усреднения используется SMA. // --------------------------------------------------------------------------- #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Red #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_level1 30 #property indicator_level2 70 // Период индикатора. extern int PERIOD = 9; // Буферы индикатора. double buf_rsi[]; // Рабочий период индикатора. int work_period; // Инициализация. int init() { IndicatorShortName(StringConcatenate( "AZZX - SMA RSI v1.0 (", PERIOD, ")")); IndicatorDigits(0); SetIndexBuffer(0, buf_rsi); SetIndexEmptyValue(0, -1); SetIndexLabel(0, "SMA RSI(" + PERIOD + ")"); work_period = Bars - PERIOD; return(0); } // Главный цикл. int start() { int i; for(i = Bars - IndicatorCounted() - 1; i >= 0; i--) { if(i < work_period) { double up = 0, dn = 0; int j; for(j = i + PERIOD - 1; j >= i; j--) { double v = Close[j] - Open[j]; if(v > 0) { up += v; } else { dn -= v; } } buf_rsi[i] = up / (up + dn) * 100; } else { buf_rsi[i] = -1; } } return(0); }