ORB and Camarrila SR [VB]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bhosalevishal

//@version=5
indicator(title="ORB and Camarrila SR [VB]", shorttitle="ORB & SR [VB]", overlay=true)

showCamarilla     = input(group="Camarilla", inline="1", title='Show Camarilla\'s SR', defval=true)

showORB     = input(group="Open Range Breakout", inline="1", title='Show Open Range Breakout', defval=true)

normal_start = timestamp(year(time), month(time), dayofmonth(time), 09, 15)
normal_end = timestamp(year(time), month(time), dayofmonth(time), 15, 30)

// CONSTANTS
var lTransp             = 50
var color blue          = #0000FF
var color blueColor      = color.new(blue, lTransp)
var color greenColor        = color.new(color.green, lTransp)
var color redColor        = color.new(color.red, lTransp)
var color purpleColor     = color.new(color.purple, lTransp)
var color blackColor    = color.new(color.black, lTransp)
var color limeColor       = color.new(color.lime, lTransp)
var color grayColor    = color.new(color.gray, lTransp)


var __intraday = true
var newHigh = 0.0
var newLow  = 0.0
var dayOpen = 0.0
var diffRange = 0.0

// Previous Day HLOC
[pDayO, pDayH, pDayL, pDayC] = request.security(syminfo.tickerid, 'D', [open[1], high[1], low[1], close[1]], barmerge.gaps_off, barmerge.lookahead_on)

// Today 15 minutes HLOC
[dayO, dayH, dayL, dayC] = request.security(syminfo.tickerid, '15', [open, high, low, close], barmerge.gaps_off, barmerge.lookahead_on)

// Today day open
[dO] = request.security(syminfo.tickerid, 'D', [open], barmerge.gaps_off, barmerge.lookahead_on)


if session.ismarket and not session.ismarket[1]
    newHigh := dayH
    newLow := dayL
    dayOpen := dO
    newHigh, newLow, dayOpen
diffRange := (newHigh - newLow) / 2.35

// calculate camarrila SRs    
calCamSR(H, L, C) =>
    Pivot_Median = (H + L + C) / 3
    Pivot_Range = H - L
    
    R1 = C + Pivot_Range  * 1.1 / 12.0
    S1 = C - Pivot_Range  * 1.1 / 12.0
    
    R2 = C + Pivot_Range  * 1.1 / 6.0
    S2 = C - Pivot_Range  * 1.1 / 6.0
    
    R3 = C + Pivot_Range  * 1.1 / 4.0
    S3 = C - Pivot_Range  * 1.1 / 4.0
    
    R4 = C + Pivot_Range  * 1.1 / 2.0
    S4 = C - Pivot_Range  * 1.1 / 2.0
    
    [R4, R3, R2, R1, S1, S2, S3, S4]    
    
// TODAYS CAMARRILA SR CALCULATIONS 
[camR4, camR3, camR2, camR1, camS1, camS2, camS3, camS4] = calCamSR(pDayH, pDayL, pDayC)    
    
plot(showORB?dayOpen:na, color=limeColor, style=plot.style_stepline, linewidth=2)

var upper1 = plot(showORB?newHigh:na, color=purpleColor, style=plot.style_stepline, linewidth=2)
var upper2 = plot(showORB?newHigh+diffRange:na, color=redColor, style=plot.style_stepline, linewidth=2)
fill(upper1, upper2, color=color.new(color.gray, 90))

var lower1 = plot(showORB?newLow:na, color=purpleColor, style=plot.style_stepline, linewidth=2)
var lower2 = plot(showORB?newLow-diffRange:na, color=greenColor, style=plot.style_stepline, linewidth=2)
fill(lower1, lower2, color=color.new(color.gray, 95))



// ********** Camarrila SR ********** //

plot(showCamarilla?camR4:na, color=blueColor, linewidth=1, style=plot.style_circles)
plot(showCamarilla?camR3:na, color=blueColor, linewidth=1, style=plot.style_circles)
plot(showCamarilla?camR2:na, color=blueColor, linewidth=1, style=plot.style_circles)
plot(showCamarilla?camR1:na, color=blueColor, linewidth=1, style=plot.style_circles)

plot(showCamarilla?camS4:na, color=blueColor, linewidth=1, style=plot.style_circles)
plot(showCamarilla?camS3:na, color=blueColor, linewidth=1, style=plot.style_circles)
plot(showCamarilla?camS2:na, color=blueColor, linewidth=1, style=plot.style_circles)
plot(showCamarilla?camS1:na, color=blueColor, linewidth=1, style=plot.style_circles)

