Horizontal lines to be displayed only when in normal display range

I have written a small code to draw two horizontal lines.
I want those lines only to be dispaly when they are in regular/default visible range.
Now the system always shows those lines, shrinking the charts while accommodating those two lines.
If there is a way to display those lines only when they are in normal display range.
I want those to appear like objects we draw from the toolbar(line lines, box, text) .

tfD= inDaily;
TimeFrameSet(inDaily); 
OP=LastValue(O);
HG=LastValue(H);
LW=LastValue(L);
datr=ATR(14);
TimeFrameRestore();
datrh=OP+datr;
datrl=OP-datr;
Plot(LastValue(datrh),"",colorwhite);
PlotGrid(LastValue(datrh),colorWhite,10,1,false);
Plot(LastValue(datrl),"",colorwhite);
PlotGrid(LastValue(datrl),colorWhite,10,1,false);

My chart is 5 mins intraday chart

Are referring to the bars flattening out ?

That is because the scale is fixed to the right.
You can either change the scale to Own (which wont make much sense as you are plotting price levels)
or you can define some thresholds for plotting like x% from the Highest and Lowest Visible values of price.

is this topic similar to your issue ?

1 Like

@snbarma, if I understand correctly what you wrote, maybe using styleNoRescale will do it:

tfD = inDaily;
TimeFrameSet( inDaily );
OP = LastValue( O );
HG = LastValue( H );
LW = LastValue( L );
datr = ATR( 14 );
TimeFrameRestore();
datrh = OP + datr;
datrl = OP - datr;
Plot( C, "Close", colorDefault, styleBar ); // This plot will set the correct y-scale
Plot( LastValue( datrh ), "", colorRed, styleDashed | styleNoRescale );
// PlotGrid(LastValue(datrh),colorWhite,10,1,false); // NOT NEEDED
Plot( LastValue( datrl ), "", colorGreen, styleDashed | styleNoRescale );
// PlotGrid(LastValue(datrl),colorWhite,10,1,false); // NOT NEEDED 

Re the correct usage of styleNoRescale, please, see this previous thread.

I also commented out the PlotGrid() lines because they seem redundant.

1 Like

Thanks a lot. This solution is perfect for the issue.
PlotGrid is in my code as I want to dispaly the value on the scale. By default, I don't want to display the values.