Line5=maximum price for [Days] last days;
Line3=medium price for Line1 and Line5,
Line2=medium price for Line1 and Line3,
Line4=medium price for Line3 and Line5.
- Code: Select all
function Init()
indicator:name("BWLIC indicator");
indicator:description("");
indicator:requiredSource(core.Bar);
indicator:type(core.Indicator);
indicator.parameters:addInteger("Days", "Days", "No description", 23);
indicator.parameters:addColor("Color1", "Color 1", "Color 1", core.rgb(0, 255, 0));
indicator.parameters:addColor("Color2", "Color 2", "Color 2", core.rgb(0, 255, 0));
indicator.parameters:addColor("Color3", "Color 3", "Color 3", core.rgb(255, 0, 0));
indicator.parameters:addColor("Color4", "Color 4", "Color 4", core.rgb(0, 0, 255));
indicator.parameters:addColor("Color5", "Color 5", "Color 5", core.rgb(0, 0, 255));
end
local first;
local source = nil;
local buff1;
local buff2;
local buff3;
local buff4;
local buff5;
local Days;
function Prepare()
Days = instance.parameters.Days;
source = instance.source;
first = source:first();
local name = profile:id() .. "(" .. source:name() .. ", " .. Days .. ")";
instance:name(name);
buff1 = instance:addStream("line1", core.Line, name .. ".line1", "line1", instance.parameters.Color1, first);
buff2 = instance:addStream("line2", core.Line, name .. ".line2", "line2", instance.parameters.Color2, first);
buff3 = instance:addStream("line3", core.Line, name .. ".line3", "line3", instance.parameters.Color3, first);
buff4 = instance:addStream("line4", core.Line, name .. ".line4", "line4", instance.parameters.Color4, first);
buff5 = instance:addStream("line5", core.Line, name .. ".line5", "line5", instance.parameters.Color5, first);
end
function Update(period, mode)
if (period>first) then
local d,t,d1,t1;
local TimeDiff;
local PriceMin=source.low[period];
local PriceMax=source.high[period];
d,t=source:date(period);
for i=first,period-1,1 do
d1,t1=source:date(i);
TimeDiff=d-d1;
if TimeDiff<=Days then
PriceMin=math.min(PriceMin,source.low[i]);
PriceMax=math.max(PriceMax,source.high[i]);
end
end
local m=(PriceMin+PriceMax)/2.;
for i=first,period,1 do
buff1[i]=PriceMin;
buff2[i]=(PriceMin+m)/2.;
buff3[i]=m;
buff4[i]=(PriceMax+m)/2.;
buff5[i]=PriceMax;
end
end
end
The indicator was revised and updated