0% found this document useful (0 votes)
4 views

Vcs

This document contains source code for a trading indicator called 'M7 DRCs' written in Pine Script, which is used for analyzing market sessions and displaying various statistical data. It includes customizable settings for session times, colors, and display options, as well as functions for determining market conditions. The code is structured to handle different market sessions, calculate levels, and draw boxes for visual representation on charts.

Uploaded by

Andrew Sharrock
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Vcs

This document contains source code for a trading indicator called 'M7 DRCs' written in Pine Script, which is used for analyzing market sessions and displaying various statistical data. It includes customizable settings for session times, colors, and display options, as well as functions for determining market conditions. The code is structured to handle different market sessions, calculate levels, and draw boxes for visual representation on charts.

Uploaded by

Andrew Sharrock
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// © Jerryg7

// This base source code is subject to the terms of the Mozilla Public License 2.0
at https://mozilla.org/MPL/2.0/
// © TheMas7er and bmistiaen

//this verion is from version 51 of the 294,54 branch that is adding AMR and time
filtering
//@version=5
indicator('M7 DRCs', overlay=true, max_lines_count=500, max_boxes_count=500,
max_labels_count=500)
//import PineCoders/VisibleChart/4 as PCchart

var GRP2 = "General Settings"


//lines
TIMEZONE = 'America/New_York'
showRegular = input.bool(true, 'Regular',
group=GRP2, inline='session', tooltip='Show Regular and/or After and/or
Overnight session')
showAfter = input.bool(true, 'After',
group=GRP2, inline='session')
showOvernight = input.bool(true, 'Overnight',
group=GRP2, inline='session')

// Hard coded inputs for retrace and target boxes


//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////

grptz = "Colorss"
var box[] boxA = array.new_box(0)
inADRColor = input.color(color.rgb(66, 222, 250, 85), title='ADR', inline="2",
group=grptz)
inADRBorderColor = input.color(color.rgb(66, 222, 250, 85), title='border',
inline="2", group=grptz, tooltip = "Box Color | Border Color")

inODRColor = input.color(color.rgb(66, 222, 250, 85), title='ODR', inline="4",


group=grptz)
inODRBorderColor = input.color(color.rgb(66, 222, 250, 85), title='border',
inline="4", group=grptz, tooltip = "Box Color | Border Color")
inRDRColor = input.color(color.rgb(66, 222, 250, 85), title='RDR', inline="6",
group=grptz)
inRDRBorderColor = input.color(color.rgb(66, 222, 250, 85), title='border',
inline="6", group=grptz, tooltip = "Box Color | Border Color")

groupX="Extras"

sessText = input.color(color.rgb(17, 2, 14, 27), title='Text ', inline="2",


group=groupX)
_labelSize = input.string("Small", title='Label Size', options=['Auto', 'Tiny',
'Small', 'Normal', 'Huge'], group=groupX)
labelSize = _labelSize == "auto" ? size.auto : _labelSize == "Tiny" ? size.tiny :
_labelSize == "Small" ? size.small : _labelSize == "Normal" ? size.normal :
size.huge

lookback = input.bool(true, "Lookback period (Days)", inline="2")


lookbackDays = input.int(defval=5, title='', minval=1, maxval=50, inline="2",
tooltip='Minimum = 1, Maximum =500')

showBodyCloseStat = input.bool(true,"Show weak rejections", tooltip = 'shows next


to TTT in [x]')

showDaysAgo = input.bool(true,"Show how old the DRC is")

statOffset = input.int(defval=50, title='Offset from the last candle', minval=1,


maxval=50, tooltip='How far after the Last candle to display
Statistics' ,group=groupX)
duplicatesCandles = input.int(defval=4, title='Offset for Stacked imbalance',
minval=1, maxval=50, tooltip='Offset for the TTT stats in No. of
candles' ,group=groupX)

var GRP4= "Time Settings"


regularTime = input.session('0930-1030', 'RDR Time', group=GRP4)
regularExtend = input.session('1030-1600', 'RDR Lines Time', group=GRP4)
afterTime = input.session('1930-2030', 'ADR Time', group=GRP4)
afterExtend = input.session('2030-0200', 'ADR Lines Time', group=GRP4)
overnightTime = input.session('0300-0400', 'ODR Time', group=GRP4)
overnightExtend = input.session('0400-0830', 'ODR Lines Time', group=GRP4)
var color currentColor = na
var color currentBorderColor =na
var box[] l1 = array.new_box(0)
var int[] c1 = array.new_int(0)
var int[] cTTT1 = array.new_int(0)
var label[] la1 = array.new_label(0)

var float bodyLow = na


var float bodyHigh = na
var float prevBodyLow = na
var float prevBodyHigh = na
var float boxTop = na
var float boxBottom = na
var string currentSession = na
float val=na
if close > open
bodyLow := open
bodyHigh := close
else
bodyLow := close
bodyHigh := open

if close[1] > open[1]


prevBodyLow := open[1]
prevBodyHigh := close[1]
else
prevBodyLow := close[1]
prevBodyHigh := open[1]
var float xHigh = na
var float xLow = na

_extendTDRC = 1 *24
lookbackTime = timestamp(year(last_bar_time), month(last_bar_time),
dayofmonth(last_bar_time) -lookbackDays, hour(last_bar_time) , 0)
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
var float idrrange = na
var int box1barindexstart=na

// } Inputs

// Variables {
var int startTime = na
var int endTime = na
var int leaveRegularSessionTime = na

var line lowrdrl = na


var line highrdrl = na
var line lowridrl = na
var line highridrl = na
var line leftrdrl = na
var line rightrdrl = na
var line middlerdrl = na
var line middleridrl = na
var line drLineOpen = na
var box bgBox = na

var line[] stdLines = array.new<line>()


var float[] stdLevels = array.new<float>()
var label[] stdLabels = array.new<label>()

var float rdrlow = na


var float rdrhigh = na
var float ridrlow = na
var float ridrhigh = na
var float rdrmiddle = na
var float ridrmiddle = na
var float sessionOpen = na
var float sessionClose = na

var float regidrlow = na


var float regidrhigh = na
var float sessionHigh = na
var float sessionLow = na

var bool ecodaymatch = false


//variables for retrace and target levels Tx and Lx, also passing in year, month,
dayofweek into timestamp
//timings
//yy=input.int(2023, title="input year", group=GRP1)

var bool use_m5 = false

// } Variables

// Functions {
f_insession(_session) =>
not na(time(timeframe.period, _session, TIMEZONE))

f_inboxsession(sessionTime, sessionTimeZone="America/New_York") =>


not na(time(timeframe.period, sessionTime, sessionTimeZone))

// } Functions

[m5_open, m5_high, m5_low, m5_close] = request.security(syminfo.tickerid, '5',


[open, high, low, close], lookahead = barmerge.lookahead_on)

open_value = use_m5 ? m5_open : open


high_value = use_m5 ? m5_high : high
low_value = use_m5 ? m5_low : low
close_value = use_m5 ? m5_close : close

inRegularSession = f_insession(regularTime) and showRegular


inRegularExtend = f_insession(regularExtend) and showRegular
inAfterSession = f_insession(afterTime) and showAfter
inAfterExtend = f_insession(afterExtend) and showAfter
inOvernightSession = f_insession(overnightTime) and showOvernight
inOvernightExtend = f_insession(overnightExtend) and showOvernight

inSession = inRegularSession or inOvernightSession or inAfterSession


inExtend = inRegularExtend or inOvernightExtend or inAfterExtend

enterSession = inSession and not inSession[1]


enterExtend = inExtend and not inExtend[1]

leaveRegularSession = not inRegularSession and inRegularSession[1] or


(not inOvernightSession and inOvernightSession[1]) or (not inAfterSession and
inAfterSession[1])
enterRegularExtend = inRegularExtend and not inRegularExtend[1] or
(inOvernightExtend and not inOvernightExtend[1]) or (inAfterExtend and not
inAfterExtend[1])
leavingRegularExtend = inRegularExtend[1] and not inRegularExtend or
(inOvernightExtend[1] and not inOvernightExtend) or (inAfterExtend[1] and not
inAfterExtend)
leaveRegularSessionTime := leaveRegularSession? time:leaveRegularSessionTime[1]

if lookback == false or ( time >= lookbackTime and time < timenow)


if timeframe.isintraday //and (PCchart.barIsVisible() or not showAllHistory)
if enterSession
currentSession := inRegularSession ? regularTime : inOvernightSession ?
overnightTime : inAfterSession ? afterTime : na
currentColor := inAfterSession ? inADRColor : inOvernightSession ?
inODRColor : inRegularSession ? inRDRColor : na
currentBorderColor := inAfterSession ? inADRBorderColor :
inOvernightSession ? inODRBorderColor : inRegularSession ? inRDRBorderColor : na

// array.clear(RetraceArray)
else if enterExtend
currentSession := inRegularExtend ? regularExtend : inOvernightExtend ?
overnightExtend : inAfterExtend ? afterExtend : na
if inSession
if not inSession[1]
startTime := time
sessionOpen := open_value
rdrhigh := high_value
rdrlow := low_value
ridrlow := math.min(open_value, close_value)
ridrhigh := math.max(open_value, close_value)
//Initialize DR Confirm states added May 31 JG

// Intialize retrace and target boxes

// Calculate levels
rdrhigh := math.max(high_value, rdrhigh)
rdrlow := math.min(low_value, rdrlow)
ridrhigh := math.max(open_value, close_value, ridrhigh)
ridrlow := math.min(open_value, close_value, ridrlow)
rdrmiddle := math.avg(rdrhigh, rdrlow)
ridrmiddle := math.avg(ridrhigh, ridrlow)
//added calc levels for retrace boxxes; intent is to draw boxes for
pullback based on idrhigh pluse or minus step size offset
(rdrhigh+offset*idrrange*Ln)
idrrange := (ridrhigh-ridrlow)

if(leavingRegularExtend )
newbox1 = box.new(bar_index, rdrhigh, bar_index + 10, ridrhigh, text =
"helllo", text_size =labelSize, text_color =sessText,text_halign =
text.align_right, xloc=xloc.bar_index, bgcolor=currentColor, border_color =
currentBorderColor ,extend = extend.right )

array.push(l1,newbox1)
array.push(c1, 0)
array.push(cTTT1, 0)
newbox2 = box.new(bar_index, ridrlow, bar_index + 10, rdrlow, text =
"helllo", text_size =labelSize,text_color =sessText, text_halign =
text.align_right, xloc=xloc.bar_index, bgcolor=currentColor, border_color =
currentBorderColor,extend = extend.right )

array.push(l1,newbox2 )
array.push(c1, 0)
array.push(cTTT1, 0)

var box myBox = na


var int myCount = na
var int myCountTTT = na

var levels = array.new_float(0, initial_value = na)

if array.size(l1) > 0
for i = 0 to array.size(l1)-1
if i <= array.size(l1)-1 and array.size(l1) > 0
myCount := array.get(c1, i)

myBox := array.get(l1, i)
myCountTTT := array.get(cTTT1, i)
b1 = box.get_top(myBox)
b2 = box.get_bottom(myBox)
if b1>b2
boxTop := b1
boxBottom := b2
else
boxTop := b2
boxBottom := b1
if(bodyLow > boxBottom and bodyLow < boxTop and bodyHigh >boxTop) or
(low > boxBottom and low < boxTop and bodyHigh >boxTop) or (bodyHigh < boxTop and
bodyHigh > boxBottom and bodyLow < boxBottom) or (high < boxTop and high >
boxBottom and bodyLow < boxBottom)
//mylabelxx = label.new(time,low,"BT:"+str.tostring(boxTop)+"
BB:"+str.tostring(boxBottom)+"l"+str.tostring(bodyLow)+"
h:"+str.tostring(bodyHigh),xloc.bar_time,yloc.abovebar,color = color.blue, style =
label.style_circle)
myCount :=myCount +1
if(open == boxTop or close == boxTop or open == boxBottom or
close==boxBottom)
myCountTTT := myCountTTT +1
//mylabelxx = label.new(time,low,"BT:"+str.tostring(boxTop)+"
BB:"+str.tostring(boxBottom)+"o"+str.tostring(open)+"
c:"+str.tostring(close),xloc.bar_time,yloc.abovebar,color = color.blue, style =
label.style_circle)

if((high == boxTop and high !=close and high != open) or (low ==


boxTop and low !=close and low !=open ) or (high == boxBottom and high !=close
and high != open) or (low==boxBottom and low !=close and low!= open))
myCountTTT := myCountTTT +1
//mylabelxx = label.new(time,low,"BT"+str.tostring(boxTop)+"
BB:"+str.tostring(boxBottom),xloc.bar_time,yloc.belowbar,color = color.red, style =
label.style_circle)

array.set(c1, i, myCount )
array.set(cTTT1, i, myCountTTT )

var int myCount2 = na

var float[] bl1 = array.new_float(0)


var int buffer = 0
var int bbIndex=na
var int bbLastIndex=na
var int timex = na
var string dateago = ""
RoundDown(number, decimals) =>
factor = math.pow(10, decimals)
math.floor(number * factor) / factor
if barstate.islast

array.clear(bl1)
if array.size(l1) > 0
for i = 0 to array.size(l1)-1
if i <= array.size(l1)-1 and array.size(l1) > 0
myBox := array.get(l1, i)
myCount := array.get(c1, i)
myCountTTT := array.get(cTTT1, i)
boxstart = box.get_left(myBox)
boxTop :=
box.get_top(myBox) ///////////////////////////////////////////////
////////////
boxBottom :=
box.get_bottom(myBox) /////////////////////////////////////////
//////////////////
bb= boxTop > boxBottom ?
boxBottom :boxTop /////////////////////////////////////////////////////
//
bbIndex := array.indexof(bl1, bb)
bbLastIndex:=na
dateago := " . "

days =RoundDown((last_bar_index - boxstart)/276 ,0)


hours =(last_bar_index - boxstart)%276
if(days >= lookbackDays and hours >1 and lookback)
box.delete(myBox)
array.remove(l1, i)
array.remove(cTTT1, i)
array.remove(c1, i)

if bbIndex >0 ///// exists

array.sort(bl1,order.ascending)
bbIndex := array.indexof(bl1, bb)
bbLastIndex := array.lastindexof(bl1, bb)
diff = bbLastIndex - bbIndex
buffer := duplicatesCandles * (diff+1)

else
buffer :=0

array.push(bl1, bb)
////////////////////
///////////////////////////////////////
timex := bar_index+statOffset +buffer
//if array.includes(boxLevels, boxHigh)
//array.includes(levels, value)
if showBodyCloseStat
if buffer > 0
box.set_text(myBox, str.tostring(myCountTTT) +" T ["
+str.tostring(myCount)+"]" +dateago)
else
box.set_text(myBox, str.tostring(myCountTTT) +" T ["
+str.tostring(myCount)+"]" +dateago)
else
box.set_text(myBox, str.tostring(myCountTTT) +" T" +dateago)
//array.set(la1, i, myLabel) // this was added

box.set_right(myBox, timex)

You might also like