Function Collection

Moderator: admin

Re: Function Collection

Postby moomoofx » Wed Jan 28, 2015 7:02 pm

A date and time stamped Trace/Log function.
Very useful when debugging.

For use in strategies.
Code: Select all
function ExtTrace(message)
    local theDate = core.dateToTable(core.host:execute("convertTime", 1, 4, math.max(instance.bid:date(instance.bid:size() - 1), instance.ask:date(instance.ask:size() - 1))));
    core.host:trace(string.format("%d/%02d/%02d %02d:%02d:%02d ", theDate.year, theDate.month, theDate.day, theDate.hour, theDate.min, theDate.sec) .. " " .. message);
end


For use in indicators.
Code: Select all
function ExtTrace(message, date)
    local theDate = core.dateToTable(core.host:execute("convertTime", 1, 4, date));
    core.host:trace(string.format("%d/%02d/%02d %02d:%02d:%02d ", theDate.year, theDate.month, theDate.day, theDate.hour, theDate.min, theDate.sec) .. " " .. message);
end
User avatar
moomoofx
FXCodeBase: Confirmed User
 
Posts: 193
Joined: Wed Oct 23, 2013 10:26 pm
Location: Okinawa, Japan. http://moomooforex.com

Re: Function Collection

Postby moomoofx » Wed Jan 28, 2015 7:07 pm

Extend the String with a split function.

Code: Select all
-- ---------------------------------------------------------
-- Adds a split function to strings.
-- @param sep the separator
-- ---------------------------------------------------------
function string:split(sep)
    local sep, fields = sep or ";", {}
    local pattern = string.format("([^%s]+)", sep)
    self:gsub(pattern, function(c) fields[#fields + 1] = c end)
    return fields
end
User avatar
moomoofx
FXCodeBase: Confirmed User
 
Posts: 193
Joined: Wed Oct 23, 2013 10:26 pm
Location: Okinawa, Japan. http://moomooforex.com

Re: Function Collection

Postby Cactus » Thu Aug 25, 2016 8:38 am

These are very good. I just wanted to say I find the codes very useful, if you have any more functions you would want to share that will be nice I'm sure the community will benefit thanks in advance.
Never chase the money, let the money come to me
User avatar
Cactus
FXCodeBase: Graduate
 
Posts: 242
Joined: Fri Feb 19, 2016 11:46 am
Location: Errywhere

Re: Function Collection

Postby mariareese » Mon Oct 30, 2017 7:05 am

@Apprentice.. code suggestions are helpful for me at some points .. thanku ..
mariareese
 
Posts: 1
Joined: Tue Jul 18, 2017 8:21 am

LagrangeInterpolation

Postby Apprentice » Mon Oct 15, 2018 3:11 pm

local y=LagrangeInterpolation(x, x1, x2, x3, y1, y2, y3);

Code: Select all
function LagrangeInterpolation(x, x1, x2, x3, y1, y2, y3)
local A=(y1*(x-x2)*(x-x3))/((x1-x2)*(x1-x3));
local B=(y2*(x-x1)*(x-x3))/((x2-x1)*(x2-x3));
local C=(y3*(x-x1)*(x-x2))/((x3-x1)*(x3-x2));
return A+B+C;
end

For lines defined by three points, will try to approximate line values.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Previous

Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 7 guests