Search code examples
pine-scriptpine-script-v5trading

Is it possible to query TV through pine script about the current Y-axis dimensions of the screen? (Issues with Auto layout window anchoring)


I have an indicator that draws a full-size session board underneath price and the rest of the drawings. It works fine without Auto engaged in the Layout window settings, but breaks down as soon as Auto is selected. For some reason, Auto treats the drawings that the indicator is making as the anchors for itself to adjust the height of the display to, and since the indicator plasters gigantic vertical rectangles that print between specific times on the X-scale and go from 0 to gazillion on the Y-scale, Auto shrinks price to completely unreadable levels.

I haven't really used Auto in my trading workflow until recently, so it was never a real issue for my main display. I used Auto on an auxiliary display, and I was perfectly fine not having the board on it. My trading, however, recently evolved to where the auxiliary 4 window layout that I ran on Auto kind of came to dominate the whole process, and I am now thinking about the workaround for this issue that I have with the session board indicator killing Auto functionality.

I am honestly confused on why Auto reacts this way to the drawings that the indicator prints. It doesn't react this way to any regular drawings, so why is it reacting this way to the automated drawings made by an indicator? I wish I knew what I was doing wrong in the coding process that somehow bound Auto to these drawings (if that is the case).

Not knowing why this is happening, I was thinking about one possible workaround would be to continuously query TV on the current height dimension of the layout window and to continuously reprint the session board to that exact height (maybe minus one or two ticks, to give Auto some room not to be confused- although an attempt to do this could go terribly wrong as well lol).

I seem to be not able to find anything in the documentation about how to query that value. I also do not understand the dynamic where Auto binds itself to indicator drawings. It would be great to understand that, but, honestly, I am a trader, not a programmer, so the code doesn't have to be perfect and a workaround would suffice. I think I just hit the limit of where my rudimentary coding skills can take me, so I came here to ask you guys. :)

Any help would be greatly appreciated! Let me know if you want to see the indicator/code. I could even make it public for you to check it out first hand. All it really does is print the background in such a way as to have the open/close/lunch times for Tokyo, London, and New York exchanges displayed visually in a very pleasant way. It has been super helpful for me to wrap my mind around how PA changes depending on the session that dominates the market without the need to draw endless vertical lines by hand.

Thank you so much for your time!

Haven't tried anything yet for a solution. Couldn't find anything helpful in the documentation, so came here realizing I hit a wall.


Solution

  • "Auto" tries to show all drawings as a whole. Have you tried keeping "Auto" and enabling "Scale price chart only" (accessible after right-clicking on the price scale)?

    Unfortunately, you can not get the layout height. However, you can calculate the price range from the visible highest/lowest values. You can refer to this answer and this Library.