by clodhoppes » Mon Jan 09, 2012 5:13 pm
Thank you for your attention. The code is listed as follows:
function Init()
indicator:name("HHH");
indicator:description("HHH");
indicator:requiredSource(core.Bar);
indicator:type(core.Indicator);
indicator.parameters:addInteger("Ni", "Ni", "right limit",1,1,200000);
indicator.parameters:addInteger("limit", "limit", "left limit",20,2,2000);
indicator.parameters:addInteger("fgi", "fgi", "reveral number",6,1,8);
indicator.parameters:addInteger("NR", "NR", "left or right range",1,1,100);
indicator.parameters:addGroup("Style");
indicator.parameters:addColor("R_color", "Color of Red", "", core.rgb(255, 0, 0));
indicator.parameters:addColor("B_color", "Color of Blue", "", core.rgb(0, 0, 255));
indicator.parameters:addColor("G_color", "Color of Green", "", core.rgb(0, 128, 0));
indicator.parameters:addColor("D_color", "Color of black", "", core.rgb(0, 0, 0));
indicator.parameters:addColor("M_color", "Color of magenta", "", core.rgb(255, 0, 255));
indicator.parameters:addColor("C_color", "Color of cyan", "", core.rgb(128, 255, 255));
indicator.parameters:addColor("Y_color", "Color of yellow", "", core.rgb(255, 255, 0));
indicator.parameters:addColor("S_color", "Color of gray", "", core.rgb(128, 128, 128));
end
-- Parameters block
local Ni,limit,fgi,NR;
local pL;
local source = nil;
-- Streams block
local fr={};
local i;
local f={};local g={};
local Cen;
-- Routine
function Prepare()
Ni = instance.parameters.Ni;
limit = instance.parameters.limit;
fgi = instance.parameters.fgi;
NR = instance.parameters.NR;
source = instance.source;
pL=source:size()-Ni;
local name = profile:id();
instance:name(name);
fr[0]=0.191;fr[1]=0.236;fr[2]=0.382;fr[3]=0.5;
fr[4]=0.618;fr[5]=0.809;fr[6]=1;fr[7]=1.191;
fr[8]=1.236;fr[9]=0.382;fr[10]=1.5;fr[11]=1.618;
fr[12]=1.809;fr[13]=2;fr[14]=2.191;fr[15]=2.236;
fr[16]=2.382;fr[17]=2.5;fr[18]=2.618;fr[19]=2.809;
fr[20]=3;fr[21]=3.191;fr[22]=3.236;fr[23]=3.5;
fr[24]=3.618;fr[25]=3.809;fr[26]=4;fr[27]=4.191;
fr[28]=4.236;fr[29]=4.382;fr[30]=4.5;fr[31]=4.618;
Cen=instance:createTextOutput ("Cen", "Cen", "Arial", 6, core.H_Center, core.V_Top, instance.parameters.G_color, 0);
for i=1,4*fgi,1 do
f[i]=instance:createTextOutput ("f"..i, "f"..i, "Arial", 6, core.H_Center, core.V_Top, instance.parameters.B_color, 0);
g[i]=instance:createTextOutput ("g"..i, "g"..i, "Arial", 6, core.H_Center, core.V_Top, instance.parameters.R_color, 0);
end
end
function Update(period,mode)
local i,H,L,DH,DL,DHL,con,s;
local ps,price,px,n;
local p={}; local dp={}; local ip;
if period==pL-1 then
ps=source:pipSize();n=0;
core.host:execute("drawLabel", 1, source:date(period), source.high[period]+7*ps, "*");
for s=pL-1,pL-1-limit,-1 do
H=source.high[s-NR]; L=source.low[s-NR];
if H==mathex.max(source.high, core.rangeTo(s, 2*NR+1)) then n=n+1; p[n]=H; dp[n]=s-NR; end
if L==mathex.min(source.low, core.rangeTo(s,2*NR+1)) then n=n+1; p[n]=(-1)*L; dp[n]=s-NR; end
end
for s=1,n-1,1 do
con=0;
if p[s]>0 then
ip=0;
for i=s+1,n,1 do if p[i]<0 then ip=i; break; end end
if ip>0 then if (-1)*p[ip]<p[s]-3*ps then DH=p[s]; DL=-1*p[ip]; DHL=DH-DL; con=1; end end
elseif p[s]<0 then
ip=0;
for i=s+1,n,1 do if p[i]>0 then ip=i; break; end end
if ip>0 then if p[ip]>(-1)*p[s]+3*ps then DH=p[ip]; DL=-1*p[s]; DHL=DH-DL; con=2; end end
end
if con>=1 then
DH=0.5*(DH+DL+DHL); DL=DH-DHL;
price=math.ceil(0.5*(DH+DL)*10/ps); px=string.sub(price,-3); price=price*ps/10; Cen:set(dp[s],price,px);
for i=1,4*fgi,1 do
price=math.ceil((DH-DHL*fr[i-1])*10/ps); px=string.sub(price,-3); price=price*ps/10; f[i]:set(dp[s],price,px);
price=math.floor((DL+DHL*fr[i-1])*10/ps); px=string.sub(price,-3); price=price*ps/10; g[i]:set(dp[s],price,px);
end
end
--for s=
end
--if period=
end
--function
end