tl_new property question

Questions about MultiCharts and user contributed studies.
paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

tl_new property question

Postby paul.robillard » 26 Nov 2015

Hello,

At first i would have expected that the following code would be seamless in a backtesting pov.

Code: Select all

tl_new(date,900,open,(date+(Next3rdFriday(1))),900,close);
What i expected was that the
1st section ->date,900,open<- would mark the OPEN price of the date at the 1st end of trend line.
2nd section (date+(Next3rdFriday(1))),900,close) to reach the end date, AND point to the END DATE CLOSE price. But NO, as is it marks the end of the begin date close :///

Since then i've been trying to figure how to build the open from the end pov ...

My readings lead to find that if i go on the graph and right click on the trend line i can change it's properties. There an option to point the value to the fixed point close.

Now i figure there must be some way to implement this in coding. As i wish to avoid having to click on 500 trendlines and more coming. Question is which of the tl functions to use and how ?

thank you for your input
Attachments
format_trendlinebox.png
format trend line box
(64.44 KiB) Downloaded 728 times

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

Re: tl_new property question

Postby TJ » 26 Nov 2015

Hello,

At first i would have expected that the following code would be seamless in a backtesting pov.

Code: Select all

tl_new(date,900,open,(date+(Next3rdFriday(1))),900,close);
What i expected was that the
1st section ->date,900,open<- would mark the OPEN price of the date at the 1st end of trend line.
2nd section (date+(Next3rdFriday(1))),900,close) to reach the end date, AND point to the END DATE CLOSE price. But NO, as is it marks the end of the begin date close :///

Since then i've been trying to figure how to build the open from the end pov ...

My readings lead to find that if i go on the graph and right click on the trend line i can change it's properties. There an option to point the value to the fixed point close.

Now i figure there must be some way to implement this in coding. As i wish to avoid having to click on 500 trendlines and more coming. Question is which of the tl functions to use and how ?

thank you for your input
You have to be descriptive and precise in your planning.

What is your chart resolution? Daily? hourly? non-time-based chart?
Each scenario have a different method of attack.

You should develop the habit of drawing a mock up, with arrows and notes highlighting the salient points. It will help you to visualize your idea, and to speed up your planning process.

paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

Re: tl_new property question

Postby paul.robillard » 27 Nov 2015

Hello,

Thanks for replying.



What is your chart resolution? Daily
I am backtesting a option spread strategy. So i need the 1st day of the month and the next3rdfridays to show up on my historic graph. See attachment.

Then i want to draw a trend line :

From the OPEN of the 1st open of the month
To the CLOSE of the 2 following next3rd fridays.

I got around with your help to figure how to draw the white and green vertical lines that mark the IN days and the expiry dates.

Then i figured how to draw trend lines between those open & expiry dates. The problem i am now trying to solve is to make those trendlines draw like they should draw. But for some reason and this is where it gets confusing the expiry price level where the trendline is set is not the close of that day. it is the close of the entry day (1st open day of the month).

Now right clicking on any individual trendlines i get a property window for that trend line (see attach) and i see i can change the calculation type of the trendline. Choosing the Fixed point from default Freestyle does the trick.

My question is how do i set this up so all my trendlines get drawn based on this choice.

Thanks :)
Attachments
format_trendlinebox.png
mock
(206.52 KiB) Downloaded 725 times

paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

Re: tl_new property question

Postby paul.robillard » 27 Nov 2015

See this attachement. I underlined the trend line and it's property box modification i made to get the right result.
Attachments
format_trendlinebox.png
trend line property box
(189.87 KiB) Downloaded 720 times

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

Re: tl_new property question

Postby TJ » 27 Nov 2015

Hello,

At first i would have expected that the following code would be seamless in a backtesting pov.

Code: Select all

tl_new(date,900,open,(date+(Next3rdFriday(1))),900,close);
::
thank you for your input
The first step in programming is to develop good programming habits.
It is most important to make things as simple as possible,
so that you can "see" what you are doing.

I would breakdown your code in the following manner:

Code: Select all


var:
start.date(0), start.time(0), start.price(0),
end.date(0), end.time(0), end.price(0);

start.date = date;
start.time = 900;
start.price = open;

end.date = date + ( Next3rdFriday(1) );
end.time = 900;
end.price = close;

tl_new( start.date, start.time, start.price, end.date, end.time, end.price);

paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

Re: tl_new property question

Postby paul.robillard » 27 Nov 2015

Wow much cleaner indeed. I will certainly keep your coding indications in mind.

Unfortunatly I did that the results are the same. Somehow i am failing to expose my problem ://

Even tough i am

Code: Select all

start.date = date;
start.time = 900;
start.price = open;

end.date = date + ( Next3rdFriday(1) );
end.time = 900;
end.price = close;

tl_new( start.date, start.time, start.price, end.date, end.time, end.price);
the
end.price is not the end.date end.price close
but rather the
start.date end.price is returned.

There some MC global configuration fix to make or TL_setting missing.

If you look at the PNG i sent you will see 2 RED TL starting at 1st day of month and each reaching out to the 2 next expiries. They should end at the CLOSE of those EXPIRY DATES, but if you look closely you will see they are actually at the level of the 1st day CLOSE.

I will post the whole code in my next reply.

Thanks for your time.

paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

Re: tl_new property question

