Go Back   DailyFX Forex Forum | FX Forum > FXCM Products and Services > FXProgrammers > Discussion / Support Forum > Indicator SDK Support

Reply
 
Thread Tools Rate Thread
  #1 (permalink)  
Old 01-28-2010, 04:24 AM
Member
 
Join Date: Jan 2010
Posts: 6
richardtao is an unknown quantity at this point
Question Help!! How to get core.max return value??

Can anyone give me the sample of indicore in lua regarding of core.max
because core.max return two value: the maxima and position
I am wondering how to get core.max
thanks!
Reply With Quote
  #2 (permalink)  
Old 02-01-2010, 01:43 AM
Member
 
Join Date: Apr 2009
Posts: 37
gidien is an unknown quantity at this point
use this

maxValue, maxPosition = core.max(source.high, core.rangeTo(period,N));

maxValue is your max returned from core.max
maxPosition is your Position (period) in the stream source.high.

example :

source.high[maxPosition] = your maxValue

for source.high you can use any indicator stream.
Reply With Quote
  #3 (permalink)  
Old 02-05-2010, 05:01 AM
Member
 
Join Date: Jan 2010
Posts: 6
richardtao is an unknown quantity at this point
Thanks gidien! it's amazing!
feedback a sample for dwon trend line list below.
if want to draw up trend line just apply the oppisite rule.
Hope everyone could enhanse if there had more efficient algorithm.

-- The indicator corresponds to the Down Trend Line in Richard Trading System
-- Usage: core.indicators:create("DTL", source, begin)
-- Description:darw the outter trend line of latest 10 period within the range begin to last


-- initializes the indicator
function Init()
indicator:name(resources:get("name"));
indicator:description(resources:get("description") );
indicator:requiredSource(core.Tick);
indicator:type(core.Indicator);

indicator.parameters:addInteger("N", resources:get("param_N_name"), resources:get("param_N_description"), 100, 2, 500);
indicator.parameters:addColor("clrDTL", resources:get("param_clrDTL_name"), resources:get("param_clrDTL_description"), core.rgb(255, 255, 255));
end

local first = 0;
local n = 0;
local source = nil;
local out = nil;

local sourcesize = 0;
local sourcepip = 0;
local pivot = nil;
local delta = nil;
local value1 = 0;
local value2 = 0;
local position1 = 0;
local position2 = 0;


-- initializes the instance of the indicator
function Prepare()
n = instance.parameters.N;
source = instance.source;
sourcesize = source:size() - 1;
sourcepip = sourceipSize();
first = sourcesize - n + 1;

local name = profile:id() .. "(" .. source:name() .. "," .. n .. ")";
instance:name(name);
pivot = instance:addInternalStream(0, 0);
delta = instance:addInternalStream(0, 0);

out = instance:addStream("DTL", core.Line, name, "DTL", instance.parameters.clrDTL, first)
end

-- calculate the value
function Update(period)
local rangeU = nil;
local rangeT = nil;
if (period == sourcesize) then
position1, position2 = DTLFindPeak(first, sourcesize);
out[position1] = position1;
out[position2] = position2;
--draw only the latest 10
rangeT = core.rangeTo(sourcesize, 10);
core.drawLine(out, rangeT, source[position1], position1, source[position2], position2);
end
end

-- find the most peak two point
function DTLFindPeak(pos1, pos2)
local i = 0;
local val = 0;
local rangeA = nil;
local rangeU = nil;
local peak = 0;
local valley = 0;
local mval = 0;
local peak1 = 0;
local peak2 = 0;


rangeA = core.range(source:first(), sourcesize);
rangeU = core.range(pos1, pos2);
-- find the trend start point
if source[pos1] > source[pos2] then
val, pos1 = core.max(source, rangeU);
else
val, pos1 = core.min(source, rangeU);
end
-- set base slope line
core.drawLine(pivot, rangeA, source[pos1], pos1, source[pos2], pos2);
-- find peak and valley
for i = source:first(), sourcesize do
if i >= pos1 then
val = (source[i] - pivot[i]);
if val > 0 then
if mval < 0 then
delta[valley] = mval;
mval = 0;
end
if val > mval then
mval = val;
peak = i;
end
elseif val < 0 then
if mval > 0 then
delta[peak] = mval;
mval = 0;
end
if val < mval then
mval = val;
valley = i;
end
elseif val == 0 then
if mval > 0 then
delta[peak] = mval;
mval = 0;
else
delta[valley] = mval;
mval = 0;
end
end
else
delta[i] = 0;
end
end

rangeU = core.range(pos1, pos2);
val, peak1, mval, peak2 = core.max2(delta, rangeU);
return peak1, peak2;
end
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Disclaimer: Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts. Any opinions, news, research, analyses, prices, or other information contained on this website is provided as general market commentary and does not constitute investment advice. Forex Capital Markets LLC. will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information.

All times are GMT -5. The time now is 02:33 PM.
Copyright ©2009 Daily FX. All Rights Reserved.