ChrisMoody

Code for All 4 Forex Sessions W/ Background Highlight!!!

3737 39 897
This is one indicator including the New York             Session, Australia Session, Asian Session, Europe Session. IMPORTANT - This template is set up based on East Coast (NY Time). Currently you have to go in to code to change times. Link in 1st Post to VIDEO walking you through the steps. Specific details in 1st Post.
Remove from Favorite Scripts Add to Favorite Scripts
//Created by user ChrisMoody 2-17-2014
//Forex Session Templates Based on EST-New York Time Zone
//Special Thanks to TheLark AKA The Coding Genius for helping me with the "On - Off" CheckBoxes in the inputs tab

study(title="CM_Forex-Sessions-Highlight_V1",shorttitle="CM_forex_Sess_Highlight", overlay=true)
timeinrange(res, sess) => time(res, sess) != 0

//Change true to false = You have to turn on, won't show up by default
//****Always use lowercase letters

doNYOpen = input(defval=true, type = bool, title="NY Open On")
doNYSession = input(defval=true, type = bool, title="NY Session On")
doNYClose = input(defval=true, type = bool, title="NY Close On")

doAussieOpen = input(defval=true, type = bool, title="Aussie Open On")
doAussieSession = input(defval=true, type = bool, title="Aussie Session On")
doAussieClose = input(defval=true, type = bool, title="Aussie Close On")

doAsiaOpen = input(defval=true, type = bool, title="Asia Open On")
doAsiaSession = input(defval=true, type = bool, title="Asia Session On")
doAsiaClose = input(defval=true, type = bool, title="Asia Close On")

doEurOpen = input(defval=true, type = bool, title="Euro Open On")
doEurSession = input(defval=true, type = bool, title="Euro Session On")
doEurClose = input(defval=true, type = bool, title="Euro Close On")

//You can copy and paste these colors. white - silver - gray - maroon - red - purple - fuchsia - green - lime
//   olive - yellow - navy - blue - teal - aqua - orange 

nySessionStart = white
nySession = white
nySessionEnd = white
australiaSessionStart = #A9A9A9
australiaSession = #A9A9A9
australiaSessionEnd = #A9A9A9
asiaSessionStart = #DAA520
asiaSession = #DAA520
asiaSessionEnd = #DAA520
europeSessionStart = #1E90FF
europeSession = #1E90FF
europeSessionEnd = #1E90FF

//****Note ---- Use Military Times --- So 3:00PM = 1500

bgcolor(doNYOpen and timeinrange(period, "0800-0810") ? nySessionStart : na, transp=20)
bgcolor(doNYSession and timeinrange(period, "0800-1700") ? nySession : na, transp=75)
bgcolor(doNYClose and timeinrange(period, "1650-1700") ? nySessionEnd : na, transp=20)

bgcolor(doAussieOpen and timeinrange(period, "1700-1710") ? australiaSessionStart : na, transp=20)
bgcolor(doAussieSession and timeinrange(period, "1700-0200") ? australiaSession : na, transp=75)
bgcolor(doAussieClose and timeinrange(period, "0150-0200") ? australiaSessionEnd : na, transp=20)

bgcolor(doAsiaOpen and timeinrange(period, "1900-1910") ? asiaSessionStart : na, transp=20)
bgcolor(doAsiaSession and timeinrange(period, "1900-0400") ? asiaSession : na, transp=75)
bgcolor(doAsiaClose and timeinrange(period, "0350-0400") ? asiaSessionEnd : na, transp=20)

bgcolor(doEurOpen and timeinrange(period, "0300-0310") ? europeSessionStart : na, transp=20)
bgcolor(doEurSession and timeinrange(period, "0300-1200") ? europeSession : na, transp=75)
bgcolor(doEurClose and timeinrange(period, "1150-1200") ? europeSessionEnd : na, transp=20)
This is one indicator including the New York Session, Australia Session, Asian Session, Europe Session.

This is a simple code but since the sessions overlap I had a VERY touch time finding colors that allowed you to tell the plots were overlapping. You can modify based on the background color of your chart. Video Below Gives Tips and Shows the Easiest Way!!!

This Indicator is based on East Coast - NY Time. Currently you have to go into the code to change the times. Detailed Video below shows how to do this. Also there is a new video showing a better way to share and import indicators. Credit goes to TheLark for showing me.

Good News is TheLark showed me how to place Check Boxes in the inputs tab so you can easily turn on and off any of the sessions you want. Also I created a Darker plot the first 10 minutes of each session beginning and end, So you can plot all of those on 1 chart and uncheck the Highlight for the whole session. Because the Opening/closing session plots are 10 minutes each you need to use a lower timeframe or they will not plot correctly. If using a 4 hour bar for example uncheck the Open/Close of session and just use background highlight.
Reply
TheLark PRO ChrisMoody
2 years ago
Glad I could help, and glad you got this one finished, turned out real nice!
Reply
New Video Showing Better Way to Import in Custom Indicators.
Titled - Importing Custom Indicators In TradingView Charts

New Video Showing how to change the times in the code to match your time zone.
Titled: How To: Change Time In Code - Background Highlights
***Recommend watching this video to understand Indicator, Shows How To Change Time in Code, Shows easier way to Change Colors, also shows a demo of similar Indicators I’m about to release.

Link To Both Videos:
http://vimeopro.com/user14689865/tradingviewcom-how-to-videos
Reply
Link To Indicator Code
http://pastebin.com/VLvRfH0m
Reply
timwest PRO
2 years ago
Nice looking chart Chris!
Reply
f3n_dy
2 years ago
error...Processing TVScript...
line 1:0 required (...)+ loop did not match anything at input ' '
Reply
ChrisMoody PRO f3n_dy
2 years ago
Just double checked and the code works. Did you copy the code from the Pastebin link above and import the code as described in the video above. If not watch just the first 6 minutes of the video....that will show the whole process of installing the indicator. The 2nd video shows how to change the times if your chart isn't set to East Coast Time...and it goes over further customizing the indicator. I'm confused because you got an error with line 1:0...The code doesn't start until line 4 or 5.

I'm happy to help..just not sure what steps you've taken...to get an error at line 1:0....
Reply
f3n_dy
2 years ago
i click add to chart and show this..
Processing TVScript...
line 1:0 required (...)+ loop did not match anything at input '\t'
Reply
ChrisMoody PRO f3n_dy
2 years ago
Just sent you a Private Message
Reply
fcha PRO
2 years ago
Chris, there is something you wrote about Lark on row paste and I have to copy that too.

Thank you!
Reply
fcha PRO fcha
2 years ago
I mean on pastebin link.
Reply
ChrisMoody PRO fcha
2 years ago
Copy the entire code....if you haven't watch the first 6 minutes of the new video...then you'll need to watch the 2nd video to understand how to customize the indicator
Reply
fcha PRO ChrisMoody
2 years ago
ok, thanks!
Reply
4apprentice08
2 years ago
THx a bunch for this code.

Any way to change the labels of the colour settings to reflect the Session Name?

How can I get code for your Opening 30min/1hr? Better yet, have you created similar ones for FOREX, e.g. High/low of Asian session, London session, etc?

Reply
4apprentice08
2 years ago
Also, have you ever considered coding session markers as Horizontal lines instead? Any idea would be to draw colour-coded horizontal lines, either as an indicators below the chart, or better yet attached to the high and/or low of the session, extended for the length of the session? You could adjust thickness of lines too.

Maybe this could easily be constructed using your 30min/1hr high/low code as a starting point. Let me know what you think.
Reply
4apprentice08 4apprentice08
2 years ago
where session times overlap, shift lines over by a a number of pips up/down, so they do not draw on top of each other. Also adjustment for the thickness of the lines could be useful, with option to fill in colour between high/low lines.Overlapping colours will be less of an issue as the horizontal lines willb e visible.
Reply
ChrisMoody PRO 4apprentice08
2 years ago
1. Code for opening range is on this link:
New Indicator!!! Opening Range_V1

2. That code just does the Opening Range in Stocks, 9:30 East Coast, or 1700 or 5pm New York Time for Forex.
3. It could only be coded for Forex for different sessions like the Europe or Asia Session making a different indicator. That may have been fixed. I'll check b/c I wanted to create options for all forex sessions.
4. I like the idea of coding the sessions to plot on a lower indicator...I'll look in to it.
5. I'll look at the code regarding your first question regarding labels, my initial resposnse is no b/c normally I would have done that. But I will double check. If they were horizontal lines you could b/c you could address each upper an dlower plot seperately and apply a name to them, and then just create a fill between the two. Plotting background highlights like this indicator does uses a new feature where it is all one plot and I don't think it allows to name it...but again I willl check...
Reply
ChrisMoody PRO ChrisMoody
2 years ago
To make a lower study you just need to change one line of code. Open the source code and line #5 starts with the word study

Copy and paste this code over line #5 ---- Then Press SAVE and then Apply to chart - you will still have original one that plots on price chart and this new one that plots on lower indicator.
study(title="CM_Forex-Sessions-Highlight_V1_LowerStudy",shorttitle="CM_forex_Sess_Highlight", overlay=false)

This will rename the study with a LowerStudy at the end of the name. And the overlay=false means it will plot as lower study
The chart shows adding the study two times and plotting two of the time zones on each that don't overlap.
You could also plot two of the time zones on the upper chart and then just have one lower study with the other two so none overlap.

snapshot
Reply
ChrisMoody PRO ChrisMoody
2 years ago
You can't label the colors at this time. I'll check with programmers tomorrow to see if there is a workaround.

Also in the code you can find where it lists the code below....if you change the defval=true to defval=false then it won't automatically plot that when you apply to chart. So you can make two of the sessions false and then on Line#5 change the first title tobe named title="CM_Fores_Sess_Highlight_NYSess_EuropeSess" and that indicator will just plot those two sessions...then create another indicator and make false the other two sessions and name those sessions in the title.

If you do the above just SAVE the indicator after you change the title, then make changes for the other two sessions and SAVE it again...

doNYOpen = input(defval=true, type = bool, title="NY Open On")
doNYSession = input(defval=true, type = bool, title="NY Session On")
doNYClose = input(defval=true, type = bool, title="NY Close On")

doAussieOpen = input(defval=true, type = bool, title="Aussie Open On")
doAussieSession = input(defval=true, type = bool, title="Aussie Session On")
doAussieClose = input(defval=true, type = bool, title="Aussie Close On")

doAsiaOpen = input(defval=true, type = bool, title="Asia Open On")
doAsiaSession = input(defval=true, type = bool, title="Asia Session On")
doAsiaClose = input(defval=true, type = bool, title="Asia Close On")

doEurOpen = input(defval=true, type = bool, title="Euro Open On")
doEurSession = input(defval=true, type = bool, title="Euro Session On")
doEurClose = input(defval=true, type = bool, title="Euro Close On")

Let me know if you have any more questions.
Reply
4apprentice08 ChrisMoody
2 years ago
Thx for Opening Range.

As for FX Sessions, This is good but for some reason the Close "bar" will not draw when I use add this as a lower study, only the open and session. Note sure why since I see it shows on yours above.

Also, any way to replace Open & Close with just vertical lines?
Also, would love to see a version with Horizontal lines on chart, if you can figure it out. ;-)

BTW, I suggest ordering your sessions so NY is the 3rd one, to keep them in the order they actually occur. Just my 2 cents.
Reply
ChrisMoody PRO 4apprentice08
2 years ago
Is it possible the reason is it is currently in the session?...Take a pic and post it here.

Regarding The order...I thought you were crazy...but since I'm using the Banking Hours or Active sessions for each major zone, your right. But shouldn't New York go last.

I've got Australia starting at 1700 Eastern TIme, Asia starting at 1900, Europe Starting at 0300, and US starting at 0800.

Do you disagree with those times? I do need to modify b/c Europe just had Day Light Savings.

What are the actual Banking Centers so I can look up exact times and see if Daylight Savings affected any others?

Australia - Sydney??? Asia - Tokyo ??? Europe - London??? U.S. - New York....
Reply
4apprentice08 ChrisMoody
2 years ago
Attached is example showing Euro turned on (all 3 settings):
snapshot


As for sessions, correct NY should be last.

