Page 1 of 1

Integrating Lua programming language w/ MultiCharts

Posted: 11 Dec 2015
by fbertram
Dear MultiCharts fans,

while EasyLanguage is very good for developing trading strategies, it is missing a lot of the functionality typical programming languages have. These include more fancy data types and access to the file system. One way to overcome these issues, is to use ELCollections, which admittedly is great. Here is a different approach how to do this: By integrating the Lua language interpreter w/ MultiCharts.

Here is a quick example what you can do with this:

Code: Select all

//==============================================================================
// Name: _fub_Lua_Test
// Description: simple Lua test project
// History: 2015xii11, FUB: created
//==============================================================================

variables:
LuaState (0);

once begin
ClearPrintLog;

//==============================================================================
// demo #1: set and get global variables, run calculation
LuaState = Lua.New();

// set global variables
Lua.SetGlobalNumber(LuaState, "a", 17);
Lua.SetGlobalNumber(LuaState, "b", 4);

// run calculation
Lua.Exec(LuaState, "c = a + b");

// get global variables
value1 = Lua.GetGlobalNumber(LuaState, "c");
print("c = ", value1);

Lua.Close(LuaState);

//==============================================================================
// demo #2: save data to file
LuaState = Lua.New();

Lua.Exec(LuaState, "f = io.open([[C:\Users\Felix Bertram\Desktop\Lua.txt]], [[w]])");
Lua.Exec(LuaState, "f:write([[Lua says hello!]])");
Lua.Exec(LuaState, "f:close()");

Lua.Close(LuaState);
end;

//==============================================================================
// end of file
If you want to learn more about Lua, have a look here:
http://www.lua.org/docs.html

This code requires the Lua 5.3 DLL. You will most likely want the Windows 64 DLL package, which you find here:
http://luabinaries.sourceforge.net/download.html

This code is in early stages, more as a proof of concept. There is lots more to do, e.g. passing strings back and forth between MultiCharts and Lua. However, I believe it might already useful "as is". Any comments welcome!


Cheers, Felix

Re: Integrating Lua programming language w/ MultiCharts

Posted: 26 Dec 2015
by bensat
This is awesome ... !!!!!!!!!! Makes me happy as I love Lua.

Ben

Re: Integrating Lua programming language w/ MultiCharts

Posted: 27 Dec 2015
by fbertram
Hi Ben,

I'm glad you like the idea. Allows to do a lot of things you can't do with ElCollections. Let me know how it works for you and how you would like to use it - I might be able to make it happen.

Cheers, Felix

Re: Integrating Lua programming language w/ MultiCharts

Posted: 15 Jan 2016
by fbertram
some sample code how to create dynamic 2D arrays:
viewtopic.php?f=1&t=49332&p=119193#p119193