0% found this document useful (0 votes)
11 views6 pages

Standards

The document contains a TradingView Pine Script code for an indicator named 'M7 Standards V2', which is designed to visualize specific trading sessions and their statistics. It includes various customizable parameters for session times, colors, and statistics display, allowing traders to analyze market behavior during different trading periods. The script also incorporates functionality for filtering and managing visual elements based on trading conditions and historical data.

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)
11 views6 pages

Standards

The document contains a TradingView Pine Script code for an indicator named 'M7 Standards V2', which is designed to visualize specific trading sessions and their statistics. It includes various customizable parameters for session times, colors, and statistics display, allowing traders to analyze market behavior during different trading periods. The script also incorporates functionality for filtering and managing visual elements based on trading conditions and historical data.

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/ 6

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

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

//@version=5
indicator("M7 Standards V2", shorttitle = "M7 Standards v2",
max_labels_count=500,max_boxes_count =500, overlay=true)

var grp0 = 'TDR Colours'


TIMEZONE = 'America/New_York'

grptz = "M7 Standards Sessions"


preADRCheck = input.bool(true, "",inline="1", group= grptz)
preADR = input.session("1800-1930","PreADR", inline="1", group= grptz)
preADRColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="1",
group=grptz)
preADRBorderColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="1",
group=grptz, tooltip = "Box Color | Border Color")
inADRCheck = input.bool(true, "",inline="2", group= grptz)
inADR = input.session("1930-0200","ADR", inline="2", group= grptz)
inADRColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="2",
group=grptz)
inADRBorderColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="2",
group=grptz, tooltip = "Box Color | Border Color")

preODRCheck = input.bool(true, "",inline="3", group= grptz)


preODR = input.session("0200-0300","PreODR", inline="3", group= grptz)
preODRColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="3",
group=grptz)
preODRBorderColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="3",
group=grptz, tooltip = "Box Color | Border Color")
inODRCheck = input.bool(true, "",inline="4", group= grptz)
inODR = input.session("0300-0830","ODR", inline="4", group= grptz)
inODRColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="4",
group=grptz)
inODRBorderColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="4",
group=grptz, tooltip = "Box Color | Border Color")

preRDRCheck = input.bool(true, "",inline="5", group= grptz)


preRDR = input.session("0830-0930","PreRDR", inline="5", group= grptz)
preRDRColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="5",
group=grptz)
preRDRBorderColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="5",
group=grptz, tooltip = "Box Color | Border Color")
inRDRCheck = input.bool(true, "",inline="6", group= grptz)
inRDR = input.session("0930-1700","RDR", inline="6", group= grptz)
inRDRColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="6",
group=grptz)
inRDRBorderColor = input.color(color.rgb(156, 39, 176, 70), title='', inline="6",
group=grptz, tooltip = "Box Color | Border Color")

stopBodies = input.bool(false, "Stop imbalance at (n) body fills", inline="1")


