Page 1 of 1

Session boxes based on high/low for the session?

Posted: Sun Dec 06, 2020 4:00 am
by jtsas
Hi all, I'm struggling to figure out how to plot a box for a defined FOREX session using the high and low of the session as the upper and lower bound. I currently have the bgcolor changing for each session, but this isn't what I want. Any ideas?

Re: Session boxes based on high/low for the session?

Posted: Tue Dec 08, 2020 2:54 pm
by jtsas
This is as far as I've gotten. I'm not sure how to get it to redraw so it backfills from the highest high and lowest low for the session.

Image

Re: Session boxes based on high/low for the session?

Posted: Thu Dec 10, 2020 3:57 am
by Matthew
Hi jtsas!

Achieving that is kind of tricky and will require the use of "var" variables.

What you need to do is something like this:

Step 1: Detect when your session begins or ends

Code: Select all

// InSession() determines if a price bar falls inside the specified session
InSession(sess) => na(time(timeframe.period, sess)) == false

Step 2: Detect the high / low of the session

Code: Select all

var highOfSession = 0.0
var lowOfSession = 99999999

if InSession(<specified_trading_session>) and (high > highOfSession or na(highOfSession))
    highOfSession := high

if InSession(<specified_trading_session>) and (low < lowOfSession or na(lowOfSession))
    lowOfSession := low

Step 3: Reset high/low when the session ends

Code: Select all

if not InSession(<specified_trading_session>)
    highOfSession := na
    lowOfSession := na

Step 4: Draw/fill background

Code: Select all

highPlot = plot(highOfSession)
lowPlot = plot(lowOfSession)
fill(highPlot, lowPlot, color=color.yellow)

Unfortunately I don't have time to go into more detail, this is just some pseudo-code to get you thinking about potential solutions. This kind of thing is fairly complex and is something we'll cover in the Mentorship Program when it's released :) best of luck with your trading!