Multiple data indicator

Questions about MultiCharts and user contributed studies.
User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Multiple data indicator

Postby larssan » 09 Oct 2011

Hi,

I'm trying to plot a relative strength indicator on a tick chart.
I use ES as data1 and NQ as data2, then I add the "Spread Ratio" indicator that is basically Data1/Data2.
This will work fine with time bars but when using a 600Tick chart the bar spacing will be uneven on the chart. (For obvious reasons, as the bars will not be completed at the same time)

My question is if anyone know if there is any way around this ?
What I want is a Tick chart with an indicator updating in real time with even spacing between the bars.
Just as it would look on a minute chart.
Data2 should somehow lock on to Data1 and create a bar whenever Data1 creates a bar.

The images are only for visualizing the issue, I need only one chart and one indicator below.
But as the indicator is using Data2 I need to plot a second data on the chart.

Chart without "lock" function:
Image

Chart with "lock" function: (NT)
Image

Thanks!

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Multiple data indicator

Postby JoshM » 09 Oct 2011

I'm trying to plot a relative strength indicator on a tick chart.
I use ES as data1 and NQ as data2, then I add the "Spread Ratio" indicator that is basically Data1/Data2.
This will work fine with time bars but when using a 600Tick chart the bar spacing will be uneven on the chart. (For obvious reasons, as the bars will not be completed at the same time)

My question is if anyone know if there is any way around this ?
What I want is a Tick chart with an indicator updating in real time with even spacing between the bars.
Just as it would look on a minute chart.
Data2 should somehow lock on to Data1 and create a bar whenever Data1 creates a bar.
A way around the bar spacing, or a way around how the Spread Indicator calculates? Because for the latter, you can change the default indicator to be only calculated when the slower instrument has closed a bar.

What you could do, is use the "All Data Everywhere" (ADE) DLL to plot Data1 and Data2 on Chart A, then create Chart B, and send the data from Chart A to the indicator plotted in Chart B. In theory that might work, but it's not as easily/quickly done at it sounds.

You could also plot the ES on Chart A, and make your own calculations of the candlesticks of NQ during that time (if you want to have the bar spacing correct, you'll need to apply NQ then to Chart B, and use GlobalVariables or ADE to send data to chart A). For example, as soon as the bar on ES opens, you could start collecting the open, high, low, close, volume data from NQ during the time period of the ES bar, and calculate the spread based on these data, so that in effect you'll have the NQ aligned with ES.

But these ideas are just food for thought, since I haven't coded this myself (otherwise I could give a concrete code example here), but that's how I would try to tackle this problem.

Btw, there is an Project Management entry for this: Multiple data series with tick data in same bar space for Tick, Contract, Point, and Renko charts.

Good luck! :)

Regards,
Josh

User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Re: Multiple data indicator

Postby larssan » 09 Oct 2011

A way around the bar spacing, or a way around how the Spread Indicator calculates?
I would say both spacing and calculations.
What you could do, is use the "All Data Everywhere" (ADE) DLL to plot Data1 and Data2 on Chart A, then create Chart B, and send the data from Chart A to the indicator plotted in Chart B. In theory that might work, but it's not as easily/quickly done at it sounds.
This sounds exactly what I'm after. Unfortunately that's way beyond my programming skills.

Do you have an idea how extensive that programming would be ?


Thanks!

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Multiple data indicator

Postby JoshM » 09 Oct 2011

Do you have an idea how extensive that programming would be?
A lot less time than I thought beforehand - just over an hour now. Can you tell me, judging from the attached screenshot, if this is what you mean / are looking for? In the image you'll see Chart A with the primary instrument on the left, and Chart B on the right with both instruments that compromise the spread. (I'll have to do some more testing to make sure that it's working, but so far it looks correct).

Any feedback or other ideas/suggestions more than welcome btw.

Regards,
Josh
Attachments
spreadIdea.png
(61.29 KiB) Downloaded 1170 times

User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Re: Multiple data indicator

Postby larssan » 09 Oct 2011

Can you tell me, judging from the attached screenshot, if this is what you mean / are looking for?
Exactly! :)

The calculations are done in Chart B and sent over to Chart A.
The indicator will plot in real time on Chart A. (Tick by Tick)

How is the calculation done when there is a new tick in Data1 but not in Data2 ?
Does it use the last available tick in Data2 ?


