TL_new, TL_delete, TL_lock

Questions about MultiCharts and user contributed studies.
kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

TL_new, TL_delete, TL_lock

Postby kernel » 19 Apr 2015

Hi,

I have problem dealing with the set of TL_XXX functions. I'd like to update a horizontal line tick by tick (with IntrabarOrderGeneration ON), with code snippet as follows:

Code: Select all

[IntrabarOrderGeneration = TRUE]
if TL_Exist(value1) then
tl_delete(value1);

value1=tl_new(d,t,H,d,t,H);
tl_setextright(value1,true);
tl_lock(value1,true);
However, the line disappears after a while. In addition, is tl_lock() necessary in here? what's it used for after all? thanks.

-K

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: TL_new, TL_delete, TL_lock

Postby kernel » 19 Apr 2015

it turned out to be that, this part of the code works fine.

However, the tl_new() function returns some value that already exist returned by other tl_new() function call.

So it boils down to the question:

Does tl_new() guarantee to return a UNIQUE value every time it gets called? If not, then problem occurs. How can you fix this?

Imagine in a situation that multiple TLs are generated and deleted dynamically from time to time, how can you make sure each TL has its own unique ID (handle) is crucial. How do you implement this in MC in such a way that the uniqueness of each TL's ID is guaranteed?

thanks.

-K

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

Re: TL_new, TL_delete, TL_lock

Postby TJ » 19 Apr 2015

it turned out to be that, this part of the code works fine.
However, the tl_new() function returns some value that already exist returned by other tl_new() function call.
So it boils down to the question:
Does tl_new() guarantee to return a UNIQUE value every time it gets called? If not, then problem occurs. How can you fix this?
Imagine in a situation that multiple TLs are generated and deleted dynamically from time to time, how can you make sure each TL has its own unique ID (handle) is crucial. How do you implement this in MC?
thanks.
-K
The problem is in your code.

I can say that because the problem you described is a simple one,
if it were a bug, it would have been discovered long ago.
Thousands of people uses drawing objects everyday with no problem.
I would recommend you to review your codes again line by line,
and to reduce complexity wherever possible.

ps. good coding habit helps too.

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: TL_new, TL_delete, TL_lock

Postby kernel » 19 Apr 2015

The problem is in your code.

I can say that because the problem you described is a simple one,
if it were a bug, it would have been discovered long ago.
Thousands of people uses drawing objects everyday with no problem.
I would recommend you to review your codes again line by line,
and to reduce complexity wherever possible.

ps. good coding habit helps too.
now it's getting clearer:
it seems that when you call tl_new() twice:
value1=tl_new();
value2=tl_new();
then call tl_delete(value1) once, after this, the value2 decrements automatically by 1....since the return value serves as the handle to the object, that automatic decrement causes problem: you lose the handle to that specific object.

I tried to put a line of tl_lock(value2,true) after value2=tl_new(), but that does not lock the value2.

-k

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: TL_new, TL_delete, TL_lock

Postby ABC » 20 Apr 2015

Hi kernel,

instead of constantly deleting and redrawing a trendline, you might want to consider drawing it only once and then just updating its start and end points with every tick. This is not only simpler it is more resource friendly, too.

Regarding TL_Lock: https://www.multicharts.com/trading-sof ... hp/Tl_lock
It basically gives the ability to prevent manual moving of the trendline.

Regards,
ABC

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: TL_new, TL_delete, TL_lock

Postby kernel » 20 Apr 2015

Hi ABC,

I agree with you on that, updating the trendline (horizontal line in my case) tick by tick is the better way to go. I did exactly that at first with tl_setbegin/tl_setend pair, but encountered similar problem. Back then I wasn't aware of the root cause of the problem, so I tried a different approach, and wound up with the solution now: repeatedly deleting the old and creating the new...and unfortunately, problems of the same nature occurred, it didn't work out.

Then I stripped the code to the core and finally figured out it's the bizarre behavior of tl_new, text_new object creating functions, especially used when IntrabarOrderGeneration set to ON, in particular, their elusive returned values (the handle to objects) that were the root cause of the problem....they are elusive and changing, so you grab the wrong handle and end up deleting the wrong object.

I realized that I was wrong on the tl_lock. It does not lock or glue the ID (the return value) to that specific object, no wonder it did not do the trick "locking the handle/ID". Basically it's not needed in my case.

-K

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

Re: TL_new, TL_delete, TL_lock

Postby Henry MultiСharts » 29 Apr 2015

now it's getting clearer:
it seems that when you call tl_new() twice:
value1=tl_new();
value2=tl_new();
then call tl_delete(value1) once, after this, the value2 decrements automatically by 1....since the return value serves as the handle to the object, that automatic decrement causes problem: you lose the handle to that specific object.

I tried to put a line of tl_lock(value2,true) after value2=tl_new(), but that does not lock the value2.

-k
Hello Kernel,

Tl_new assigns any free ID when you create a new object. If you have deleted the trendline with ID=1 and then created a new object, it will receive ID = 1.

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

Re: TL_new, TL_delete, TL_lock

Postby furytrader » 29 Apr 2015

Correct me if I'm wrong though - if you delete a trendline, that shouldn't change the ID of trendlines that were created earlier and continue to exist?

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

Re: TL_new, TL_delete, TL_lock

Postby Henry MultiСharts » 01 May 2015

Correct me if I'm wrong though - if you delete a trendline, that shouldn't change the ID of trendlines that were created earlier and continue to exist?
furytrader, deleting a trendline does not change the ID of trendlines that were created earlier and continue to exist.


Return to “MultiCharts”