maxBodies = input.int(defval=10, title='', minval=1, maxval=100, inline="1",
tooltip='Minimum = 1, Maximum = 100')
lookback = input.bool(false, "Lookback period (Days)", inline="2")
lookbackDays = input.int(defval=7, title='', minval=1, maxval=50, inline="2",
tooltip='Minimum = 1, Maximum =500')
groupStat = "TTT Rejection Stats"
showStats = input.bool(true, "Show TTT Rejection Stats", inline="1",
group=groupStat)
showBodyCloseStat = input.bool(true,"Show Body close stat", tooltip = 'shows next
to TTT in (x)', group=groupStat)
showDaysAgo = input.bool(true,"Show how old the M7IB Special is", group=groupStat)
sessText = input.color(color.rgb(17, 2, 14, 27), title='Text ', inline="2",
group=groupStat)
_labelSize = input.string("Small", title='Label Size', options=['Auto', 'Tiny',
'Small', 'Normal', 'Huge'], group=groupStat)
statOffset = input.int(defval=20, title='Offset from the last candle', minval=1,
maxval=100, tooltip='Offset for stats' ,group=groupStat)
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=groupStat)
groupF="Filter"
useFilter = input.bool(false, "Create Filter;", inline="1",group=groupF)
filterMinimumBodyClose = input.int(defval=5, title='Mimimum Body Closes required',
minval=1, maxval=50, inline="2x", tooltip='Have a a mimum body close, as to not
hide recent VIBS that have not been touched' ,group=groupF)
filterRejectionRatio = input.int(defval=3, title='Ratio', minval=1,
maxval=50,inline="1x" ,group=groupF)
filterBodyCloseRatio = input.int(defval=1, title=':', minval=1, maxval=50,
inline="1x", tooltip='Ratio for rejctions, if you choose 1:1, if you have only 5
rejections TTT or less and 5 Body closes, it will remove them' ,group=groupF)

labelSize = _labelSize == "auto" ? size.auto : _labelSize == "Tiny" ? size.tiny :


_labelSize == "Small" ? size.small : _labelSize == "Normal" ? size.normal :
size.huge

lookbackTime = timestamp(year(last_bar_time), month(last_bar_time),


dayofmonth(last_bar_time) -lookbackDays, hour(last_bar_time) , 0)

_extendTDRC = 1 *24

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
var color currentColor = na
var color currentBorderColor =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]

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

inPreADRSession = f_insession(preADR) and preADRCheck


inADRSession = f_insession(inADR) and inADRCheck
inPreODRSession = f_insession(preODR) and preODRCheck
inODRSession = f_insession(inODR) and inODRCheck
inPreRDRSession = f_insession(preRDR) and preRDRCheck
inRDRSession = f_insession(inRDR) and inRDRCheck

inSession = inPreADRSession or inADRSession or inPreODRSession or


inODRSession or inPreRDRSession or inRDRSession
enterSession = inSession and not inSession[1]

if timeframe.isintraday //and (PCchart.barIsVisible() or not showAllHistory)


if enterSession
currentSession := inPreADRSession ? preADR : inADRSession ? inADR :
inPreODRSession ? preODR : inODRSession ? inODR : inPreRDRSession ? preRDR :
inRDRSession ? inRDR : na
currentColor := inPreADRSession ? preADRColor : inADRSession ? inADRColor :
inPreODRSession ? preODRColor : inODRSession ? inODRColor : inPreRDRSession ?
preRDRColor : inRDRSession ? inRDRColor : na
currentBorderColor := inPreADRSession ? preADRBorderColor : inADRSession ?
inADRBorderColor : inPreODRSession ? preODRBorderColor : inODRSession ?
inODRBorderColor : inPreRDRSession ? preRDRBorderColor : inRDRSession ?
inRDRBorderColor : na

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


if (bodyHigh == low[1] and high == prevBodyLow and bodyHigh < prevBodyLow)
//if (open == high[1] and open > open[1] and open<=close and close[1] ==open
and low != close[1] and close[1] >=open[1])
newbox1 = box.new(bar_index-1, high, bar_index + _extendTDRC,
bodyHigh,text = "", text_size =labelSize, text_color =sessText, text_halign =
text.align_right, xloc=xloc.bar_index, bgcolor=currentColor, border_color =
currentBorderColor )
box.set_extend(newbox1, extend.right)

array.push(l1,newbox1 )
array.push(c1, 0)
array.push(cTTT1, -2)
if ( bodyLow == high[1] and low == prevBodyHigh and bodyLow > prevBodyHigh)
newbox1 = box.new(bar_index-1, bodyLow, bar_index + _extendTDRC, low,text
= "", text_size =labelSize, text_color =sessText, text_halign = text.align_right,
xloc=xloc.bar_index, bgcolor=currentColor, border_color = currentBorderColor )
box.set_extend(newbox1, extend.right)
array.push(l1,newbox1 )
array.push(c1, 0)
array.push(cTTT1, -2)
var box myBox = na
var label myLabel = na
var int myCount = na
var int myCountTTT = na

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

myBox := array.get(l1, i)
myCountTTT := array.get(cTTT1, i)
boxstart = box.get_left(myBox)
if (stopBodies and maxBodies >0 and myCount <maxBodies ) or
(stopBodies == false)
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 bodyHigh > boxTop)

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 )
if (myCount == maxBodies and stopBodies)
box.set_right(myBox, bar_index)
box.set_extend(myBox, extend.none)

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 = ""
var int[] removeArray = array.new_int(0)
RoundDown(number, decimals) =>
factor = math.pow(10, decimals)
math.floor(number * factor) / factor
if barstate.islast and showStats

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)

dateago := ""
if useFilter and myCount >= filterMinimumBodyClose and ( myCountTTT
/ myCount) < (filterRejectionRatio/filterBodyCloseRatio) /// remove if ratio is
worse
x=11
myBox.set_bgcolor(color =color.rgb(0,0,0,100))
myBox.set_border_color(color =color.rgb(0,0,0,100))
myBox.set_text_color(color.rgb(0,0,0,90))
box.set_text(myBox, str.tostring(myCountTTT) +" TTT ("
+str.tostring(myCount)+")")
//arraySize2 := arraySize2-1
else

days =RoundDown((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 showDaysAgo
dateago += " . "+str.tostring(days ) +" d
"//+str.tostring(hours)+"h"

boxBottom :=
box.get_bottom(myBox) /////////////////////////////////////////
//////////////////
boxTop :=
box.get_top(myBox) ////////////////////////////////////////////
///////////////
bb = boxTop > boxBottom ? boxBottom :boxTop
bbIndex := array.indexof(bl1, bb)
bbLastIndex:=na
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 //+
math.round(math.random(10,90,1))
//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)

if (stopBodies and maxBodies >0 and myCount <maxBodies) or


(stopBodies == false)
box.set_right(myBox, timex)

You might also like