Regards, Lars

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Multiple data indicator

Postby JoshM » 09 Oct 2011

How is the calculation done when there is a new tick in Data1 but not in Data2 ?
Does it use the last available tick in Data2 ?
Yes, on the closing of the Data 1 bar, it uses the latest price from data 2. So if Data2 is a "slow" instrument, that would be a relatively old price, while it will be a recent price if the Data2 instrument is quick.


Using the indicators

To use the indicators (see below), you'll need to install the ELCollections, which can be found in this thread. "Install" sounds pretty complicated, but in this case it means a) put the ELCollections.DLL in the MultiCharts Program Files folder and b) import the .ELD file with the EasyLanguage Functions into the PowerLanguage Editor.

- The indicators below only use the MapNN.Share, MapNN.Get and MapNN.Put functions from the ELCollections .ELD file. So if you want, you can only import these three from that file - but of course you'll also may import all the ELCollections Functions. Just saying in case you don't want to import all those different functions.

-> Also read the document in the ELCollections zip, since that contains the whole step-by-step process needed to "install" the ELCollections into MultiCharts.

- To use the indicators, the indicator named "SendSpreadData" needs to be applied to the chart with the Data 1 and Data 2 dataseries applied. The "Spread Indicator'-indicator below will be applied to the chart with one data serie, on which you'll want your spread ratio be plotted. (On the attached screenshot, the "SendSpreadData" indicator is on the right, while the "Spread Indicator" is applied to the chart on the left.)

- The primary data serie on the chart with both data series on it needs to be the same as the data serie for which you'll want to plot the ratio. For example, with the ES 600 tick as Data1 and NQ 600 tick as Data2 on one chart, the other chart needs to be ES 600 tick. This is needed because the data map (see in the code below) generates an unique name for that map based on the instrument. So, it makes an data map available to other charts with the name "ES 600" in it, and the ES 600 tick chart looks for a shared data map named "ES 600".

(Sidenote: You can change the code below (the part in the MapNN.Share(......) code) to give the data map another name. I've chosen this way to ensure that each data map has an unique name, so that there are no conflicts if you add multiple of the spread indicators to other instruments. If you name each shared data map a fixed name, like "myData", you'll run into conflict errors.)

"SendSpreadData" indicator

Code: Select all

{ SendSpreadData indicator; this indicator 'sends' the spread ratio, between Data1 and Data2 to a shared data map,
so it can be used in other charts. }

Inputs:
DataSeries1(Close of data1), DataSeries2(Close of Data2);

Variables:
MapID(MapNN.Share(
Text(getsymbolname, "_", NumToStr(barinterval, 0), "_", NumToStr(bartype_ex, 0))
)),
dataKey(0);

// On closing tick of the primary data series, save the data in the shared map
if BarStatus(1) = 2 then begin
// Generate the unique identifier for this bar
dataKey = el_datetodatetime(date) + el_timetodatetime_s(time_s) / 10000;

// Calculate the spread
value1 = DataSeries1 / DataSeries2;

// Save the spread in the shared map
value2 = MapNN.Put(MapID, dataKey, value1);

// Plot the spread (just for comparision purposes)
Plot2(value1, "Spread");
end;
"Spread Indicator"

Code: Select all

{ Spread Indicator; this indicator plots the shared data map, which is made available from another chart. }

Variables:
MapID(MapNN.Share(
Text(getsymbolname, "_", NumToStr(barinterval, 0), "_", NumToStr(bartype_ex, 0))
)),
dataKey(0);

// Generate the unique identifier for this bar
dataKey = el_datetodatetime(date) + el_timetodatetime_s(time_s) / 10000;

// Get the value from the shared map
value1 = MapNN.Get(MapID, dataKey);

// Plot the retrieved value
Plot1(Value1, "Spread");
(Ow and yes, that's all the code. :) )

I've attached a screenshot with the four steps highlighted that the indicators perform. Coupled with the comments in the code above, that should make it relatively easy to tweak or change the indicator.

Good luck! :)

Regards,
Josh
Attachments
workingOfSpreadIndicator.png
(66.23 KiB) Downloaded 1150 times

User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Re: Multiple data indicator

Postby larssan » 09 Oct 2011

Thank you so much for your help! :)

I didn't think it was possible.

