Horizontal Trend Line for Session Time  [SOLVED]

Questions about MultiCharts and user contributed studies.
brunor
Posts: 65
Joined: 11 Feb 2013
Has thanked: 24 times
Been thanked: 6 times

Horizontal Trend Line for Session Time

Postby brunor » 14 Feb 2020

I found this code online years ago to plot a price line ... works very well. I have modified it slightly to plot a horizontal trend line for the current session but can't define the current session. I would like the horizontal trend line to consider prices starting at 9:30am for the current session. It works if I use a custom session template beginning at 9:30am ... if I use a default (full) session for emini futures it plots the line based on the entire session.
Any assistance would be greatly appreciated.
Bruno

Code: Select all

Input: LineStyle(3), LineSize(0.5), LineColor(rgb(90,90,90)), ExtLeft(false), BeginTL(930), SessionBeginTime(930); var: intrabarpersist need_delete_this_bar(false), Lo(0); Lo = Lows(0); if lastbaronchart and sessionstarttime(1,1) >= SessionBeginTime then begin value10 = TL_New(date, time, hi, date, time, hi); value1 = TL_SetBegin(value10,date,BeginTL, hi); Value1 = TL_SetColor (value10, LineColor); value1 = TL_SetExtRight (value10, true); value1 = TL_SetExtLeft (value10, ExtLeft); value1 = TL_setsize (value10, LineSize); value1 = TL_Setstyle (value10, LineStyle); need_delete_this_bar = not need_delete_this_bar and value10[1] > 0 AND value10 <> value10[1]; value11 = tl_getfirst(1); if tl_getnext(value11, 1) > 0 and need_delete_this_bar then value1 = TL_Delete(value11); if barstatus = 2 then need_delete_this_bar = false; end;

brunor
Posts: 65
Joined: 11 Feb 2013
Has thanked: 24 times
Been thanked: 6 times

Re: Horizontal Trend Line for Session Time

Postby brunor » 19 Feb 2020

Figured out a simple solution:
1) insert Data 1 as symbol with default session
2) insert Data 2 (same symbol as Data 1) as symbol with custom session template ... use invisible bars as the style setting
3) format the indicator to base study on Data 2

The horizontal trend line will be plotted onto your default session, based on data from your custom session.

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

Re: Horizontal Trend Line for Session Time

Postby TJ » 19 Feb 2020

Try this:

Code: Select all

var: HorLine(-1); If TIME = SessionStartTime(1,1) then begin TL.price = H; HorLine = TL_New( date, time, TL.price, date, time, TL.price); TL_SetColor ( HorLine, LineColor); TL_setsize ( HorLine, LineSize); TL_Setstyle ( HorLine, LineStyle); TL_SetExtRight ( HorLine, true); end; If TIME = SessionEndTime(1,1) then begin TL_SetExtRight ( HorLine, false); TL_SetEnd ( HorLine, date, time, TL.price); end;

brunor
Posts: 65
Joined: 11 Feb 2013
Has thanked: 24 times
Been thanked: 6 times

Re: Horizontal Trend Line for Session Time

Postby brunor » 20 Feb 2020

Hi TJ.
Nothing plots with this code on a default session for SP500 emini ... I added "TL.Price" as a variable.
No plot with custom session template either ... custom template begins at 9:30am and ends at 16:15.
Appreciate your help.

Code: Select all

Input: LineStyle(3), LineSize(0.5), LineColor(rgb(90,90,90)); var: HorLine(-1), TL.Price(H); If TIME = SessionStartTime(1,1) then begin TL.price = H; HorLine = TL_New( date, time, TL.price, date, time, TL.price); TL_SetColor ( HorLine, LineColor); TL_setsize ( HorLine, LineSize); TL_Setstyle ( HorLine, LineStyle); TL_SetExtRight ( HorLine, true); end; If TIME = SessionEndTime(1,1) then begin TL_SetExtRight ( HorLine, false); TL_SetEnd ( HorLine, date, time, TL.price); end;

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

Re: Horizontal Trend Line for Session Time  [SOLVED]

Postby TJ » 20 Feb 2020

Go to the Wiki,
See : 8 PowerLanguage Keyword Reference
Look under : Sessions‎ (18 P)

You can choose one of the session times that fits your application.
Or, you can hard code the time into your script.

brunor
Posts: 65
Joined: 11 Feb 2013
Has thanked: 24 times
Been thanked: 6 times

Re: Horizontal Trend Line for Session Time

Postby brunor » 20 Feb 2020

I'm grateful for your help.
I'll have to spend a little time working on it.

Bruno

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: Horizontal Trend Line for Session Time

Postby Anna MultiCharts » 28 Feb 2020

Hello brunor,

Considering that you modified the code and we cannot know what was done exactly, we can only assume that some parts of your code still remain excessive. We’d suggest adding the time check conditions in the beginning of the script:

Code: Select all

if time >= StartDrawingTime then
For the drawings to be plotted after a certain time with no respect to the sessions try this:

Code: Select all

Input: LineStyle(3), LineSize(0.5), LineColor(rgb(90,90,90)), ExtLeft(false); //BeginTL(930); //Add code //SessionBeginTime(930); //Add code Input: StartDrawingTime(0930); //Add code var: intrabarpersist need_delete_this_bar(false), Lo(0), Hi(0); //Add code Lo = Lows(0); hi = Highs(0); //Add code if time >= StartDrawingTime then begin if lastbaronchart {and sessionstarttime(1,1) >= SessionBeginTime} then //Add code print(sessionstarttime(1,1)); begin value10 = TL_New(date, time, hi, date, time, hi); value1 = TL_SetBegin(value10,date,StartDrawingTime, hi); //Add code Value1 = TL_SetColor(value10, LineColor); value1 = TL_SetExtRight(value10, true); value1 = TL_SetExtLeft(value10, ExtLeft); value1 = TL_setsize(value10, LineSize); value1 = TL_Setstyle(value10, LineStyle); need_delete_this_bar = (not need_delete_this_bar) and (value10[1] > 0) AND (value10 <> value10[1]); value11 = tl_getfirst(1); if (tl_getnext(value11, 1) > 0) and (need_delete_this_bar) then begin value1 = TL_Delete(value11); end; if (barstatus = 2) then begin need_delete_this_bar = false; end; end; end;

brunor
Posts: 65
Joined: 11 Feb 2013
Has thanked: 24 times
Been thanked: 6 times

Re: Horizontal Trend Line for Session Time

Postby brunor » 28 Feb 2020

Thank you Anna ... I will have a look when I get the chance.


Return to “MultiCharts”