Times are correct, except Wellington is 1700, Australia is 1900. Frankfurt is usually 0200 1 hour before Europe but right now looks like on same time

Here is a trading clock you can see all times (I believe factors in Daylight Savings times for each region, though not 100% sure)
http://mc24.ch/index.html

Reply
ChrisMoody PRO 4apprentice08
2 years ago
First the reason the lines aren't showing up is you have on 60 minute chart while the Opneing and Closing lines for each session is set to 10 minutes...so I'm surprised the first line is showing.

To Fix if you primarily use 60 minute chart...in the code find the section that has
bgcolor(doNYOpen and timeinrange(period, "0800-0810") ? nySessionStart : na, transp=20)

And you would change the doNYOpen time to 0800-0900...same for doNYClose

I'm not a forex expert so let me know what cities that are listed on the link above to use for different Forex Sessions. And let me know which city goes with the main name for each session....Example Frankfurt = Europe.....???? = Asia etc.

Once I have that I will recode with correct sessions and names and I will put in correct order...I would wait until then to change the opening and closing times to a hour b/c the code I send you won't reflect that.
Reply
fcha PRO ChrisMoody
2 years ago
Hi, Chris.
I have the same problem, I copy again from the link and now is fine.
Reply
4apprentice08 ChrisMoody
2 years ago
Ok, so I tried lower time frame and it works better. Will have to play around with "line" thickness by changing the time range for higher time frames. But it seems like a bug in PINE that the OPEN "line" shows but the CLOSE "Line" does not show on higher time frames, since they are both using the same time range.

That said, how hard would it be to change this to draw actual vertical lines instead of the time range used for the OPEN or CLOSE?

As for the session times for the FOREX there are as follows (highlighting zones of greatest interest to set default ON):
Kiwi -> Wellington (New Zealand) = 1700-23:45 OPEN ONLY (Close often ignored. often considered with Sydney as part of Aussie session )
Aussie session -> Sydney (Australia) = 1900-0100 OPEN & CLOSE
Asian session -> Tokyo (Japan) = 1900-0200 OPEN ONLY (CLOSE often considered with Singapore as part of Asian session)
Asian Session -> Singapore/Hong Kong = 2100-0300 CLOSE ONLY (CLOSE often considered with Japan as part of Asian session)
Euro Session -> Frankfurt (Germany) = 0200-1000 OPEN ONLY (CLOSE often considered with London as part of Euro session)
Euro Session -> London (UK) = 0300-1100 OPEN & CLOSE
NY Session -> NY (US) = 0800-1700 OPEN & CLOSE

The open & Close will change based on daylight savings observances that vary from country to country.

So I would list then as Session (City), e.g. Aussie Session (Wellington), Aussie Session (Sydney), etc.
Reply
ChrisMoody PRO 4apprentice08
2 years ago
The last 3 paragraphs I understand 100%. Thanks and I will get this done.

The 2nd paragraph is unclear so please explain in detail.
"That said, how hard would it be to change this to draw actual vertical lines instead of the time range used for the OPEN or CLOSE?"

I need more detail on that one...It does draw vertical lines at open and close, I can just use those or take them off. I f I use them you will have issue with changing to different timeframes as you are now. Currently we can't use an adjustable input where you can switch any sort of times in the Inputs window...you actually have to go in to the code.

I can just have the background color without Open and Close line but it's just as easy to change those to False so they won't automatically show up.

Tell me what I'm missing and I will let you if currently it can be done....

Thanks
Reply
4apprentice08 ChrisMoody
2 years ago
Re: 2nd paragraph - pardon my ignorance but it appears that you are drawing the Open and Close by shading a time range (I am unclear if this is the actual method you are using).

My thought was whether or not it is possible to use a single vertical line, like one produced by the Vertical Line drawing tool and use PINE to draw that. When you don it manually, you do not need to worry about the time range to make the line show up. No matter what time resolution you are on, a line is a line. And the manual drawing tool allows colour and line thickness choices.

BTW, I was just looking at the "Script Language Reference Manual" and I see function called hline. I think what I am thinking about is the equivalent but a vline function that takes date and time as inputs, where the date is optional and the vline is drawn at every time that matches. I think that would be the ideal.....