I'll set everything up and try it out...

Thanks, Lars

User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Re: Multiple data indicator

Postby larssan » 10 Oct 2011

Hi,

I've tried it and everything looks great.

But, every time a Tick is updated the Spread Indicator goes down to zero.
However, the plot on the "SendSpreadData" chart stays correct.

I tried with "unticking" the "Update on every tick" box, but the Spread Indicator still goes down to zero after completion of the first bar.

Can't really understand why as the "SendSpreadData" chart looks ok....

Regards, Lars

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Multiple data indicator

Postby Henry MultiСharts » 10 Oct 2011

Please try to disable the option in the Format indicator window-Skip identical ticks.

User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Re: Multiple data indicator

Postby larssan » 10 Oct 2011

Please try to disable the option in the Format indicator window-Skip identical ticks.
I've done that but it didn't help.

However, I was in contact with support today regarding a similar problem with a tick chart and they told me that it was a bug that would be fixed in a later release.

Maybe this is a similar problem...

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Multiple data indicator

Postby Henry MultiСharts » 10 Oct 2011

Yes Sir this bug was confirmed . It will be fixed in the next version of MultiCharts.
What I have suggested is a possible workaround at the moment.
Unfortunately this workaround cannot be applied to all cases.

User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Re: Multiple data indicator

Postby larssan » 11 Oct 2011

Yes Sir this bug was confirmed . It will be fixed in the next version of MultiCharts.
What I have suggested is a possible workaround at the moment.
Unfortunately this workaround cannot be applied to all cases.
Henry, can you confirm that this is the issue here to ?
Or could it be something else ?


Regards, Lars

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Multiple data indicator

Postby JoshM » 11 Oct 2011

Henry, can you confirm that this is the issue here to ?
Or could it be something else ?
(I think I've made an error, but I haven't completely uncovered/solved it. Will update later with more.)

User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Re: Multiple data indicator

Postby larssan » 11 Oct 2011

(I think I've made an error, but I haven't completely uncovered/solved it. Will update later with more.)
I really appreciate it.
But there are some issues with tick charts in MC7.1 so your code is probably correct...

Regarding the calculation:
You said that the last available price in data 2 will be used.
Is that the last tick in a "open" bar or the last tick in the last closed bar ?

Say you have a closed 600Tick bar since 5 min ago at 1220.00, and a working 600Tick bar with 400 ticks to go at 1221.00, which price will be used in the calculation ?

Hope you can understand what I mean... :)

Regards, Lars

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Multiple data indicator

Postby Henry MultiСharts » 11 Oct 2011

Henry, can you confirm that this is the issue here to ?
Or could it be something else ?
Regards, Lars
The issue you have reported in the live chat is a bug. It was confirmed.
It will be fixed in the next version of MultiCharts.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Multiple data indicator

Postby JoshM » 11 Oct 2011

But, every time a Tick is updated the Spread Indicator goes down to zero.
However, the plot on the "SendSpreadData" chart stays correct.

I tried with "unticking" the "Update on every tick" box, but the Spread Indicator still goes down to zero after completion of the first bar.

Can't really understand why as the "SendSpreadData" chart looks ok....
I've the same behaviour here; on the opening tick of the primary data series, the "Receiving indicator" plots correct, but for every other tick it drops completely to 0, and then on the opening tick of the next bar, it plots correctly, and then drops to 0, and so on. And during this time, the "Sending indicator" plots correctly. (Just to confirm we're talking about the same behaviour)

That behaviour was caused from an error on my part; in the code below this is corrected by removing the BarStatus(1) condition. With the current version, it will also update on every tick (something that the other version was designed not to do).

The “SendSpreadData” indicator

Code: Select all

{ "SendSpreadData" indicator; this indicator 'sends' the spread ratio, between Data1 and Data2 to a shared data map,
so it can be used in other charts. }

Inputs:
DataSeries1(Close of data1), DataSeries2(Close of Data2);

Variables:
MapID(MapNN.Share(
Text(getsymbolname, "_", NumToStr(barinterval, 0), "_", NumToStr(bartype_ex, 0))
)),
dataKey(0);

// Generate the unique identifier for this bar
if LastBarOnChart_s = true and GetAppInfo(aiRealTimeCalc) = 1 then
dataKey = 123.00000 // keep the data map tidy
else
dataKey = el_datetodatetime(date Data(1)) + el_timetodatetime_s(time_s Data(1)) / 10000;

