What are range bars? Range bars only consider price, e.g., a 10 pip range bar defines…
- User
What are range bars?
Range bars only consider price, e.g., a 10 pip range bar defines that every bar has a range of 10 pips when measured from high to low. Time is cancelled, meaning a new range bar is only shown if price breaks out of its range, so: Each bar has a high and low that is defined based on the input price level. A new range bar opens outside the high or the low of the previous bar. A range bar closes at the high or at the low. based on above information write a code in amibroker formula for to plot non repaint rangebar without errors. Use plotohlc function to plot rangebars. Provide toggle option for variables used in code. Create complete loop to plot non repaint rangebars. Make sure there is no gap between previous rangebar close and current rangebar open price.don't use words [ array, var, highest, lowest] in entire code. write only code don't explain.
- Assistant
RangeSize = Param("Range Size", 10, 0.0001, 100, 0.1); ro = Null; rh = Null; rl = Null; rc = Null; bar = 0; current_open = O[0]; current_high = H[0]; current_low = L[0]; current_close = C[0]; ro[bar] = current_open; rh[bar] = current_high; rl[bar] = current_low; rc[bar] = current_close; for (i = 1; i < BarCount; i++) { current_high = Max(current_high, H[i]); current_low = Min(current_low, L[i]); range = current_high - current_low; if (range >= RangeSize) { if (C[i] >= current_open) { current_close = current_high; } else { current_close = current_low; } rh[bar] = current_high; rl[bar] = current_low; rc[bar] = current_close; bar = bar + 1; if (bar >= BarCount) break; current_open = current_close; ro[bar] = current_open; current_high = H[i]; current_low = L[i]; rh[bar] = current_high; rl[bar] = current_low; current_close = C[i]; rc[bar] = current_close; } else { rh[bar] = current_high; rl[bar] = current_low; rc[bar] = C[i]; } } SetChartOptions(0, chartShowArrows | chartShowDates); PlotOHLC(ro, rh, rl, rc, "Range Bars", colorBlue, styleCandle);