Center of Gravity I see also here: viewtopic.php?f=17&t=366&p=605&hilit=Ehler#p605
Center of Gravity indicator:
- Code: Select all
function Init()
indicator:name("Ehlers CG Oscillator");
indicator:description("Ehlers CG Oscillator");
indicator:requiredSource(core.Bar);
indicator:type(core.Oscillator);
indicator.parameters:addInteger("Length", "Length", "", 10);
indicator.parameters:addColor("clr_buff1", "Color of Buff1", "Color of Buff1", core.rgb(0, 255, 0));
indicator.parameters:addColor("clr_buff2", "Color of Buff2", "Color of Buff2", core.rgb(0, 128, 0));
end
local first;
local source = nil;
local Length;
local Price;
local Buff1=nil;
local Buff2=nil;
function Prepare()
source = instance.source;
Length=instance.parameters.Length;
Price = instance:addInternalStream(0, 0);
first = source:first()+2;
local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.Length .. ")";
instance:name(name);
Buff1 = instance:addStream("Buff1", core.Line, name .. ".Buff1", "Buff1", instance.parameters.clr_buff1, first);
Buff2 = instance:addStream("Buff2", core.Line, name .. ".Buff2", "Buff2", instance.parameters.clr_buff2, first);
Buff1:addLevel(0);
end
function Update(period, mode)
if (period>first+Length) then
local Num=0.;
local Demon=0.;
Price[period]=(source.high[period]+source.low[period])/2.;
for i=0,Length-1,1 do
Num=Num+(i+1)*Price[period-i];
Demon=Demon+Price[period-i];
end
if Demon~=0. then
Buff1[period]=-Num/Demon+(Length+1.)/2.;
else
Buff1[period]=0.;
end
Buff2[period]=Buff1[period-1];
end
end
Cyber cycle indicator:
- Code: Select all
function Init()
indicator:name("Ehlers Cyber Cycle");
indicator:description("Ehlers Cyber Cycle");
indicator:requiredSource(core.Bar);
indicator:type(core.Oscillator);
indicator.parameters:addDouble("Alpha", "Alpha", "", 0.07);
indicator.parameters:addColor("clr_buff1", "Color of Buff1", "Color of Buff1", core.rgb(0, 255, 0));
indicator.parameters:addColor("clr_buff2", "Color of Buff2", "Color of Buff2", core.rgb(0, 128, 0));
end
local first;
local source = nil;
local Alpha;
local Price;
local Smooth;
local Buff1=nil;
local Buff2=nil;
function Prepare()
source = instance.source;
Alpha=instance.parameters.Alpha;
Price = instance:addInternalStream(0, 0);
Smooth = instance:addInternalStream(0, 0);
first = source:first()+2;
local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.Alpha .. ")";
instance:name(name);
Buff1 = instance:addStream("Buff1", core.Line, name .. ".Buff1", "Buff1", instance.parameters.clr_buff1, first);
Buff2 = instance:addStream("Buff2", core.Line, name .. ".Buff2", "Buff2", instance.parameters.clr_buff2, first);
Buff1:addLevel(0);
end
function Update(period, mode)
Price[period]=(source.high[period]+source.low[period])/2.;
if (period>first+4) then
Smooth[period]=(Price[period]+2.*Price[period-1]+2.*Price[period-2]+Price[period-3])/6.;
if period<first+8 then
Buff1[period]=(Price[period]-2.*Price[period-1]+Price[period-2])/4.;
else
Buff1[period]=(1.-0.5*Alpha)*(1.-0.5*Alpha)*(Smooth[period]-2.*Smooth[period-1]+Smooth[period-2])+2.*(1.-Alpha)*Buff1[period-1]-(1.-Alpha)*(1.-Alpha)*Buff1[period-2];
end
Buff2[period]=Buff1[period-1];
end
end
Ehlers_CG.lua based strategy.
viewtopic.php?f=31&t=2420