ELCollections questions

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

ELCollections questions

Postby arjfca » 06 Jul 2011

Hello again, Another esoteric question for me this morning

A little code read a string within a text file. It then store the value in a variable.

Code: Select all

If lastbaronchart then
begin
value1 = ListS.Readfile(listid,"f:\temp\TestData\CSVData.Txt");
TextFile = Lists.Get(ListID,1);
Print (textFile);
end;
Problem: While my indicator is running, if I modify some value in my text file, these one are not reflected in the print command, Print(TextFile); New value will be display only after I turned off then turn on the indicator.

I did try with or without the command line <<If LastBarOnTheChart then Begin >>, same result

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

Re: Reading an updated file... No modification

Postby JoshM » 07 Jul 2011

[..]
Problem: While my indicator is running, if I modify some value in my text file, these one are not reflected in the print command, Print(TextFile); New value will be display only after I turned off then turn on the indicator.
[..]
Haven't worked with the type of situation you describe, but if I make some modest suggestions (probably you've already tried them):

- Do you keep the text file open after modifying these values? As you describe it, MC seems to access and older (temporary) version of the file, since it doesn't has access (any more) to the current version.
- Perhaps two lists could work? One for reading, then copying to second list, then forcing ELCollections to release (see List.Release()) the first list (and thus removing the lock from the file), and then making a new connection with list one to the text file, to get the newest version.
Normally you don’t have to worry about cleaning up collections yourself: the ELCollections utility will do it for you automatically when a study or strategy is unloaded. However, there may be times when you want to create a temporary collection, do some work with it, and then delete it to save memory. You can do this with the Release function:

Value1 = ListX.Release(ID) or
Value1 = MapXY.Release(ID)

If you release a local collection (created with New), it will be deleted immediately. If you release a shared collection (created with Share), it will be deleted only when it has been released by all studies and strategies that use it.
New value will be display only after I turned off then turn on the indicator.
Hope I said something useful. ;)

Regards,
Josh

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Reading an updated file... No modification

Postby arjfca » 07 Jul 2011

Thank you JoshM
Normally you don’t have to worry about cleaning up collections yourself: the ELCollections utility will do it for you automatically when a study or strategy is unloaded. However, there may be times when you want to create a temporary collection, do some work with it, and then delete it to save memory. You can do this with the Release function:

Value1 = ListX.Release(ID) or
Value1 = MapXY.Release(ID)
I did not take care of that

Is it a good manner to close a collection after each lecture?

Also, I will implant a timer delay to prevent an overuse of the drive and memory. I think a reading every 200 ms up to 500 ms could be sufficient.

Martin

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

Re: Reading an updated file... No modification

Postby JoshM » 07 Jul 2011

[..]
Is it a good manner to close a collection after each lecture?
[..]
Normally this is done implicitly by the program/code itself, so you don't have to make it explicit. However, since your code is in the LastBarOnChart (and thus with real-time data always active) it might be that the ELCollection doesn't make a new connection to your changed file but keep the current one open without reloading it (probably since the connection and the contents of the file are already in the memory). But I'm mostly just assuming since I can't look into the ELCollection file (and am no expert :)). Perhaps TJ or Bowlesj3 can shed some light on it. :)

I don't think this will be a serious memory consumption, since you won't be doing it continuously.

Let us know if closing the collection works. :)

Regards,
Josh

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Reading an updated file... No modification

Postby arjfca » 07 Jul 2011

Hello Josh

Actually, went I tried to use the release command, i received a failure message and the signal close.
Maybe I don't call it in a proper manner

Code: Select all

VAR:ListID(ListS.New);
value1 = ListS.Readfile(listid,"f:\temp\TestData\DataReady.Txt");
TextFile = Lists.Get(ListID,1);
Value1 = ListS.Release(listid) ;
After some test, I realised that by releasing it, I was killing the value of the variable ListID that was set in the variables section

I changed my code to declare the value of ListID inside my code instead of using a variable value

Code: Select all

