Can we delete a TL using an IF ?  [SOLVED]

Questions about MultiCharts and user contributed studies.
Automeq
Posts: 105
Joined: 16 Apr 2014
Has thanked: 15 times
Been thanked: 1 time

Can we delete a TL using an IF ?

Postby Automeq » 31 Aug 2016

The objective is to have intraday a vertical trendline with the daily range. I tried 2 options but only the second one worked.

First Option: Code analyses if this bar is a new day. If so, it would delete the TL. This is not working.

Code: Select all

if dayofmonth(date)<>dayofmonth(date)[1] then begin
TL_delete(Value1);
end;

value1=TL_new(CurrentDate,2300,HighD(0),CurrentDate,2300,LowD(0));
Apparently MC is drawing a TL from the lowest value ever to the highest value ever. I suspect that it is drawing the daily TLs since the beginning of the quotes, without deleting any of them (which means they are all overlapping). I was trying to understand why this first option is not working.
Option1.PNG
(224.61 KiB) Downloaded 748 times
Second Option: The simple approach, deleting the TL every bar and draw it again.

Code: Select all

TL_delete(Value1);
value1=TL_new(CurrentDate,2300,HighD(0),CurrentDate,2300,LowD(0));
This works well.
Option2.PNG
(153.51 KiB) Downloaded 748 times
Another question: is it possible to have the TL identified with something other than value1 ? I would prefer to have DailyRangeTL for example.

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

Re: Can we delete a TL using an IF ?

Postby TJ » 31 Aug 2016

::

Another question: is it possible to have the TL identified with something other than value1 ? I would prefer to have DailyRangeTL for example.

Actually, you SHOULD always have the TL identified with something other than value1.

Value1 is only an example for illustration purposes in the manual.

All variables should have its own easily identifiable unique name.

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

Re: Can we delete a TL using an IF ?

Postby TJ » 31 Aug 2016

::
Apparently MC is drawing a TL from the lowest value ever to the highest value ever.
::
A TL is drawn from left to right, bottom to top.

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

Re: Can we delete a TL using an IF ?

Postby TJ » 31 Aug 2016

The objective is to have intraday a vertical trendline with the daily range. I tried 2 options but only the second one worked.

First Option: Code analyses if this bar is a new day. If so, it would delete the TL. This is not working.

Code: Select all

if dayofmonth(date)<>dayofmonth(date)[1] then begin
TL_delete(Value1);
end;

value1=TL_new(CurrentDate,2300,HighD(0),CurrentDate,2300,LowD(0));
::
Try this

Code: Select all


DailyRangeTL = TL_new( Date, time, LowD(0), Date, time, HighD(0) );

if dayofmonth(date) = dayofmonth(date)[1] then
begin

TL_delete( DailyRangeTL[1] );

end;

Automeq
Posts: 105
Joined: 16 Apr 2014
Has thanked: 15 times
Been thanked: 1 time

Re: Can we delete a TL using an IF ?

Postby Automeq » 31 Aug 2016

Thanks for that TJ.

That code is going to draw a vertical TL each day but I just wanted one TL (only today). I don't want to populate the past data (this was not clear in my initial post).

I guess this is the simpler way ?

Code: Select all

variables:
DailyRangeTL(0);

TL_delete( DailyRangeTL[1] );

DailyRangeTL = TL_new( Date, 2300, LowD(0), Date, 2300, HighD(0) );

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

Re: Can we delete a TL using an IF ?  [SOLVED]

Postby TJ » 31 Aug 2016

Thanks for that TJ.

That code is going to draw a vertical TL each day but I just wanted one TL (only today). I don't want to populate the past data (this was not clear in my initial post).

I guess this is the simpler way ?

Code: Select all

variables:
DailyRangeTL(0);

TL_delete( DailyRangeTL[1] );

DailyRangeTL = TL_new( Date, 2300, LowD(0), Date, 2300, HighD(0) );

Yes that would work.

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Can we delete a TL using an IF ?

Postby bensat » 01 Sep 2016

If you would like to run a script for the current day only, I would recommend to declare it via ...

Code: Select all

variables:
DailyRangeTL(0);

if date = currentdate then
begin
DailyRangeTL = TL_new( date, 2300, LowD(0), date,2300, HighD(0) );
end;

Kind Regards.

Ben


Return to “MultiCharts”