External inputs / values into strategies? e.g. csv lookup?  [SOLVED]

Questions about MultiCharts and user contributed studies.
thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

External inputs / values into strategies? e.g. csv lookup?

Postby thutch » 23 Apr 2012

Hello everyone,

I hope someone here will have useful ideas.

External to MC, I am calculating Kelly fractions (% to invest) for different strategies, which considers both returns and their covariances. I have a whole bunch of strategies, and would like each of them to somehow look up this external value (to be recalculated weekly). I prefer to not manually type these values into MC strategies as there are many of them and errors are bound to be made.

The number of contracts to trade per strategy in MC should be calculated from a realtime account (equity) look-up together with the Kelly fraction.

The realtime account look-up is not hard to do, but I have no idea how to import the Kelly values into different strategies. My external programme could produce an excel file or csv, but I don't know how to:

1) reference that file from within MC strategy code, and
2) match the correct Kelly fractions from this file to each strategy

Surely there is a way to do this?

Any help or suggestions are warmly welcomed.

User avatar
Henry MultiСharts
Posts: 9132
Joined: 25 Aug 2011
Has thanked: 1260 times
Been thanked: 2929 times

Re: External inputs / values into strategies? e.g. csv looku

Postby Henry MultiСharts » 25 Apr 2012

Hello Thutch,

You can read from a file with the help of a custom Dll.
It is not provided from the box, you need to write it or search for it over the Internet (as far as I am concerned ELCollections provides an opportunity to read from a file-use our forum search to find it).
In order to call an outside dll from Power Language you need to use DefineDLLFunc code word.
DefineDLLFunc: “dll name”, the parameter dll returns, “the name of the function you refer to (inside the external dll)”, the type of the data you send to the external dll.

Code: Select all

DefineDLLFunc: "dlltest.dll", int, "MC_TEST", int;

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: External inputs / values into strategies? e.g. csv looku

Postby furytrader » 26 Apr 2012

The ELCollections.dll, which is free on the Internet and can be found here:

viewtopic.php?t=2483

... adds a bunch of new commands to EasyLanguage which can be used to retrieve data from .csv files and search it quickly. I've written several strategies that use % probability data generated in a .csv file to evaluate current setups.

The ELCollections.dll .zip file also contains a good user's guide about how to use it.

That's where I would start.

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: External inputs / values into strategies? e.g. csv looku

Postby TJ » 26 Apr 2012

If you using MultiCharts 64 bit version,
please download your add-on here:

viewtopic.php?f=16&t=10094

thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

Re: External inputs / values into strategies? e.g. csv looku

Postby thutch » 26 Apr 2012

The ELCollections.dll, which is free on the Internet and can be found here:

viewtopic.php?t=2483

... adds a bunch of new commands to EasyLanguage which can be used to retrieve data from .csv files and search it quickly. I've written several strategies that use % probability data generated in a .csv file to evaluate current setups.

The ELCollections.dll .zip file also contains a good user's guide about how to use it.
Ok, so I eventually understood that these functions need to be imported into MC. And then I read the guide and followed an example.

I can't say I understand it too well, but it does seem to work. Here is the result for some code that calculates the number of contracts to trade per strategy based on an external file called 'last_live_ctrl.csv' (and it runs together with a silly strategy):

Code: Select all

Vars:
millicontracts(0),
equity(0),
Num(MapSC.New),
RowMap(MapSN.New),
ColList(0),
RowNum(0);

MapSC.ReadFile(Num,"C:/Users/Administrator/Desktop/live/last_live_ctrl.csv");
// renames the ctrl file 'Num'
MapSC.BuildRowMap(Num,RowMap,"file");
// "file" is the column with the model name

ColList = MapSC.Get(Num, "millicontractsPerDollarEquity");
// get the contracts column from Num
RowNum = MapSN.Get(RowMap, "CL_trade.csv");
// get the row for the specific model

millicontracts = (ListN.Get(ColList, RowNum));
// assign the millicontracts value

equity = GetRTAccountEquity("DU....");
// paper trading account

If marketposition = 0 then buy floor(millicontracts * equity / 1000) contracts next bar at low limit;
If marketposition > 0 then sell next bar at high limit;

If marketposition = 0 then sellshort floor(millicontracts * equity / 1000) contracts next bar at high limit;
If marketposition < 0 then buytocover next bar at low limit;

arjfca
Posts: 1283
Joined: 23 Nov 2010
Has thanked: 724 times
Been thanked: 222 times

Re: External inputs / values into strategies? e.g. csv looku

Postby arjfca » 27 Apr 2012

Hello everyone,

I hope someone here will have useful ideas.

External to MC, I am calculating Kelly fractions (% to invest) for different strategies, which considers both returns and their covariances. I have a whole bunch of strategies, and would like each of them to somehow look up this external value (to be recalculated weekly). I prefer to not manually type these values into MC strategies as there are many of them and errors are bound to be made.

The number of contracts to trade per strategy in MC should be calculated from a realtime account (equity) look-up together with the Kelly fraction.

The realtime account look-up is not hard to do, but I have no idea how to import the Kelly values into different strategies. My external programme could produce an excel file or csv, but I don't know how to:

1) reference that file from within MC strategy code, and
2) match the correct Kelly fractions from this file to each strategy

Surely there is a way to do this?

Any help or suggestions are warmly welcomed.
Hello To communicate between MC and Excel I use XLinput dll and Global Variable

- XLINPUT could read and write to Excel Sometime it fail because the link between them is fragile. You can't code Excel or play with formula while a communication link is established between them. Timing will cause a problem and MC indicator or signal will bring an error and close the indicator.

- Global variable work very well too.

Martin

Shahram
Posts: 5
Joined: 21 Apr 2017
Has thanked: 1 time

Re: External inputs / values into strategies? e.g. csv looku

Postby Shahram » 22 Apr 2017

The ELCollections.dll, which is free on the Internet and can be found here:

viewtopic.php?t=2483

... adds a bunch of new commands to EasyLanguage which can be used to retrieve data from .csv files and search it quickly. I've written several strategies that use % probability data generated in a .csv file to evaluate current setups.

The ELCollections.dll .zip file also contains a good user's guide about how to use it.
Ok, so I eventually understood that these functions need to be imported into MC. And then I read the guide and followed an example.

I can't say I understand it too well, but it does seem to work. Here is the result for some code that calculates the number of contracts to trade per strategy based on an external file called 'last_live_ctrl.csv' (and it runs together with a silly strategy):

Code: Select all

Vars:
millicontracts(0),
equity(0),
Num(MapSC.New),
RowMap(MapSN.New),
ColList(0),
RowNum(0);

MapSC.ReadFile(Num,"C:/Users/Administrator/Desktop/live/last_live_ctrl.csv");
// renames the ctrl file 'Num'
MapSC.BuildRowMap(Num,RowMap,"file");
// "file" is the column with the model name

ColList = MapSC.Get(Num, "millicontractsPerDollarEquity");
// get the contracts column from Num
RowNum = MapSN.Get(RowMap, "CL_trade.csv");
// get the row for the specific model

millicontracts = (ListN.Get(ColList, RowNum));
// assign the millicontracts value

equity = GetRTAccountEquity("DU....");
// paper trading account

If marketposition = 0 then buy floor(millicontracts * equity / 1000) contracts next bar at low limit;
If marketposition > 0 then sell next bar at high limit;

If marketposition = 0 then sellshort floor(millicontracts * equity / 1000) contracts next bar at high limit;
If marketposition < 0 then buytocover next bar at low limit;

Hello,

Would you pls tell how did you define all necessary funktions by "DefineDLLFunc:"?

Best Regards

arjfca
Posts: 1283
Joined: 23 Nov 2010
Has thanked: 724 times
Been thanked: 222 times

Re: External inputs / values into strategies? e.g. csv lookup?

Postby arjfca » 22 Apr 2017

Look for the elcollection. There is some exemple on the site on how to read a csv file.

I did wrote a little function that will read a specific data on a csv string that is available. Look for splitstring I did wrote it for MC and Excel

Basically,
Splitring(CSV string, position);
Splitstring("Marc, Paul, Ann,Denis",2) will return "Paul" Paul is the 2' data in the csv string

Martin

Shahram
Posts: 5
Joined: 21 Apr 2017
Has thanked: 1 time

Re: External inputs / values into strategies? e.g. csv lookup?

Postby Shahram » 22 Apr 2017

Ok!

My problem is that I do not find any documentation telling how to define the dlls functions!
Which parameters and types they get and what they return.

These informations needed to define those first lines as....
Externals: "MapSC.Readfile", .......
And so on!

Best regards
Shahram

Shahram
Posts: 5
Joined: 21 Apr 2017
Has thanked: 1 time

Re: External inputs / values into strategies? e.g. csv looku

Postby Shahram » 23 Apr 2017

Hello Thutch,

You can read from a file with the help of a custom Dll.
It is not provided from the box, you need to write it or search for it over the Internet (as far as I am concerned ELCollections provides an opportunity to read from a file-use our forum search to find it).
In order to call an outside dll from Power Language you need to use DefineDLLFunc code word.
DefineDLLFunc: “dll name”, the parameter dll returns, “the name of the function you refer to (inside the external dll)”, the type of the data you send to the external dll.

Code: Select all

DefineDLLFunc: "dlltest.dll", int, "MC_TEST", int;

Hi,

Would you pls. tell how I define DLL functions of ELCollection?
I can not find any documentation with all the funktions with their parameters.
For example:
External: "ELCollections.dll", ????,"MapSC.New", ????, ????;

Best regards
Shahram

User avatar
ABC
Posts: 634
Joined: 16 Dec 2006
Has thanked: 120 times
Been thanked: 359 times
Contact:

Re: External inputs / values into strategies? e.g. csv lookup?  [SOLVED]

Postby ABC » 24 Apr 2017

Shahram,

there is no need to do that. Simply import the ELD with the functions, read the documentation and study the examples on how to use the functions.

Regards,

ABC

Shahram
Posts: 5
Joined: 21 Apr 2017
Has thanked: 1 time

Re: External inputs / values into strategies? e.g. csv lookup?

Postby Shahram » 24 Apr 2017

Thanks,

I just noticed that! :)


Return to “MultiCharts”