VAR: ListID (0);
ListID=(ListS.New);
value1 = ListS.Readfile(listid,"f:\temp\TestData\DataReady.Txt");
TextFile = Lists.Get(ListID,1);
Value1 = ListS.Release(listid) ;
I don't think this will be a serious memory consumption, since you won't be doing it continuously.
Indeed it could be a problem because this is going to be read in a loop. My project is to scan Texts Files for new information. These info will be trade order parameters that will have been sent via Excel. There will be a constant communication between MC and Excel, one speaking to the other via Text files and direct access to Excel cells using XLInputs http://shop.qclsolutions.com/XLInputs-101.htm

I will work on a comparative test using a delay.

Last night i was able to modify the text files and see the modification in the MC print out. Only problem is it was not a direct sight. I was seeing the modification after 5 to 10 secondes. My theories is that since the lectures is done in a loop, I'm over saturated the print out memory allocation. It cant' display as fast as the modification are done and while I was thinking that the system was not reading new data, he was only displaying the information's that he was not fast enough to show. Hence the delay in the print out and the wrong assumption that my code was not working.

I will keep in touch

User avatar
Lobo.Trader
Posts: 12
Joined: 26 Nov 2011
Location: Germany
Has thanked: 19 times
Been thanked: 6 times

EL Collections Error // "There is no collection with that ID

Postby Lobo.Trader » 25 Jan 2012

Hello

following code generating "There is no collection with that ID" - error :

Code: Select all

Inputs: FileName ( "C:\ADE\Data\My_Test.txt" ) ;

Vars: DataMap(ListN.New),
code(0),
x(0);


if CurrentBar > 1 then begin
if ELC.PathExists(FileName) then begin
value1 = ListN.ReadFile(DataMap, FileName);

// Check map count in case file was empty
if ListN.Count(DataMap) > 1 then begin
code = ListN.Get(DataMap,1);
end;


value3 = ListN.Get(code, 1);


X = text_new(d,t,c[1],"");

If lastbaronchart then
Text_setstring(x, numtostr(value3,0));
end
else print ("File does not exist");
end;
Task of code is only to load content of My_Test. Me wanting to learn functionality .

Checked multiple times location of file and is OK. Format is ".txt" .
Content of File is 11111 (5 times number "1" ) .

Thx

Lobo
Attachments
ELError.png
(6.71 KiB) Downloaded 5389 times

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

Re: Reading an updated file... No modification

Postby TJ » 25 Jan 2012

the problem is in this line:

value3 = ListN.Get(code, 1);



"code" is not a declared list.

if you are copying the example from the ELC document,
it was a comma delimited ListC extracted into 4 new lists.
While in your case, you only have one ListN.

User avatar
Lobo.Trader
Posts: 12
Joined: 26 Nov 2011
Location: Germany
Has thanked: 19 times
Been thanked: 6 times

Re: ELCollections questions

Postby Lobo.Trader » 26 Jan 2012

Hello , a bit of follow up at your convenience =>

Code: Select all

Inputs: FileName ( "C:\ADE\Data\My_Memory.txt" );// File location

Vars: DataMap(ListN.New) ,// Create List of numeric values named "Datamap"
Ergebnis (0) ,// Variable for the content || result
Counter(0) ;// just to count up

Counter = Counter+1 ;// Barcounter one up (for debugg only)

if CurrentBar > 1 then begin // all bars in chart but the current
if ELC.PathExists(FileName) then begin // in case file is found
value1 = ListN.ReadFile(DataMap, FileName);// read file into list "DataMap"
Ergebnis = ListN.Get(DataMap,1) ;// pick first data in list and make it Ergebnis
Print (Counter, " Gefunden = ",Ergebnis);// print it for debugging only
end //
else //
print ( Counter , "Kein File vorhanden") ;// File not found
end ;//
value1 = ListN.Clear(DataMap) ;// Clear List and free memory
@TJ and all : I now have code which works fine for me . It now will be easy to extend .

Thank´s to TJ once again .

Lobo

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

Re: ELCollections questions

Postby TJ » 26 Jan 2012

Hello , a bit of follow up at your convenience =>
...

@TJ and all : I now have code which works fine for me . It now will be easy to extend .

Thank´s to TJ once again .

Lobo
You are welcome!

Thanks for the follow up.

TJ


Return to “User Contributed Studies and Indicator Library”