BTW, if a vline function is created, I have a few other uses for it too. I assumed it was there but since I do not , I see some other things I will not be able to have scripted, e.g. drawing a vertical line on my chart when say MACD crosses the 0 line.

P.S. Though I have done some coding in the past (20 years ago), and have been in IT for over 20 yrs, I am not a strong programmer. So I can decipher code to some extent.
Reply
ChrisMoody PRO 4apprentice08
2 years ago
You are correct. The only current option is a form of shading using a newer Function/Reserved Word - bgcolor...then I just change the transparency settings to appear like a vertical line.

I use hlines a lot....no vline option yet. Don't get discouraged and keep letting me know features you want...

The advantage I have is I know the long term vision of the company and the features they are currently working on. What most people don't know is the creators of TradingView have a long track record of developing High End Institutional Grade Trading Platforms. I can assure you that T.V. Will offer advanced capabilities never seen before in the industry. Pine Script is still in Beta and although today it lacks features we all want...It's already the most advanced custom coding language ever made available on a 100% pure web browser based platform. They are releasing one or two new capabilities at a time so any bugs can be fixed quickly. Just know the developers have already created award winning platforms with Institutional Grade Coding Capabilities. We will have all the bells and whistles in due time.

For the next few years every 3-6 months you'll see so many feature enhancements you'll look back and laugh at the time when we couldn't plot a simple vertical line. We will go from basic indicators to being able to code complete systems before you know it...

Keep the ideas and requests coming...
Reply
4apprentice08 ChrisMoody
2 years ago
Thanks for the feedback...I'll submit a request to the vline function. Until then, your current code will have to do, unless you find a better work around.

ANother question...is there a way to draw this only when a Forex symbol is selected? It currently draws on any symbol.
Reply
fcha PRO
2 years ago
Something wrong with the time now.
Reply
ChrisMoody PRO fcha
2 years ago
Are you still having problems? If so the time should only be off one hour at most b/c of Daylight Savings which I will adjust as soon as I fix the issues mentioned above.

If time is way off as the video says the times are based on New York timezone. So if it was working before and not now you just have to go on to you chart, Right Click and select TIMEZONE and make sure it is set to EST. If you don't want your TimeZone on EST you have to manually adjust ALL of the times in the code. I'll help if you need help....
Reply
John Mann
2 years ago
"Let me know if you have any requests!" . . . Three items come to mind right away:


1. a price action alarm
2. a pinbar detector
3. an engulfed candle indicator
Reply
ChrisMoody PRO John Mann
2 years ago
John,

1. A Price Action Alarm? --- Be more Specific. If your speaking of placing lines on a chart and being alerted when price reaches those levels...the capability is not there yet....but it is coming. No Alarms can be set for any criteria. But the feature is coming.

2. PinBar Detector? - That is actually on my list of items to code. Currently it will have to be coloring the candlestick of price bar a certain color. By the way are you a Chris Capre Student? Or Where did you learn about PinBars?

3. Engulfed Candle? - I'm in the process of coding many candlestick patterns. That one is easy and I may have already coded that...if so I will post code to indicator below.
Reply
ChartArt
2 years ago
I thank you for your creating this very helpful script with this screenshot of using your script in the Apple stock 1-minute chart. Yes, you can clearly see a correlation between the lunch time in New York and the end of the European session (EU session = blue, end of EU session = bright blue):

snapshot
Reply
ChrisMoody PRO ChartArt
2 years ago
First...Thanks....I forgot about this thread...I need to look at this script...we may have newer improvements released that would allow to make a little better...I'll have to look. Will be next week before I can get to it but If I don't respond feel free to PM me and remind me
Reply
ChartArt ChrisMoody
2 years ago
"We may have newer improvements released that would allow to make it a little better" (...) "remind me"

Reminder :D
Reply
NikoGiannaros ChrisMoody
2 months ago
this is great! anyway to add Hi and low line of sessions?
Reply
GaborKrasznai PRO ChrisMoody
19 days ago
@ChrisMoody, Hi Chris, This script is no longer working. Is there a newer version? thanks, Gabor
Reply
Sputnik81 PRO
10 months ago
Thank you!
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out