Exchanging data between code

Questions about MultiCharts and user contributed studies.
PK1
Posts: 102
Joined: 12 Jun 2011
Has thanked: 42 times
Been thanked: 12 times

Exchanging data between code

Postby PK1 » 18 May 2018

Hello,

I've got a question regarding the ways of exchanging data between a strategy and an indicator. The indicator is processing things and storing potential signals in a global variable. I've checked the few posts to be found on the net and here as well, also of course the PDF containing little documentation regarding the GV. I know that Global Variables are not part of Multicharts but important for some things when developing indicators and strategies and many user are interested in using them. So I hope I can address the problem here. I will start explaining what I did followed by the actual problem.

Since a few years I use global variables and it works quite well. At the moment I use the methods and the similar methods for Int (which has no impact on the problem)

Code: Select all

GVSetNamedDouble(tpGlobalVar, tpPrice); GVGetNamedDouble("S8_M5_TP", -1);
In 2017 I'read a post with suggestions that AccuracySetNamedInt and AccuracyGetNamedInt are a replacement for the methods above. I couldn't find any detailed information, like a well hidden secret.

Now I wanted to add GV to my strategies storing signals in GV in order to fetch them later on in my strategy. I came upon strange behavior looking like a binding or threading problem. The code in the indicator is like this and the problem occurs already on this side where I store the value.

Code: Select all

variables: signalVal ( 0 ), hasLongSignal ( false );

if hasLongSignal = true then signalVal = 5
else signalVal = 8;

// GVSetNamedInt(signalName, _Bool2Int(hasLongSignal)); // Original idea but always stores 0
// GVSetNamedInt("SignalX", signalVal);
AccuracySetNamedInt("SignalX", signalVal); // all variants I've tried store a value where hasLongSignal is false, even if hasLongSignal is true, so here always 8, never 5

// Shows always the correct value, sometimes 1 and sometimes 0 depending on hasLongSignal
Commentary("# Signal=" + NumToStr(_Bool2Int(hasLongSignal), 0));
So there are the common ways to store the value and the simple boolean variable indicating the signal state is interpreted by the common methods like Commentary correctly but the GV-Methods always think that hasLongSignal is false. Even when not using the boolean directly and storing it into signalVal before accessing the GV-Method the code always thinks the hasLongSignal is false.

I wanted to avoid storing the signals into a time series or using my interop-lib to change data between code but I have no clue what is wrong here or whether I missed some important piece when using the GV or Accuracy-Methods.

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: Exchanging data between code

Postby Smoky » 18 May 2018

