Download the indicator:
- Code: Select all
-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
function Init()
indicator:name("Belkayate timing indicator");
indicator:description("");
indicator:requiredSource(core.Bar);
indicator:type(core.Oscillator);
indicator.parameters:addInteger("N", "Number of bars", "No description", 5);
end
-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- Parameters block
local N;
local first;
local source = nil;
-- Streams block
local O = nil;
local H = nil;
local L = nil;
local C = nil;
-- Routine
function Prepare()
N = instance.parameters.N;
source = instance.source;
first = source:first() + N;
local name = profile:id() .. "(" .. source:name() .. ", " .. N .. ")";
instance:name(name);
O = instance:addStream("O", core.Line, name .. ".O", "O", 0, first);
H = instance:addStream("H", core.Line, name .. ".H", "H", 0, first);
L = instance:addStream("L", core.Line, name .. ".L", "L", 0, first);
C = instance:addStream("C", core.Line, name .. ".C", "C", 0, first);
O:addLevel(8);
O:addLevel(6);
O:addLevel(0);
O:addLevel(-6);
O:addLevel(-8);
instance:createCandleGroup("BT", "BT", O, H, L, C);
end
-- Indicator calculation routine
function Update(period)
if period >= first then
local range, sumhigh, sumlow, avg1, avg2;
range = core.rangeTo(period, N);
sumhigh = core.sum(source.high, range);
sumlow = core.sum(source.low, range);
avg1 = (sumhigh + sumlow) / (2 * N);
avg2 = (sumhigh - sumlow) / (5 * N);
O[period] = (source.open[period] - avg1) / avg2;
H[period] = (source.high[period] - avg1) / avg2;
L[period] = (source.low[period] - avg1) / avg2;
C[period] = (source.close[period] - avg1) / avg2;
end
end