Price line

Questions about MultiCharts and user contributed studies.
seneca
Posts: 97
Joined: 02 Apr 2012
Has thanked: 38 times
Been thanked: 22 times

Price line

Postby seneca » 11 Feb 2014

I use the code below (I found it some time ago somewhere in this forum and customized it slightly) to display a horizontal price line which updates on each tick, see the yellow line in attached picture.

Code: Select all

vars:
intrabarpersist need_delete_this_bar(false),
priceline(-1),
tl_first(-1),
pl_attr(-1),
line_color(RGB(230,240,80));

if lastbaronchart and bartype_ex is = 2 then begin

priceline = TL_New(date, time-2400, close, date, time, close);
pl_attr= TL_SetColor (priceline , line_color);
pl_attr= TL_SetExtRight (priceline , true);
{pl_attr = TL_SetExtLeft (priceline , false); } // toggles SetExtLeft
pl_attr= TL_setsize (priceline , 1);
pl_attr= TL_Setstyle (priceline , 2);
pl_attr= TL_Lock (priceline , true);

need_delete_this_bar = not need_delete_this_bar and priceline [1] > 0 AND priceline <> priceline [1];

tl_first = tl_getfirst(1);

if tl_getnext(tl_first, 1) > 0 and need_delete_this_bar then pl_attr = TL_Delete(tl_first);
if barstatus = 2 then need_delete_this_bar = false;

end;
The drawback is that this code consumes quite a lot of computing resources, so if I run this code on a big number of chart windows MC becomes noticeably slower. I wonder if there is a way to improve it for more efficiency, or, which would be even better, if the price line feature could be integrated in MC. I think displaying a price line is pretty much industry standard.
Attachments
price_line.jpg
(1.41 MiB) Downloaded 1637 times

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: Price line

Postby arnie » 11 Feb 2014

See if this suits your needs

viewtopic.php?f=5&t=11658

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Price line

Postby MAtricks » 11 Feb 2014

A horizontal line drawn through the chart is fairly standard.. It would be a simple thing to add for MC.

This should be faster...

Code: Select all


//ShowText to False to speed it up a bit
//Format the indicator once its on the chart and set it to HIDDEN
//Make sure the indicator is set to UPDATE ON EACH TICK

inputs:
ShowPriceLine( True ),
LineColor( DarkGray ),
LineStyle( Tool_Dashed3 ), //Tool_Solid, Tool_Dotted, Tool_Dashed, Tool_Dashed2, Tool_Dashed3
ShowText( True ),
TextColor( RGB(255,104,32) ), //RGB(xxx,xxx,xxx) or Color Name eg: Red
TextSize( 14 ),
TextShiftUp( 2 ) ; //Plot Price Text this amount of ticks up from Close price

variables:
TL_ID( 0 ),
int NumDecimals( 0 ),
Text_ID( 0 ) ;

if Category = 12 then
NumDecimals = Log( PriceScale ) / Log( 10 ) - 1
else
NumDecimals = Log( PriceScale ) / Log( 10 ) ;

if CurrentBar = 1 and ShowPriceLine then begin
TL_ID = TL_New( D, T, C, D, T, C ) ;
TL_SetColor( TL_ID, LineColor ) ;
TL_SetStyle( TL_ID, LineStyle ) ;
TL_SetSize( TL_ID, 0 ) ;
TL_SetExtRight( TL_ID, True ) ;
TL_SetExtLeft( TL_ID, True ) ;
TL_SetColor( TL_ID, LineColor ) ;
Text_ID = Text_New( D, T, C, NumToStr( C, NumDecimals ) ) ;
end ;

TL_SetEnd( TL_ID, D, T, C );
TL_SetBegin( TL_ID, D, T, C );

if ShowText then begin
Text_SetLocation( Text_ID, D, T, C+ TextShiftUp ) ;
Text_SetColor( Text_ID, TextColor ) ;
Text_SetSize( Text_ID, TextSize ) ;
Text_SetString( Text_ID, Spaces( 0 ) + NumToStr( C, NumDecimals ) ) ;
Text_SetStyle( Text_ID, 0, 1 ) ;
end ;
Image

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

Re: Price line

Postby arjfca » 12 Feb 2014

I use the code below (I found it some time ago somewhere in this forum and customized it slightly) to display a horizontal price line which updates on each tick, see the yellow line in attached picture.

Code: Select all

vars:
intrabarpersist need_delete_this_bar(false),
priceline(-1),
tl_first(-1),
pl_attr(-1),
line_color(RGB(230,240,80));

if lastbaronchart and bartype_ex is = 2 then begin