// Calculate the spread
value1 = DataSeries1 / DataSeries2;

// Save the spread in the shared map
value2 = MapNN.Put(MapID, dataKey, value1);

// Plot the spread (just for comparison purposes)
Plot2(value1, "Spread");

// Showing which tick is used in the calculations;
// uncomment or delete the code below if you _don't_ want it to print
// to the PowerLanuage Editor Output window.
if LastBarOnChart_s = true and GetAppInfo(aiRealTimeCalc) = 1 then begin

Print(
GetSymbolName Data(1), " / ", GetSymbolName Data(2), " ratio @ ", NumToStr(value1, 10), NewLine,
Spaces(3),
GetSymbolName Data(1), " last price: ", Close Data(1), " @ ",
FormatTime("HH:mm:ss", el_timetodatetime_s(time_s Data(1))), NewLine,
Spaces(3),
GetSymbolName Data(2), " last price: ", Close Data(2), " @ ",
FormatTime("HH:mm:ss", el_timetodatetime_s(time_s Data(2)))
);

end;
The “ReceiveSpreadData” indicator

Code: Select all

{ "ReceiveSpreadData" Indicator; this indicator plots the shared data map, which is made available from another chart. }

Variables:
MapID(MapNN.Share(
Text(getsymbolname, "_", NumToStr(barinterval, 0), "_", NumToStr(bartype_ex, 0))
)),
dataKey(0);

// Generate the unique identifier for this bar
if LastBarOnChart_s = true and GetAppInfo(aiRealTimeCalc) = 1 then
dataKey = 123.00000 // keep the data map tidy
else
dataKey = el_datetodatetime(date) + el_timetodatetime_s(time_s) / 10000;

// Get the value from the shared map
value1 = MapNN.Get(MapID, dataKey);

// Plot the retrieved value
Plot1(Value1, "Spread");
You said that the last available price in data 2 will be used.
Is that the last tick in a "open" bar or the last tick in the last closed bar ?
With the default settings, it uses the last tick. I don’t know how that bug that you refer to might impact this.

In the “Send indicator” above, I’ve included a Print() statement which will print data to the PowerLanguage Editor log about which tick and from which time is used. That way you can verify which tick (i.e. how recent) is used in the calculation of the indicator. If that bug that you refer to might impact these calculations, you should be able to see that in the output log.

Btw, you’ll need to comment out that code out or remove it if you don’t want to use it.

Good luck! :)

Regards,
Josh

User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Re: Multiple data indicator

Postby larssan » 12 Oct 2011

Josh,

I've tried it now and it looks perfect! :)

Again, thank you for the time and effort you put in to this.

Regards, Lars

User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Re: Multiple data indicator

Postby larssan » 14 Oct 2011

Josh,

A follow up question, if you have time.

If you would like more values plotted in the indicator like for instance a EMA of "Value1".
How should the Spread Indicator be changed ?

I tried it myself and I can update the "SendSpreadData" code, but I can't figure out how to send the second data to the "SpreadIndicator" and make it plot it.

For example I add a line in your code for calculating the EMA:

Code: Select all

// Calculate the spread
value1 = DataSeries1 / DataSeries2;
AVGvalue1 = XAverage(value1,10); //This data should also be sent and plotted by the indicator.
I'm guessing that you would need a unique MapID and/or dataKey and send it just like value1?

I'm not sure how/what MapID and dataKey does really.

If you can spare the time I would appreciate it.

Cheers, Lars

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Multiple data indicator

Postby JoshM » 14 Oct 2011

Hi Lars,

The short answer:
I'm guessing that you would need a unique MapID and/or dataKey and send it just like value1?
Yes, if you want to put it in a new data map, then you’ll need a unique MapID. The datakey can be reused, since it works as an identifier for that bar.
I'm not sure how/what MapID and dataKey does really.
The MapID variable holds the id for the shared data map. This is needed so that can be specified in which data map the data needs to be saved, otherwise when there are multiple maps, there will be “confusion” between them. The ‘dataKey’ generates a unique number for that bar, so that when the ELCollections look up the data map, they plot the right data belonging to that dataKey.

The long answer:

(Below is the incomplete code from the indicator posted above, that’s to save space and remove the obvious code like “Plot1(value1, “Spread”);” to prevent cluttering this response)

(Btw, I’m no expert and I’ve tried to explain it as I understand it, which is not to mean that everything is correct. )

////////////////////

”SendData” indicator

Code: Select all

Variables:
MapID(MapNN.Share(
Text(getsymbolname, "_", NumToStr(barinterval, 0), "_", NumToStr(bartype_ex, 0))
)),
dataKey(0);

// Generate the unique identifier for this bar
if LastBarOnChart_s = true and GetAppInfo(aiRealTimeCalc) = 1 then
dataKey = 123.00000 // keep the data map tidy
else
dataKey = el_datetodatetime(date Data(1)) + el_timetodatetime_s(time_s Data(1)) / 10000;

// Save the spread in the shared map
value2 = MapNN.Put(MapID, dataKey, value1);
If we now take apart that code in steps..

Code: Select all

Variables:
MapID(MapNN.Share(
Text(getsymbolname, "_", NumToStr(barinterval, 0), "_", NumToStr(bartype_ex, 0))
)),
dataKey(0);
In this part of the SendData indicator, both variables are defined; dataKey initialized to 0 and MapID somewhat different. In fact, three things happen here:

1) First, there is an unique name for the data map generated, by calling..

Code: Select all

Text(getsymbolname, "_", NumToStr(barinterval, 0), "_", NumToStr(bartype_ex, 0))
This creates the string with the unique name for the data map, and for an ES 100 tick chart, this generated string looks like “ES_100_1”, and for an 5 minute EUR/USD chart it will look like “EUR/USD_5_2”. This is done so that you can apply that indicator to multiple instruments, and each will have an unique data map, so there are no conflicts between them. (In other words, this code is a fancy way to generate an unique name).

If you want to make an “EMA data map”, you can use something like..

Code: Select all

Text(“sharedEma_”, getsymbolname, "_", NumToStr(barinterval, 0), "_", NumToStr(bartype_ex, 0))
2) Secondly, in the..

Code: Select all

MapNN.Share( … )
piece of code there is a new data Map made with the unique name. However, since it is a “Share” map, this map can be accessed by other indicators, and before it makes an empty Map with that name, it first looks if there happens to be already such a map with such a name. If not, a new one with the unique name is generated, if yes: the existing map is accessed.

The “MapNN” refers to that this is a data map, consisting of Number to Number, for example, the data map could look like (where “-“ means a tab) :

dataKey - value
1 - 20.25
2 - 20.34
3 - 20.39
4 - 20.31
And so on.

A “MapSN” would consist out of a String to Number, for example:

dataKey - value
“string1” - 20.25
“aString2” - 20.34
“evenMore” - 20.39
“andSoOn” - 20.31

And a “MapSS” would link a String with a String.

So in effect, the whole

Code: Select all

MapNN.Share( … )
code parts tells to the ELCollection:
Make for me a shared data map, where both data columns contain numbers. Ow, and I want to use this string as the unique map name. If you happen to see a shared map with that name, then use that one, else make me a new one.
3. The last part of the ‘Variables:’ code..

Code: Select all

MapID(…)
Contains the numeric map id value so that in the code further in the indicator, this numeric id can be used and the ELCollection then know what kind of map you mean and what the name of that map is. So, this MapID variable just holds the “address” of where we can find this map, if we want to put data in it, or get data from it. (In analogy to Excel, this would be the name of the Excel sheet).


The next part of the SendData indicator code looks like..

Code: Select all

// Generate the unique identifier for this bar
if LastBarOnChart_s = true and GetAppInfo(aiRealTimeCalc) = 1 then
dataKey = 123.00000 // keep the data map tidy
else
dataKey = el_datetodatetime(date Data(1)) + el_timetodatetime_s(time_s Data(1)) / 10000;
Here the variable ‘dataKey’ is assigned an numeric value based on either a fixed value (if the current bar is the last one on the chart) or calculated value based on the date and time_s of the bar (in the other cases).

This ‘dataKey’ ensures that the values on each chart align. In effect, this looks like a “look up” value, just like in a library. For example, if we calculated a spread value of 0.3400 (the book), we calculate with the ‘dataKey’ code an unique place for the spread value (the shelve where we place a book), so that when we later search for the ‘0.3400’ value, we can directly go to the unique place where we saved it (the generated ‘dataKey’ in this example), and pull the data from the data map (get the book from the shelve).