Postby paul.robillard » 27 Nov 2015

Code: Select all

variables:
txtID (0),
TLID (0),
TLID1(0),
TLID2(0);

var:
start.date(0), start.time(0), start.price(0),
end.date1(0), end.time1(0), end.price1(0),
end.date2(0), end.time2(0), end.price2(0);

start.date = date;
start.time = 900;
start.price = open;

end.date1 = date + ( Next3rdFriday(1) );
end.time1 = 900;
end.price1 = close;

end.date2 = date + ( Next3rdFriday(2) );
end.time2 = 900;
end.price2 = close;

once cleardebug;

////////////////
//THIRD FRIDAYs
///////////////

if Next3rdFriday(0)=0 and Next3rdFriday(0)[1]<>0 then
begin
TLID =
tl_new(date,900,0,date,900,low-100);
tl_SetColor(TLID, green);
tl_setstyle(TLID, 1);
end;


/////////////////////////////////////////////////////////////////////
// FIRST OF THE MONTH
/////////////////////////////////////////////////////////////////////

if month(date) <> month(Date[1])then
begin
//////////////////////////////////
// vertical 1st open day of month
//////////////////////////////////
TLID =
tl_new(date,900,0,date,900,low-100);
tl_SetColor(TLID, white);
tl_setstyle(TLID, 1);

///////////////////////////////////////////////////////////////////////////////
// trend lines from 1st of month to next expiry for specific months of the year
///////////////////////////////////////////////////////////////////////////////

if month(date)= 12 or
month(date)= 1 or
month(date)= 2 or
month(date)= 3 or
month(date)= 8 or
month(date)= 9 or
month(date)= 10 then


////////////////////////////
// 1st TL to nearest expiry
////////////////////////////

TLID1 =
tl_new( start.date, start.time, start.price, end.date1, end.time1, end.price1);
//Value1 = TL_GetActive;
//TL_SetEnd (Value1, (tday+(Next3rdFriday(1))), 1600, close);
//print(Value1," TLID1");
tl_SetColor(TLID1, red);
tl_setstyle(TLID1, 1);



////////////////////////////////
// 2nd TL to 2nd nearest expiry
////////////////////////////////

TLID2 =
tl_new( start.date, start.time, start.price, end.date2, end.time2, end.price2);
// tl_new(tday,900,open,(tday+(Next3rdFriday(2))),900,close);
//Value2 = TL_GetActive;
//print(Value2," num de la t2");
//TL_SetEnd (Value2, (tday+(Next3rdFriday(1))), 1600, close);
tl_SetColor(TLID2, red);
tl_setstyle(TLID2, 1);



end;


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

Re: tl_new property question

Postby TJ » 27 Nov 2015

EasyLanguage is a Procedural Language.

ie. the computer will read and process your code in a step-by-step manner.

MultiCharts will jump into action ONCE a tick is arrived at your computer.
MultiCharts will read the code line-by-line from the top to the bottom,
and execute any instructions that meet your criteria.

ie. if you have an instruction that says:

Code: Select all

if month(date) = 12 then
TLID1 = tl_new( start.date, start.time, start.price, end.date1, end.time1, end.price1);
MultiCharts will execute this line of code if and only if month(date)=12.

At the time of executing the TL, if the "end.price1"=100, then that value will stay with the line until the bitter end.

...unless you instruct it again otherwise.

paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

Re: tl_new property question

Postby paul.robillard » 27 Nov 2015

ok let me try to ask this then.

how would i code to print in the output the close of the end.date1 ?

Code: Select all

print(end.date1(close));


if i may express my need this way.

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

Re: tl_new property question

Postby TJ » 27 Nov 2015

ok let me try to ask this then.

how would i code to print in the output the close of the end.date1 ?

Code: Select all

print(end.date1(close));


if i may express my need this way.

Code: Select all


print( end.date1 );

paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

Re: tl_new property question

Postby paul.robillard » 27 Nov 2015

Hmm. Are you sure this would print the CLOSE price of end.date1 ?

I think it will print only the date !

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

Re: tl_new property question

Postby TJ » 27 Nov 2015

Hmm. Are you sure this would print the CLOSE price of end.date1 ?

I think it will print only the date !
Then substitue the variable with "end.price1".


Your question is not complete. We are dealing with a moving target. You have to determine at which point in time you are looking for this "close price".

paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

Re: tl_new property question

Postby paul.robillard » 28 Nov 2015

I am sure part of my issue comes from my logic is not in synch with Power Language logic (hopefully just yet).

But just to check i got this right :

Each bar processes the whole code from top to bottom. Am i right ?

If i am right, then am i right to assume that in the code section where i figure out & then draw the last 3rd fridays verticals if i set the value of end.price1 at that point in the code the value will be :
1. equal to the close of the next3rdfriday
2. this value should remain at least until it the whole code is processed again, next bar

At this point I feel like a dog running in circles trying to bite his own tail :/

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

Re: tl_new property question

Postby TJ » 28 Nov 2015

::

At this point I feel like a dog running in circles trying to bite his own tail :/
That's why it is so important to draw a mock up chart,
with all the values of the variables identified at each turning point.

You should also draw 2 more mock ups,
one at the end of the TL,
and one in between.

Once you have done that,
you will see the big picture.


Return to “MultiCharts”