下载MetaTrader 5
要添加评论,请登录注册
对交易者们的意见感兴趣吗?在论坛发起一个民意调查吧!
BingBing Wang
4207
BingBing Wang 2010.04.05 11:30 

-- http://vtsystems.com/resources/helps/0000/HTML_VTtrader_Help_Manual/index.html?ti_donchianchannel.html
--

-- initializes the indicator
function Init()
-- indicator:fail()
indicator:name("Donchian Channel")
indicator:description("The simple trend-following indicator. Shows highest high and lowest low for the specified number of periods.");
indicator:requiredSource(core.Bar);
indicator:type(core.Indicator);

indicator.parameters:addInteger("N", "Number of periods", "", 20, 2, 10000);
indicator.parameters:addString("AC", "Analyze the current period", "", "yes");
indicator.parameters:addStringAlternative("AC", "no", "", "no");
indicator.parameters:addStringAlternative("AC", "yes", "", "yes");
indicator.parameters:addColor("clrDU", "Color of the Up line", "", core.rgb(255, 255, 0));
indicator.parameters:addColor("clrDN", "Color of the Down line", "", core.rgb(255, 255, 0));
indicator.parameters:addColor("clrDM", "Color of the middle line", "", core.rgb(255, 255, 0));
indicator.parameters:addString("SM", "Show middle line", "", "no");
indicator.parameters:addStringAlternative("SM", "no", "", "no");
indicator.parameters:addStringAlternative("SM", "yes", "", "yes");

end

local first = 0;
local n = 0;
local ac = true;
local sm = false;
local source = nil;
local dn = nil;
local du = nil;
local dm = nil;

-- initializes the instance of the indicator
function Prepare()
source = instance.source;
n = instance.parameters.N;
ac = (instance.parameters.AC == "yes");
sm = (instance.parameters.SM == "yes");

first = n + source:first() - 1;
if (not ac) then
first = first + 1;
end
local name = profile:id() .. "(" .. source:name() .. "," .. n .. ")";
instance:name(name);
dn = instance:addStream("DU", core.Line, name .. ".DU", "DU", instance.parameters.clrDU, first)
du = instance:addStream("DN", core.Line, name .. ".DN", "DN", instance.parameters.clrDN, first)
if (sm) then
dm = instance:addStream("DM", core.Line, name .. ".DM", "DM", instance.parameters.clrDM, first)
end
end

-- calculate the value
function Update(period)
if (period >= first) then
local range;
if (ac) then
range = core.rangeTo(period, n);
else
range = core.rangeTo(period - 1, n);
end
du[period] = core.max(source.high, range);
dn[period] = core.min(source.low, range);
if (sm) then
dm[period] = (du[period] + dn[period]) / 2;
end
end
end


BingBing Wang
4207
BingBing Wang 2010.04.05 11:37  

最好有会写ea公式也来帮忙,我有交易思路,但不会写,求双赢。

Bryant
22
Bryant 2010.04.06 07:36  

你这个好像是唐奇安通道吧?我会一点点ea编程,欢迎赐教:wenbb_4@126.com

ttchu
7
ttchu 2010.04.09 02:33  

问题不知解决没有,我是做程序的,如果能合作肯定是没问题的,ourusb@gmail.com

/
要添加评论,请登录注册