FXCM Forex Trading

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: 204
Joined: Fri Feb 19, 2016 11:46 am
Location: Errywhere

Previous

Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 3 guests