Advertisement
Maurizio-Ciullo

Indicatore Session_Max high/low/open/close

Oct 27th, 2022
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © Maurizio-Ciullo
  3.  
  4. // https://www.tradingcode.net/tradingview/session-highest-high/
  5.  
  6.                                       // USED FOR INTRA DAY ONLY, NOT FOR DAILY OR MAJOUR //
  7.  
  8. //@version=5
  9. indicator(title="Indicatore Session_Max high/low/open/close", overlay=true)
  10.  
  11. // SessionHigh() returns the highest price during the specified
  12. // session, optionally corrected for the given time zone.
  13. // Returns 'na' when the session hasn't started or isn't on the chart.
  14. SessionHigh(sessionTime, sessionTimeZone=syminfo.timezone) =>
  15.     insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
  16.     var float sessionHighPrice = na
  17.  
  18.     if insideSession and not insideSession[1]
  19.         sessionHighPrice := high
  20.     else if insideSession
  21.         sessionHighPrice := math.max(sessionHighPrice, high)
  22.    
  23.     sessionHighPrice
  24.  
  25.  
  26. // InSession() returns 'true' when the current bar happens inside
  27. // the specified session, corrected for the given time zone (optional).
  28. // Returns 'false' when the bar doesn't happen in that time period,
  29. // or when the chart's time frame is 1 day or higher.
  30. InSession(sessionTimes, sessionTimeZone=syminfo.timezone) =>
  31.     not na(time(timeframe.period, sessionTimes, sessionTimeZone))
  32.  
  33.  
  34. // Configure session with inputs
  35. session  = input.session("0800-1700", title="Trading Session")
  36. timeZone = input.string("GMT", title="Time Zone")
  37.  
  38. // Get the session high
  39. sessHigh = SessionHigh(session, timeZone)
  40.  
  41. // Show the session high on the chart
  42. plot(sessHigh, color=color.green, title="Session High")
  43.  
  44. // For visual verification, highlight the background of session bars
  45. bgcolor(InSession(session, timeZone) ? color.new(color.orange, 90) : na)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement