The indicator is a port of Metatrader TrendLord indicator.
Trendlord indicator shows the trend direction. A green bar means uptrend and a red bar means down trend.
A green bar appears when TrendLordFunction is above the previous value and a red bar appears when it's below the previous value.
Important! The indicator repaints one bar back when direction is switched. So, the signal and/or strategy will show the signal two bars back against the displayed value.
The function is
LWMA(LWMA(close, N), SquareRoot(N))
where N is the indicator parameters.
Download indicator:
- Code: Select all
function Init()
indicator:name("Trend lord");
indicator:description("Trend lord");
indicator:requiredSource(core.Tick);
indicator:type(core.Oscillator);
indicator.parameters:addGroup("Calculation");
indicator.parameters:addInteger("Period", "Period", "Period", 50);
indicator.parameters:addBoolean("StrategyMode", "Don't change, parameter is for strategies only!!!", "", false);
indicator.parameters:addGroup("Style");
indicator.parameters:addColor("clrUP", "UP color", "UP color", core.rgb(0, 255, 0));
indicator.parameters:addColor("clrDN", "DN color", "DN color", core.rgb(255, 0, 0));
end
local first;
local source = nil;
local Period;
local MA;
local buffUP=nil;
local buffDN=nil;
local array1;
local array2;
function Prepare(onlyName)
source = instance.source;
Period=instance.parameters.Period;
local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.Period .. ")";
instance:name(name);
if onlyName then
return ;
end
MA = core.indicators:create("LWMA", source, Period);
firstMA = MA.DATA:first();
MA2 = core.indicators:create("LWMA", MA.DATA, math.sqrt(Period));
array1 = MA2.DATA;
first = array1:first() + 1;
if instance.parameters.StrategyMode then
array2 = instance:addStream("D", core.Line, name .. ".D", "D", core.rgb(0, 0, 0), first);
array2:setStyle(core.LINE_NONE);
else
array2 = instance:addInternalStream(first, 0);
end
buffUP = instance:addStream("UP", core.Bar, name .. ".UP", "UP", instance.parameters.clrUP, first);
buffDN = instance:addStream("DN", core.Bar, name .. ".DN", "DN", instance.parameters.clrDN, first);
end
function Update(period, mode)
MA:update(mode);
MA2:update(mode);
if period >= first then
array2[period] = array2[period - 1];
if array1[period] > array1[period - 1] then
array2[period] = 1;
elseif array1[period] < array1[period - 1] then
array2[period] = -1;
end
if array2[period] > 0 then
buffUP[period] = array1[period];
if array2[period - 1] < 0 then
buffUP[period - 1] = array1[period - 1];
buffDN[period - 1] = nil;
end
elseif array2[period] < 0 then
buffDN[period]=array1[period];
if array2[period - 1] > 0 then
buffDN[period - 1] = array1[period - 1];
buffUP[period - 1] = nil;
end
end
end
end
TrendLord with Higher Time Frame Confirmation will add Higher Time Frame TrendLord,
to confirm the chart time frame indications.
TrendLord.lua based strategy.
viewtopic.php?f=31&t=2262