Moderator: admin
function Init()
indicator:name("BetterRenko");
indicator:description("BetterRenko");
indicator:requiredSource(core.Bar);
indicator:type(core.Indicator);
indicator:setTag("replaceSource", "t");
indicator.parameters:addGroup("Calculation");
indicator.parameters:addInteger("Step", "Step in pips", "", 10);
end
local first;
local source = nil;
local Step;
local up = nil;
local down = nil;
local n;
local i;
local open = nil;
local high = nil;
local low = nil;
local close = nil;
function Prepare()
source = instance.source.close;
Step=instance.parameters.Step;
first = source:first();
up = instance:addInternalStream(first, 0);
down = instance:addInternalStream(first, 0);
local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.Step .. ")";
instance:name(name);
open = instance:addStream("open", core.Line, name, "open", core.rgb(0, 0, 0), first)
high = instance:addStream("high", core.Line, name, "high", core.rgb(0, 0, 0), first)
low = instance:addStream("low", core.Line, name, "low", core.rgb(0, 0, 0), first)
close = instance:addStream("close", core.Line, name, "close", core.rgb(0, 0, 0), first)
instance:createCandleGroup("Renko", "Renko", open, high, low, close);
end
function Update(period, mode)
if (period==source:size()-1) then
n=1;
up[n] = source[first];
down[n] = source[first];
for i=first+1,period,1 do
local not_done;
if n == first then
up[n] = source[i];
down[n] = source[i];
n = n + 1;
else
if source[i] > up[n-1] + Step*source:pipSize() then
up[n] = up[n-1] + Step*source:pipSize();
down[n] = up[n-1] - Step*source:pipSize();
n = n + 1;
if source[i] > up[n-1] + Step*source:pipSize() then
not_done = 1;
else
not_done = 0;
end
while(not_done == 1) do
up[n] = up[n-1] + Step*source:pipSize();
down[n] = up[n-1] - Step*source:pipSize();
n = n + 1;
if source[i] > up[n-1] + Step*source:pipSize() then
not_done = 1;
else
not_done = 0;
end
end
elseif source[i] < down[n-1] - Step*source:pipSize() then
down[n] = down[n-1] - Step*source:pipSize();
up[n] = down[n-1] + Step*source:pipSize();
n = n + 1;
if source[i] < down[n-1] - Step*source:pipSize() then
not_done = 1;
else
not_done = 0;
end
while(not_done == 1) do
down[n] = down[n-1] - Step*source:pipSize();
up[n] = down[n-1] + Step*source:pipSize();
n = n + 1;
if source[i] < down[n-1] - Step*source:pipSize() then
not_done = 1;
else
not_done = 0;
end
end
else
down[n] = down[n-1];
up[n] = up[n-1]
n = n + 1;
end
end
end
for i=1,open:size()-1,1 do
local m=1;
if i < 2 then
open[m]=nil;
close[m]=nil;
low[m]=nil;
high[m]=nil;
else
if up[i] > up[i-1] then
open[m]=down[i];
close[m]=up[i];
low[m]=down[i];
high[m]=up[i];
m = m + 1;
end
if up[i] > up[i-1] then
open[m]=up[i];
close[m]=down[i];
low[m]=down[i];
high[m]=up[i];
m = m + 1;
end
end
end
end
end
whninja wrote:can someone help
i had some trouble with the streams and array calc
while(not_done == 1) do
up[n] = up[n-1] + Step*source:pipSize();
down[n] = up[n-1] - Step*source:pipSize();
n = n + 1;
if source[i] > up[n-1] + Step*source:pipSize() then
not_done = 1;
else
not_done = 0;
end
end
whninja wrote:thanks my problem is
n can be greater period (with a small bricksize) or n can be smaller period (with a higher bricksize)
n is the count for the bricks - in this case a higher range of a bar can have more bricks (trend)
i is a count for period/bar - in this case more bars can have only a brick (sideways)
tomorow i will swith i with (current ) period
local up = {};
local down = {};
function Prepare()
...
end
local up = nil;
local down = nil;
function Prepare()
...
up = instance:addInternalStream(first, 0);
down = instance:addInternalStream(first, 0)
...
end
function Update(period, mode)
if mode == core.UpdateAll then
-- clear arrays
up = {};
...
end
end
Users browsing this forum: No registered users and 76 guests