Integrating Lua programming language w/ MultiCharts

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 76 times
Contact:

Integrating Lua programming language w/ MultiCharts

Postby fbertram » 11 Dec 2015

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
Attachments
LuaForMultiCharts.pla
(45.49 KiB) Downloaded 723 times

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Integrating Lua programming language w/ MultiCharts

Postby bensat » 26 Dec 2015

This is awesome ... !!!!!!!!!! Makes me happy as I love Lua.

Ben

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 76 times
Contact:

Re: Integrating Lua programming language w/ MultiCharts

Postby fbertram » 27 Dec 2015

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

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 76 times
Contact:

Re: Integrating Lua programming language w/ MultiCharts

Postby fbertram » 15 Jan 2016

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


Return to “User Contributed Studies and Indicator Library”