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!
fbertram
Posts: 128
Joined: 16 Oct 2014
Has thanked: 37 times
Been thanked: 51 times

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 167 times

User avatar
bensat
Posts: 332
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 103 times

Re: Integrating Lua programming language w/ MultiCharts

Postby bensat » 26 Dec 2015

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

Ben

fbertram
Posts: 128
Joined: 16 Oct 2014
Has thanked: 37 times
Been thanked: 51 times

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

fbertram
Posts: 128
Joined: 16 Oct 2014
Has thanked: 37 times
Been thanked: 51 times

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”