显示几年前每个时间段(例如一月或四季度)的背景颜色
Show background color for every time period (Eg. January or quater) a few years back
我想在图表上显示几年前所有季度的背景颜色。
我有这个工作示例,但是有问题。 for 循环无法正常工作,因为它只绘制去年的背景(而不是为所有年份着色)。
请帮忙。 :)
//// DISPLAY BACKGROUND COLOR FOR EVERY QUATER A FEW YEARS BACK
//@version=4
getMonthNumber(value) =>
currentMonth = month
amountToSubtract = (12 - value) % 12
abs(currentMonth - (currentMonth - amountToSubtract))
getMonth(monthNumber, yearsBack) =>
oneYear = 31556952000 // ms
timestamp(year(timenow - oneYear * yearsBack), month(timenow) - getMonthNumber(monthNumber), 1, 0, 0, 0)
getEndOfDecember(yearsBack) =>
oneYear = 31556952000 // ms
timestamp(year(timenow - oneYear * (yearsBack - 1)), month(timenow) - getMonthNumber(1), 1, 0, 0, 0)
q1 = false
q2 = false
q3 = false
q4 = false
DRAW_YEARS_BACK = 1
for i = 0 to DRAW_YEARS_BACK // PROBLEM: draws only the last year (instead of all)
q1 := time > getMonth(1, i) and time < getMonth(4, i)
q2 := time > getMonth(4, i) and time < getMonth(7, i)
q3 := time > getMonth(7, i) and time < getMonth(10, i)
q4 := time > getMonth(10, i) and time < getEndOfDecember(i)
bgcolor(color = q1 ? color.green : na)
bgcolor(color = q2 ? color.yellow : na)
bgcolor(color = q3 ? color.orange : na)
bgcolor(color = q4 ? color.silver : na)
//@version=4
study("colors")
q = month < 4 ? color.green : month < 7 ? color.yellow : month < 10 ? color.orange : color.silver
bgcolor(q)
好了
我想在图表上显示几年前所有季度的背景颜色。
我有这个工作示例,但是有问题。 for 循环无法正常工作,因为它只绘制去年的背景(而不是为所有年份着色)。
请帮忙。 :)
//// DISPLAY BACKGROUND COLOR FOR EVERY QUATER A FEW YEARS BACK
//@version=4
getMonthNumber(value) =>
currentMonth = month
amountToSubtract = (12 - value) % 12
abs(currentMonth - (currentMonth - amountToSubtract))
getMonth(monthNumber, yearsBack) =>
oneYear = 31556952000 // ms
timestamp(year(timenow - oneYear * yearsBack), month(timenow) - getMonthNumber(monthNumber), 1, 0, 0, 0)
getEndOfDecember(yearsBack) =>
oneYear = 31556952000 // ms
timestamp(year(timenow - oneYear * (yearsBack - 1)), month(timenow) - getMonthNumber(1), 1, 0, 0, 0)
q1 = false
q2 = false
q3 = false
q4 = false
DRAW_YEARS_BACK = 1
for i = 0 to DRAW_YEARS_BACK // PROBLEM: draws only the last year (instead of all)
q1 := time > getMonth(1, i) and time < getMonth(4, i)
q2 := time > getMonth(4, i) and time < getMonth(7, i)
q3 := time > getMonth(7, i) and time < getMonth(10, i)
q4 := time > getMonth(10, i) and time < getEndOfDecember(i)
bgcolor(color = q1 ? color.green : na)
bgcolor(color = q2 ? color.yellow : na)
bgcolor(color = q3 ? color.orange : na)
bgcolor(color = q4 ? color.silver : na)
//@version=4
study("colors")
q = month < 4 ? color.green : month < 7 ? color.yellow : month < 10 ? color.orange : color.silver
bgcolor(q)
好了