Expose Price points along hand drawn trendline with studyID

Hello group,

I like to draw my support and resistance trendlines and usually give them a studyID in the properties dialogue.
I know we can setup an explore etc to alert if we have a breakout ( up or down ) crossing the trendline. I was thinking on how to expose the price points along these drawn trendlines for a visual confirmation.

So far I have the following code below with an image showing the result. I am not sure if this is correct
way to find the price points, please have a look. Suggestions / fixes are welcomed.

Anthony

_SECTION_BEGIN("trendline price point");
trendline = Study("UP", GetChartID() );
x=H-trendline;
xx=H-x;

trendline = xx ; 

FirstVisibleBar = Status( "FirstVisibleBar" );  
Lastvisiblebar = Status("LastVisibleBar");  
for( i = Firstvisiblebar; i <= Lastvisiblebar AND i < BarCount; i++)  
{  
if( trendline[i] )  
{  
PlotText(NumToStr(trendline[i],1.2),i,trendline[i],colorwhite);  

}  
} 

_SECTION_END();

chart example

I.e. your three lines

x = H - trendline;
xx = H - x;

trendline = xx;

are redundant code and are not necessary.
StudyID is an array function.

What your lines say is this

x -> difference between H and trendline
xx -> H minus that difference -> so we have trendline again
trendline = xx -> results in trendline of line two again.

So it’s pointless code lines as it does not serve any further purpose in your code.
So basically below one is all you need (instead of those three mentioned lines).
(I just added printf so you can see yourself that trendline is type array)

trendline = Study("UP", GetChartID() );
//printf( "Type of trendline: %s", typeof(trendline) );

etc.

1 Like

Thank you @fxshrat for having a look . I removed the 3 redundant lines.
When you mentioned StudyID is an array function helped. Again, thank you.

_SECTION_BEGIN("trendline price point");
trendline = Study("UP", GetChartID() );


FirstVisibleBar = Status( "FirstVisibleBar" );  
Lastvisiblebar = Status("LastVisibleBar");  
for( i = Firstvisiblebar; i <= Lastvisiblebar AND i < BarCount; i++)  
{  
if( trendline[i] )  
{  
PlotText(NumToStr(trendline[i],1.2),i,trendline[i],colorwhite);  

}  
}