It must be noticed however, that this indicator doesn't give any information as to the direction of the trade, for that a directional indicator must be used.
- Code: Select all
function Init()
indicator:name("Hurst Difference");
indicator:description("Hurst Difference");
indicator:requiredSource(core.Bar);
indicator:type(core.Oscillator);
indicator.parameters:addInteger("Period", "Period", "Period", 30);
indicator.parameters:addString("app_price", "app_price", "", "close");
indicator.parameters:addStringAlternative("app_price", "close", "", "close");
indicator.parameters:addStringAlternative("app_price", "open", "", "open");
indicator.parameters:addStringAlternative("app_price", "high", "", "high");
indicator.parameters:addStringAlternative("app_price", "low", "", "low");
indicator.parameters:addStringAlternative("app_price", "median", "", "median");
indicator.parameters:addStringAlternative("app_price", "typical", "", "typical");
indicator.parameters:addStringAlternative("app_price", "weighted", "", "weighted");
indicator.parameters:addColor("clr_Line", "Color of Line", "Color of Line", core.rgb(255, 255, 0));
end
local first;
local source = nil;
local Period;
local app_price;
local Price;
local fdi;
local HurstBuff=nil;
function Prepare()
source = instance.source;
Period=instance.parameters.Period;
app_price=instance.parameters.app_price;
first = source:first()+2;
local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.Period .. ", " .. instance.parameters.app_price .. ")";
instance:name(name);
Price = instance:addInternalStream(0, 0);
fdi = instance:addInternalStream(0, 0);
HurstBuff = instance:addStream("HurstBuff", core.Line, name .. ".HurstBuff", "HurstBuff", instance.parameters.clr_Line, first);
HurstBuff:addLevel(0);
end
function Update(period, mode)
if app_price=="close" then
Price[period]=source.close[period];
elseif app_price=="open" then
Price[period]=source.open[period];
elseif app_price=="high" then
Price[period]=source.high[period];
elseif app_price=="low" then
Price[period]=source.low[period];
elseif app_price=="median" then
Price[period]=(source.high[period]+source.low[period])/2.;
elseif app_price=="typical" then
Price[period]=(source.high[period]+source.low[period]+source.close[period])/3.;
else
Price[period]=(source.high[period]+source.low[period]+2.*source.close[period])/4.;
end
if (period>first+Period) then
local priceMax=core.max(Price,core.rangeTo(period,Period));
local priceMin=core.min(Price,core.rangeTo(period,Period));
local length=0.;
local priorDiff=0.;
local sum=0.;
for i=period-Period+1,period,1 do
if priceMax-priceMin>0. then
diff=(Price[i]-priceMin)/(priceMax-priceMin);
if i>period-Period+1 then
length=length+math.sqrt(math.pow(diff-priorDiff,2)+(1./math.pow(Period,2)));
end
priorDiff=diff;
end
end
if length>0. then
fdi[period]=1.+(math.log(length)+math.log(2.))/math.log(2.*(Period-1))
else
fdi[period]=0.;
end
HurstBuff[period]=fdi[period-1]-fdi[period];
end
end
Mq4/MT4 version.
viewtopic.php?f=38&t=63898