maybe try to evaluate (_Bool2Int(hasLongSignal) first and put in GV value

Code: Select all

tempvalue=_Bool2Int(hasLongSignal);
GVSetNamedInt(signalName, tempvalue);
i remember some issue with funtions in GV paramaters

PK1
Posts: 102
Joined: 12 Jun 2011
Has thanked: 42 times
Been thanked: 12 times

Re: Exchanging data between code

Postby PK1 » 18 May 2018

in the quoted code are three variants, with usage of my little converter function and with using the int value directly. It doesn't matter for the outcome, unfortunately.

The GV Method always uses the wrong value of hasLongSignal and the Commentary-Method uses the value which was calculated before (the simple IF-ELSE Part). Actually this can't be possible, both methods should behave identical when dealing with current variables but they don't.

Is there some threading or binding problem with the DLL?

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: Exchanging data between code

Postby Smoky » 18 May 2018

@PK1

personally i prefer to use sharevar tools, because with sharevar server you can see yours datas in real time ! very good for debugging ...

Image


https://fx1.net/sharedvar.php


hope it can help You.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Exchanging data between code

Postby TJ » 18 May 2018

Hello,

I've got a question regarding the ways of exchanging data between a strategy and an indicator. ....

Are the strategy and indicator residing in the same chart?

PK1
Posts: 102
Joined: 12 Jun 2011
Has thanked: 42 times
Been thanked: 12 times

Re: Exchanging data between code

Postby PK1 » 18 May 2018

Are the strategy and indicator residing in the same chart?
Yes.
Also I opened only one workspace and checked that the strategy is not running on another chart.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Exchanging data between code

Postby TJ » 18 May 2018

Look up these new Keywords. They might be useful

i_getplotvalue
i_setplotvalue

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: Exchanging data between code

Postby Smoky » 19 May 2018

Yes TJ, but only on way signal to indicator ? is there a way to use ploted data in signal to only have calculated data ? without GV or other external tool

PK1
Posts: 102
Joined: 12 Jun 2011
Has thanked: 42 times
Been thanked: 12 times

Re: Exchanging data between code

Postby PK1 » 19 May 2018

personally i prefer to use sharevar tools, because with sharevar server you can see yours datas in real time ! very good for debugging ...
Indeed! Very helpful, didn't know about that and it looks very promising. Right now I was trying to revive my C# App which is connected via a DLL and MySQL to MC, so there I can debug the workflow I trigger within MC and my thoughts were to do my own thing with Named Pipes or Memory Mapped Files. I will try SharedVar, thx for pointing out!
i_getplotvalue
i_setplotvalue
Very useful as well! Thx! For a single chart with indicator and strategy to draw results (like drawdown) from signal this is perfect. According to the docu i_setplotvalue is to avoid copying calculation logic in both, indicator and strategy but I'm afraid the realization is only for one direction (Strategy --> Indicator). So one still would need to copy calculation logic in both, indicator and strategy. Moreover afaik there is only the possibility for one variable which reduces the usage extremely. GV would do it as there's a huge need for exchanging data between the running indicators and strategies when developing a realistic approuch of a trading system. Would be a valuable improvement for MC to have a solid solution regarding this, maybe based on the already existing messaging system ...

I wrote logic in my indicators, function and external DLL, my strategies just collect all needed calculations and put all things up, doing the trade management. It wouldn't be a clean solution to mix this up putting some logic there and some somewhere else. Logic for my indicators should stay there (not existing twice which is always error prone), core methods should stay in my functions, further calculations and logging should be done by the external DLL.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Exchanging data between code

Postby TJ » 19 May 2018

If there is a will, there is a way.

PK1
Posts: 102
Joined: 12 Jun 2011
Has thanked: 42 times
Been thanked: 12 times

Re: Exchanging data between code

Postby PK1 » 19 May 2018

If there is a will, there is a way.
ok, but one has to stick to given signatures which limit the usage. With these I_set/I_get - functionality things get way better but in a limited way. Pls correct me if I don't see some things but someone who wants to draw max drawdown and current profit from a signal, that person can't use the set/get-methods as there is no distinction. Using multiple charts with different time frame then tf1 and tf2 can both be necessary for a signal to calculate. Not possible either, only with GV for example. Also the common workflow should be that indicator logic doesn't reside in a strategy as a copy. Not possible either. That thinking that the logic shouldn't reside as a copy in indicator and strategy is part of the docu itself but only possible when someone wants to draw exactly one information from a signal onto a chart. Anything more exceeds the limit, unfortunately.

Don't see this as critique, it's just the limit of the set/get-Methods making ppl seeking for external things as I do.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Exchanging data between code

Postby TJ » 19 May 2018

If there is a will, there is a way.
ok, but one has to stick to given signatures which limit the usage. With these I_set/I_get - functionality things get way better but in a limited way. Pls correct me if I don't see some things but someone who wants to draw max drawdown and current profit from a signal, that person can't use the set/get-methods as there is no distinction. Using multiple charts with different time frame then tf1 and tf2 can both be necessary for a signal to calculate. Not possible either, only with GV for example. Also the common workflow should be that indicator logic doesn't reside in a strategy as a copy. Not possible either. That thinking that the logic shouldn't reside as a copy in indicator and strategy is part of the docu itself but only possible when someone wants to draw exactly one information from a signal onto a chart. Anything more exceeds the limit, unfortunately.

Don't see this as critique, it's just the limit of the set/get-Methods making ppl seeking for external things as I do.

That's why I asked if the strategy and indicator reside in the same chart.

If you have other requirements, you might need other solutions.

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: Exchanging data between code

Postby Smoky » 20 May 2018

@PK1 if you want database you can also use ELcollections with List and Maps structures, run fast as GlobalVariables and can share all datas without any problem with List.share or Maps.share instructions...


* tests made with 64 bits dll


Return to “MultiCharts”