In the code example above, the ‘dataKey’ for the last bar on the chart is not calculated but given a fixed value of 123.00. This is done to prevent that every real-time tick will make an unique “shelve”, and thus giving a very big map.

(Summarized: this ‘dataKey’ code is just a fancy way to determine a bar number. In analogy with Excel, this would be the row number of your Excel sheet).


The last part of the SendData indicator looks like this:

Code: Select all

// Save the spread in the shared map
value2 = MapNN.Put(MapID, dataKey, value1);
This ‘value1’ variable holds the calculated spread, and this is put into the data map by “MapNN.Put”, in which we specify the MapID (i.e. in which map to put), the ‘dataKey’ (i.e. on which row of the data map to put?), and ‘value1’ (which actual value should be saved?). The “MapNN” part means that we use a data map consisting of Number to Number. And the ‘value2’ will hold the result of this “put into”-action (such as error codes).

In continuing the analogy with Excel, this code can be read as:
MapNN.Put(Excel sheet name, row number, value to put into column A);
////////////

The receive data indicator

The receive data indicator looks simplified like..

Code: Select all

Variables:
MapID(MapNN.Share(
Text(getsymbolname, "_", NumToStr(barinterval, 0), "_", NumToStr(bartype_ex, 0))
)),
dataKey(0);

// Generate the unique identifier for this bar
if LastBarOnChart_s = true and GetAppInfo(aiRealTimeCalc) = 1 then
dataKey = 123.00000 // keep the data map tidy
else
dataKey = el_datetodatetime(date) + el_timetodatetime_s(time_s) / 10000;

// Get the value from the shared map
value1 = MapNN.Get(MapID, dataKey);
The first part of this code…

Code: Select all

Variables:
MapID(MapNN.Share(
Text(getsymbolname, "_", NumToStr(barinterval, 0), "_", NumToStr(bartype_ex, 0))
)),
dataKey(0);
Does the same as this part of code in the SendData indicator. Note that here the same unique name is identified; that way this shared map is the same map as used in the SendData indicator, and they can look up data from each other.

The second part of the code..

Code: Select all

if LastBarOnChart_s = true and GetAppInfo(aiRealTimeCalc) = 1 then
dataKey = 123.00000 // keep the data map tidy
else
dataKey = el_datetodatetime(date) + el_timetodatetime_s(time_s) / 10000;
..generates an unique ‘dataKey’ for that bar, so that when this ReceiveData indicator looks up the data put in the map by the SendData indicator, it looks at the correct row and retrieves the accompanying value. In other words, the ‘dataKey’ here is your Excel rownumber, and in the following code the value from column A is pulled:

Code: Select all

// Get the value from the shared map
value1 = MapNN.Get(MapID, dataKey);
Here the variable ‘value1’ is assigned the value corresponding to the MapID (the variable with the numeric value that refers to the shared map) and ‘dataKey’ variable (which holds the row number for that map). In other words:
value1 = MapNN.Get(Excel worksheet name, rownumber);
////////////////

So, if you want to transfer the EMA values the following steps can be taken:

1. The SendData indicator needs a new shared data map, with an unique name, so that it can save the EMA values in that;
2. In the SendData indicator the calculated EMA value needs to be put in that map (but it can use the same dataKey);
3. A new indicator needs to be made in which..
- the shared data map is made in the ‘Variables:’ section (so that this new indicator can access the data with EMA values),
- the shared data map should have the same name as the “EMA data map” in the SendData indicator (so that they can “communicate” with each other),
- the ‘dataKey’ in this new indicator should be calculated in the same way as in the SendData indicator (so that it will look up the correct row when retrieving the EMA values),
- and this indicator needs to pull that EMA value from the map (for example with MapNN.Get(…)), which it then can plot as a line.

(For completeness sake, you can also use a collection of a list combined with a map, see the ELCollections.doc for examples on that, but that’s even more abstract than this way :) )

I hope you made it all to the end of this post and that it helped somewhat, :)

Regards,
Josh

User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Re: Multiple data indicator

Postby larssan » 15 Oct 2011

Thank you very much! :)

No problems at all after your educational explanation.


Regards, Lars


Return to “MultiCharts”