OPEN-SOURCE SCRIPT
4-Day Average Initial Balance (RTH)

//version=5
indicator("4-Day Average Initial Balance (RTH)", overlay=true, max_labels_count=500, max_lines_count=500)
//===================== Inputs =====================
ibBars = input.int(12, "IB length in bars (5-min = 12 bars)", minval=1)
sessRTH = input.session("0930-1600", "RTH Session (Exchange Time)")
bgColor = input.color(color.new(color.blue, 70), "Background Color")
//===================== Session Logic =====================
inSession = time(timeframe.period, sessRTH) != 0
newSession = inSession and not inSession[1]
//===================== IB Tracking =====================
var float ibHigh = na
var float ibLow = na
var int ibBarCount = 0
var bool ibDone = false
if newSession
ibHigh := na
ibLow := na
ibBarCount := 0
ibDone := false
if inSession and not ibDone
ibHigh := na(ibHigh) ? high : math.max(ibHigh, high)
ibLow := na(ibLow) ? low : math.min(ibLow, low)
ibBarCount += 1
if ibBarCount >= ibBars
ibDone := true
//===================== Store Last 4 IB Ranges =====================
var float ib1 = na
var float ib2 = na
var float ib3 = na
var float ib4 = na
todayIBRange = ibDone ? ibHigh - ibLow : na
justCompletedIB = ibDone and not ibDone[1]
if justCompletedIB and not na(todayIBRange)
ib4 := ib3
ib3 := ib2
ib2 := ib1
ib1 := todayIBRange
//===================== Average of Last 4 =====================
sum = 0.0
count = 0
if not na(ib1)
sum += ib1
count += 1
if not na(ib2)
sum += ib2
count += 1
if not na(ib3)
sum += ib3
count += 1
if not na(ib4)
sum += ib4
count += 1
avgIB = count > 0 ? sum / count : na
//===================== Display Number on Right =====================
var table t = table.new(position.top_right, 1, 1, frame_color=color.new(color.black, 0), frame_width=1)
if barstate.islast
txt = na(avgIB) ? "Avg IB(4d): n/a" : "Avg IB(4d): " + str.tostring(avgIB, "#.00") + " pts"
table.cell(t, 0, 0, txt, text_color=color.white, text_halign=text.align_right, bgcolor=bgColor)
indicator("4-Day Average Initial Balance (RTH)", overlay=true, max_labels_count=500, max_lines_count=500)
//===================== Inputs =====================
ibBars = input.int(12, "IB length in bars (5-min = 12 bars)", minval=1)
sessRTH = input.session("0930-1600", "RTH Session (Exchange Time)")
bgColor = input.color(color.new(color.blue, 70), "Background Color")
//===================== Session Logic =====================
inSession = time(timeframe.period, sessRTH) != 0
newSession = inSession and not inSession[1]
//===================== IB Tracking =====================
var float ibHigh = na
var float ibLow = na
var int ibBarCount = 0
var bool ibDone = false
if newSession
ibHigh := na
ibLow := na
ibBarCount := 0
ibDone := false
if inSession and not ibDone
ibHigh := na(ibHigh) ? high : math.max(ibHigh, high)
ibLow := na(ibLow) ? low : math.min(ibLow, low)
ibBarCount += 1
if ibBarCount >= ibBars
ibDone := true
//===================== Store Last 4 IB Ranges =====================
var float ib1 = na
var float ib2 = na
var float ib3 = na
var float ib4 = na
todayIBRange = ibDone ? ibHigh - ibLow : na
justCompletedIB = ibDone and not ibDone[1]
if justCompletedIB and not na(todayIBRange)
ib4 := ib3
ib3 := ib2
ib2 := ib1
ib1 := todayIBRange
//===================== Average of Last 4 =====================
sum = 0.0
count = 0
if not na(ib1)
sum += ib1
count += 1
if not na(ib2)
sum += ib2
count += 1
if not na(ib3)
sum += ib3
count += 1
if not na(ib4)
sum += ib4
count += 1
avgIB = count > 0 ? sum / count : na
//===================== Display Number on Right =====================
var table t = table.new(position.top_right, 1, 1, frame_color=color.new(color.black, 0), frame_width=1)
if barstate.islast
txt = na(avgIB) ? "Avg IB(4d): n/a" : "Avg IB(4d): " + str.tostring(avgIB, "#.00") + " pts"
table.cell(t, 0, 0, txt, text_color=color.white, text_halign=text.align_right, bgcolor=bgColor)
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.