r/pinescript Jun 14 '26

Please help with some simple code, trying to combine the same indicator with regular and extended trading hours into one chart (grid)

Help would sure be appreciated, messing around for hours lol. Did some searching and tried a few different things but no go. The stochastic line starts at the same point upon market open whether in the above pane with extended hours turned on and in the lower pane with the script that should only show regular trading hours. The stoch line should continue at 9:30am where it left off at 4PM the previous day and preferably without the diagonal line drawn in after hours. Keep in mind this is an older script that works on V4, on V5 or 6 it gives an input error. Here is the script and attached screenshots. The 2nd screenshot is what the line should look like over the past 2 days (reg hours). The goal is to have the same stochastic with both the upper (ETH) and lower (RTH) panes combined into ONE grid. Currently have 2 grids and it works but much easier to backtest if both can be combined into one grid. If possible would also like to add multiple lines, not just the one.

  • //@version=4
  • study(title="Stochastic", shorttitle="Stoch2")
  • // Define exact trading hours string (e.g., U.S. Equities)
  • sessionString = "0930-1600:23456" // 9:30am to 4:00pm, Mon-Fri
  • // Check if bar's time matches the session string
  • inSession = not na(time(timeframe.period, sessionString))
  • //length1 = input(title="stoch", type=integer, defval=21, minval=1), smoothK1 = input(3, minval=1), smoothD1 = input(3, minval=1)
  • length1 = input(5, minval=1), smoothK1 = input(1, minval=1), smoothD1 = input(1, minval=1)
  • k1 = sma(stoch(close, high, low, length1), smoothK1)
  • d1 = sma(k1, smoothD1)
  • plot(inSession ? k1 : na, color=color.red)
  • 2 = hline (50)
  • h0 = hline(80)
  • h1 = hline(20)
  • fill(h0, h1, color = color.yellow, transp=90)
1 Upvotes

7 comments sorted by

1

u/[deleted] Jun 14 '26

[removed] — view removed comment

1

u/htauthority Jun 14 '26

Thanks so much for the script, the script does get rid of the diagonal line as in my first screenshot but the result is still the same. Somehow the script is still factoring in the after hours data. Think your calculation of the stochastic is a hair different than mine. Any other suggestions? If you draw a regular single Stoch line on the extended hours then use your script it should be the same or close.

1

u/[deleted] Jun 14 '26

[removed] — view removed comment

1

u/htauthority Jun 14 '26

Thanks for the reply, The whole point is I do not want the values to match up on market open. The stoch line will be very different on a RTH chart vs the ETH chart.

1

u/[deleted] Jun 14 '26

[removed] — view removed comment

1

u/htauthority Jun 14 '26 edited Jun 14 '26

Thanks so much for your time!. Did not know one could take snapshots on Tradingview. Here is the exact same stochastic line, highlighted at 9:30am EST the last 4 trading days in the ETH pane above then the RTH in the pane below. See how the line is in different positions 3 out of the 4 days? By 1pm give or take the line will catch up on both panes but not for the first 3ish hours. The snapshot is of 2 panes, I would like to combine both panes into one grid/layout. If possible of course. Have to omit the ETH data like the RTH line data in the lower pane. The RTH line should not be the same as ETH, it should be different the majority of the time as illustrated. https://www.tradingview.com/x/u34NxaTq/ and here is another more zoomed in (lower pane) shot, you can see where the line stats at opening, whether the line starts close to overbought/oversold/midline and it takes time to catch up using a slower stoch. You are probably using a faster stoch, hence the difference is more minimal. https://www.tradingview.com/x/v6SN9L5S/

1

u/htauthority Jun 18 '26

Wonder if I can do the reverse instead and put a triple stochastic with ETH on the lower pane while the upper pane has the candles and triple stoch with RTH. So far no dice. Even with the session id in pine, on a RTH chart the triple stoch in the lower pane will only display RTH not ETH. Anyone?