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)
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.