priceline = TL_New(date, time-2400, close, date, time, close);
pl_attr= TL_SetColor (priceline , line_color);
pl_attr= TL_SetExtRight (priceline , true);
{pl_attr = TL_SetExtLeft (priceline , false); } // toggles SetExtLeft
pl_attr= TL_setsize (priceline , 1);
pl_attr= TL_Setstyle (priceline , 2);
pl_attr= TL_Lock (priceline , true);

need_delete_this_bar = not need_delete_this_bar and priceline [1] > 0 AND priceline <> priceline [1];

tl_first = tl_getfirst(1);

if tl_getnext(tl_first, 1) > 0 and need_delete_this_bar then pl_attr = TL_Delete(tl_first);
if barstatus = 2 then need_delete_this_bar = false;

end;
The drawback is that this code consumes quite a lot of computing resources, so if I run this code on a big number of chart windows MC becomes noticeably slower. I wonder if there is a way to improve it for more efficiency, or, which would be even better, if the price line feature could be integrated in MC. I think displaying a price line is pretty much industry standard.
Best way to lower the memory consumption is to lower the numbers of bars display. If you use a very low time frame and a starting date away from the actual day, you may get the low memory problem

Also, for your very low time scale charts, try to use one charts per MC instance

Good luck

N.B.
What is the news indicator that your are using. seems interesting

Martin

seneca
Posts: 97
Joined: 02 Apr 2012
Has thanked: 38 times
Been thanked: 22 times

Re: Price line

Postby seneca » 12 Feb 2014

arnie, MAtricks, thanks for the codes posted above. Although the codes work great, they still consume some noticeable amount of computing resources.
A horizontal line drawn through the chart is fairly standard.. It would be a simple thing to add for MC.
Absolutely. As we already have the price marker with countdown on the y-axis, adding an option for a horizontal line should be a no-brainer and should be quite easy to implement.

@MC team: What do you think?
N.B.
What is the news indicator that your are using. seems interesting
This is the Economic Events Collection which JoshM posted on this forum. Really a great contribution to MC. You can find it in the User contributed Studies section:
http://www.multicharts.com/discussion/v ... f=5&t=9951

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Price line

Postby MAtricks » 12 Feb 2014

Have you tried my code? All others seem to really bog my charts down, but that one was the ticket.

Totally agree that this should be a platform feature that we can turn off or on and that's updated every TICK. The trendlines have a slight lag in them...

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

Re: Price line

Postby TJ » 12 Feb 2014

arnie, MAtricks, thanks for the codes posted above. Although the codes work great, they still consume some noticeable amount of computing resources.
::
Something else is slowing you down; there is more to it than the snippet in your 1st post. Your code is not properly written, but it should not cause any noticeable slow down.

What you want is only a trendline; many people have hundreds of them on their charts.

I would suggest you post your complete codes if you need further help.

seneca
Posts: 97
Joined: 02 Apr 2012
Has thanked: 38 times
Been thanked: 22 times

Re: Price line

Postby seneca » 12 Feb 2014

Have you tried my code? All others seem to really bog my charts down, but that one was the ticket.

Totally agree that this should be a platform feature that we can turn off or on and that's updated every TICK. The trendlines have a slight lag in them...
Your code is the fastest of the three on my charts as well, as it shows the least significant time lag. This is definitively a good work around for the time being, thanks.

seneca
Posts: 97
Joined: 02 Apr 2012
Has thanked: 38 times
Been thanked: 22 times

Re: Price line

Postby seneca » 13 Feb 2014

Sorry for unresolving this topic, but as of now we have only a workaround. A true solution would be a horizontal price line as an integral part of MC, as suggested above.

@MC, please consider this feature for implementation in future releases.

Thanks.

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

Re: Price line

Postby Henry MultiСharts » 14 Feb 2014

@MC, please consider this feature for implementation in future releases.
Thank you for your suggestion. All feature requests are forwarded to the management of the company and are evaluated in a timely manner. Please note that even though we value your opinion not all requests can be implemented due to the fact that some features do not fit into our current roadmap.

seneca
Posts: 97
Joined: 02 Apr 2012
Has thanked: 38 times
Been thanked: 22 times

Re: Price line

Postby seneca » 15 Feb 2014

Something else is slowing you down; there is more to it than the snippet in your 1st post. Your code is not properly written, but it should not cause any noticeable slow down.

What you want is only a trendline; many people have hundreds of them on their charts.

I would suggest you post your complete codes if you need further help.
TJ,

maybe "slowing down" is not the very best wording for what I wanted to describe. Compared with the proposed integrated price line feature, I see two disadvantages with the EL coded price line:

1. Time lag of the price line of about 100 - 200 ms, compared with the price marker
2. The price line needs some few seconds to be calculated when opening a chart. This is a factor if you have regularly some 20 or 30 charts open


Return to “MultiCharts”