Help with metatrader 4 to LUA

Moderator: admin

Help with metatrader 4 to LUA

Postby WoodyFX » Thu Mar 11, 2010 5:26 am

Hello I'm new to the LUA and I would like some help converting this MT4 code snippet to LUA.
Code: Select all
(High[iHighest(NULL,0,MODE_HIGH,Pd,i)] + Low[iLowest(NULL,0,MODE_LOW,Pd,i)])


iHighest takes the form in MT4 as
int iHighest( string symbol, int timeframe, int type, int count=WHOLE_ARRAY, int start=0)
Returns the shift of the maximum value over a specific number of periods depending on type.
Parameters:
symbol - Symbol the data of which should be used to calculate indicator. NULL means the current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
type - Series array identifier. It can be any of the Series array identifier enumeration values.
count - Number of periods (in direction from the start bar to the back one) on which the calculation is carried out.
start - Shift showing the bar, relative to the current bar, that the data should be taken from.

Sample:
double val;
// calculating the highest value on the 20 consequtive bars in the range
// from the 4th to the 23rd index inclusive on the current chart
val=High[iHighest(NULL,0,MODE_HIGH,20,4)];



thanks in advance for your help.
WoodyFX
 
Posts: 2
Joined: Thu Mar 11, 2010 5:05 am

Re: Help with metatrader 4 to LUA

Postby Nikolay.Gekht » Thu Mar 11, 2010 10:03 am

For the current version:
Code: Select all
local range, result;

-- i = 0 is the latest element
-- i = 1 the previous element and so on...
-- Pd - number of items
range = core.rangeTo(instance.source:size() - i - 1, Pd);
result = core.max(instance.source.high, range) - core.min(instance.source.low, range);


The next version will be also allow a faster way, when min and max are calculated together:
Code: Select all
local range, result, min, max;

-- i = 0 is the latest element
-- i = 1 the previous element and so on...
-- Pd - number of items
range = core.rangeTo(instance.source:size() - i - 1, Pd);
min, max = core.minmax(instance.source, range);
result = max - min;


If you need an index of the period, use the second returned value of the min or max functions:
Code: Select all
local range, max, pos;
-- find the maximum value and return the difference from the previous to the max value.
range = core.rangeTo(instance.source:size() - i - 1, Pd);
max, pos = core.max(instance.source.high, range);
return (max - instance.source.high[pos - 1]);
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Help with metatrader 4 to LUA

Postby WoodyFX » Mon Mar 15, 2010 5:02 pm

Thanks for the help will try it out
WoodyFX
 
Posts: 2
Joined: Thu Mar 11, 2010 5:05 am


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 15 guests