Opening range indicator asian/europe session (with 2 profit targets)

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #71615 quote
    julien1978
    Participant
    Average

    Dear fellow traders,

     

    Since i have zero skills in programming, i would be really pleased if someone would be kind enough to adapt an indicator found on tradingview into our beloved prorealtime language (see the code below).

    Basically, as I understand it, this indicator sets up a range for the entire trading day based on the lowest and highest point reached between midnight until 7 am, just before the London session opening (hours should be able to be modified to suit personal taste), on a 1H timeframe.

    More over, it automatically sets 2 profit targets above and below the range: 1 based on half of the range size and 1 equals to the total size of the range.

    (See attached picture)

    This indicator proves to be very helpful in trading some strategies such as the London open breakout.

    Cheers/merci in advance!

     

    Jules

     

    Source code:

     

    //Created by ChrisMoody on 9/03/2014

    //Requested by rayhug1 to use ENTIRE Asia Range From 5pm Est to 2am Est To Plot Opening Range of Entire 9 hour session…uses 540 minutes (5pm to 2am Est) to calculate the Range…then breakouts trigger after 2am

    //Ability to change Start and End Times to use any entire session.  Defaults to 540 minutes (9 hours)  but Opening Range Calculation can be changed to 1 hour etc. in inputs tab

    study(“_CM_Opening-Range_Asia_Europe Sessions”, overlay=true)

     

    sessNum = input(1, minval=0, maxval=2, title=”Session to use (0 = 24 Hours, Other Numbers Listed Below)”)

    desc = input(false, title=”Below—Line Plot Start Times and End Times—1 = Asian Session, 2 = Europe Session”)

    asian_session = input(‘1700-1659’, type=session, title=”1 – Asia Session”)

    europe_session = input(‘0200-0159’, type=session, title=”2 – Europe Session”)

    //us_session = input(‘0800-0759’, type=session, title=”3 – U.S. Session”)

    pt1 = input(5, minval=1, maxval=15, title=”Profit Target 1 – Multiple of Opening Range *.1, 5 = .5, 7 = .7, 10 = 1, 15 = 1.5 etc.”)

    pt2 = input(10, minval=1, maxval=30, title=”Profit Target 2 – Multiple of Opening Range *.1, 10 = 1, 15 = 1.5, 18 = 1.8, etc.”)

    res = input(‘540’, type=resolution, title=”Length Of Opening Range-Defaults to 540 Minutes (9 Hours) Select Drop Down Box To Change?”)

    snp = input(true, title=”Plot 1 and 2 When 1st and 2nd Profit Target are Achieved?”)

     

    //Session Selection Rules

    sessToUse = sessNum == 1 ? asian_session : sessNum == 2 ? europe_session : ‘0000-0000’

     

    //Session Rules

    bartimeSess = (sessNum == 0 ? time(‘D’) : time(‘D’, sessToUse))

    fr2to17 = (sessNum == 0 ? time(period) : time(period, sessToUse))

    newbarSess = bartimeSess != bartimeSess[1]

    high_range = valuewhen(newbarSess,high,0)

    low_range = valuewhen(newbarSess,low,0)

    adopt(r, s) => security(tickerid, r, s)

     

    //Formula For Opening Range

    highRes = adopt(res, high_range)

    lowRes = adopt(res, low_range)

    range = highRes – lowRes

     

    //Highlighting Line Rules For Opening Range

    highColor = high > highRes ? lime : yellow

    lowColor = low < lowRes ? red : yellow

     

    //Plot Statements For Opening Range Lines

    openRangeHigh = plot(fr2to17 > 0 ? highRes : na, color=highColor, style=circles, linewidth=4)

    openRangeLow = plot(fr2to17 > 0 ? lowRes : na, color=lowColor, style=circles, linewidth=4)

    bgcolor(fr2to17 > 0 ? silver : na, transp=85)

    fill(openRangeHigh, openRangeLow, color=silver, transp=70, title=”Opening Range Fill”)

     

    //Formula For Profit Target 1

    pft1 = pt1*.1

    highRes2 = highRes+range*pft1

    lowRes2 = lowRes-range*pft1

     

    //Highlighting Line rules for Profit Target 1

    highColor2 = high > highRes2 ? lime : fuchsia

    lowColor2 = low < lowRes2 ? lime : fuchsia

     

    //Plots For Profit Target 1

    p1=plot(fr2to17 > 0 ? highRes2 : na, color=highColor2, style=circles, linewidth=4)

    p2=plot(fr2to17 > 0 ? lowRes2 : na, color=lowColor2, style=circles, linewidth=4)

     

    //Formula For Profit Target 2

    pft2 = pt2*.1

    highRes3 = highRes+range*pft2

    lowRes3 = lowRes-range*pft2

     

    //Highlighting Line rules for Profit Target 2

    highColor3 = high > highRes3 ? lime : aqua

    lowColor3 = low < lowRes3 ? lime : aqua

     

    //Plots For Profit Targe 2

    plot(fr2to17 > 0 ? highRes3 : na, color=highColor3, style=circles, linewidth=4)

    plot(fr2to17 > 0 ? lowRes3 : na, color=lowColor3, style=circles, linewidth=4)

     

    //Rules for when to plot Numbers 1 or 2 When Profit Target 1 or 2 is Reached

    pt1UHit = (high >= highRes2  and high[1] < highRes2 and high[2] < highRes2 and high[3] < highRes2 and high[4] < highRes2 and high[5] < highRes2) and fr2to17 > 0

    pt1LHit = (low <= lowRes2  and low[1] > lowRes2 and low[2] > lowRes2 and low[3] > lowRes2 and low[4] > lowRes2 and low[5] > lowRes2) and low > lowRes3 and fr2to17 > 0

    pt2UHit = (high >= highRes3  and high[1] < highRes3 and high[2] < highRes3 and high[3] < highRes3 and high[4] < highRes3 and high[5] < highRes3) and fr2to17 > 0

    pt2LHit = (low <= lowRes3  and low[1] > lowRes3 and low[2] > lowRes3 and low[3] > lowRes3 and low[4] > lowRes3 and low[5] > lowRes3) and fr2to17 > 0

     

    //Rules for plotting 1 or 2 When Profit Target 1 or 2 is Reached

    plotchar(snp and pt1UHit ? pt1UHit : na, title=’UpSide Profit Target 1 Achieved’, char=’1′, location=location.abovebar, color=white, transp=0, offset=0)

    plotchar(snp and pt1LHit ? pt1LHit : na, title=’DownSide Profit Target 1 Achieved’, char=’1′, location=location.belowbar, color=white, transp=0, offset=0)

    plotchar(snp and pt2UHit ? pt2UHit : na, title=’UpSide Profit Target 2 Achieved’, char=’2′, location=location.abovebar, color=white, transp=0, offset=0)

    plotchar(snp and pt2LHit ? pt2LHit : na, title=’DownSide Profit Target 2 Achieved’, char=’2′, location=location.belowbar, color=white, transp=0, offset=0)

    #71698 quote
    Nicolas
    Keymaster
    Master

    Topic moved to English forum.

    Same indicator as this one? : Open Range Breakout Indicator ORB

    #71728 quote
    julien1978
    Participant
    Average

    Thank you Nicolas for your very quick answer!

    This is almost what i was looking for, but how do you base this indicator on a larger time period (for example from 4 am candle to 7 am candle) instead of just 1 specific hour candle. Sorry i don’t manage to do it.

    Also, is it possible to add 10 pips (for example) to the lowest and highest of the range in order to define its boundaries? What would be the code for that?

    #71856 quote
    Nicolas
    Keymaster
    Master

    Please find below the code with the modifications required:

    once maxii=undefined
    once minii=undefined
    once maxi1=undefined
    once mini1=undefined
    once maxi2=undefined
    once mini2=undefined
    once maxi3=undefined
    once mini3=undefined
     
    if time<040000 then
     maxi=high 
     mini=low
    elsif time<070001 and time>=040000 then
     maxi=max(high,maxi)
     mini=min(low,mini)
     lerange=((maxi-mini)/2)+10*pointsize
    else
     maxii=maxi
     minii=mini
     maxi1=maxi+lerange
     mini1=mini-lerange
     maxi2=maxi+2*lerange
     mini2=mini-2*lerange
     maxi3=maxi+3*lerange
     mini3=mini-3*lerange
    endif
     
    return maxii as "Maxi première heure de cotation", minii as "Mini première heure de cotation", maxi1 as "Maxi1" ,mini1 as "Mini1",maxi2 as "Maxi2" ,mini2 as "Mini2",maxi3 as "Maxi3" ,mini3 as "Mini3"
    
    #71882 quote
    julien1978
    Participant
    Average

    Thank you again for your help!

    I have tried to combine this code with another that i have found on this website in order to make my own custom range box.

    It works pretty well except a little bug: it does not draw properly the last target from below the range (not bug however for the upper target).

    How could i fix this?

    once hh=undefined
    once ll=undefined
    once hh1=undefined
    once ll1=undefined
    once hh2=undefined
    once ll2=undefined
    once hh3=undefined
    once ll3=undefined
    
    starttime = 050000
    endtime = 080000
     
    if intradaybarindex=0 then
    hh = 0
    ll = 0
    alreadydrawn = 0
    endif
     
    if time=starttime then
    startbar=barindex
    endif
     
    if time=endtime then
    endbar=barindex
    endif
     
    if time>=starttime and time<=endtime then
    if high + 5*pipsize>hh then
    hh = high + 5*pipsize
    endif
    if low - 5*pipsize<ll or ll=0 then
    ll = low - 5*pipsize
    endif
    
    lerange=(hh-ll)/2
    else
    hh=hh
    ll=ll
    hh1=hh+lerange
    ll1=ll-lerange
    hh2=hh+2*lerange
    ll2=ll-2*lerange
    hh3=hh+3*lerange
    ll3=ll-3*lerange
    endif
    
    if time>endtime and alreadydrawn=0 then
    drawrectangle(startbar,hh,endbar,ll)
    alreadydrawn=1
    endif
     
    return hh as "Maxi période de cotation", ll as "Mini période de cotation", hh1 as "Maxi1" ,ll1 as "Mini1",hh2 as "Maxi2" ,ll2 as "Mini2",hh3 as "Maxi3" ,ll3 as "Mini3"
    #71883 quote
    julien1978
    Participant
    Average

    In addition to fixing this bug, is there a way to show directly on the indicator (on the graphic) the size of the range in pips as well as the number of pips of each target level?

    Something like this:

    ——- 75 pips (maxi 3)

    ——-50 pips (maxi 2)

    ——- 25 pips (maxi 1)

    ____50 pips (range size)

    ____

    ——- -25 pips (mini 1)

    ——- -50 pips (mini 2)

    etc…

    #71885 quote
    Nicolas
    Keymaster
    Master

    it does not draw properly the last target from below the range (not bug however for the upper target).

    Could you explain please?

    You can add text in front of each line, like I did in this indicator for instance: Fibonacci Pivots Points 4 Hours, Daily, Weekly and Monthly

    #71888 quote
    julien1978
    Participant
    Average

    The bottom of the range target is not drawn properly (it adds some vertical lines with no end). However the upper range targets are drawn correctly. Please see attached picture

    This is not so bad but i am a little nitpicking! 😉

    #71928 quote
    Nicolas
    Keymaster
    Master

    These lines are the lines hh and ll coming from 0 to their new calculated levels. If you do not want to see them, just remove their names from the RETURN instruction.

    #71985 quote
    julien1978
    Participant
    Average

    Sorry Nicolas but it does not seem to work. How can I get rid of the vertical lines coming from zero with keeping all the horizontal ones? (and the box around the range)

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Opening range indicator asian/europe session (with 2 profit targets)


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
julien1978 @julien1978 Participant
Summary

This topic contains 9 replies,
has 2 voices, and was last updated by julien1978
7 years, 8 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/29/2018
Status: Active
Attachments: 2 files
Logo Logo
Loading...