"//@version=5
indicator("20.1) Refined Flower and Fire tbl Multi-Time Frame", overlay=true, max_bars_back=500)
// Function to compute 'Flower' condition
flower_condition_tf() =>
rsi9 = ta.rsi(close, 9)
ema20_high = ta.ema(high, 20)
rma20_low = ta.rma(low, 20)
Flower = ta.crossover(rsi9, 30) and ema20_high < rma20_low
Flower
// Function to get last Flower time and price in higher time frame
flower_info() =>
Flower = flower_condition_tf()
lastTime = ta.valuewhen(Flower, time, 0)
lastPrice = ta.valuewhen(Flower, close, 0)
[lastTime, lastPrice]
// Function to compute 'Fire' condition
fire_condition_tf() =>
rsi9 = ta.rsi(close, 9)
Fire = ta.crossover(rsi9, 90)
Fire
// Function to get last Fire time and price in higher time frame
fire_info() =>
Fire = fire_condition_tf()
lastTime = ta.valuewhen(Fire, time, 0)
lastPrice = ta.valuewhen(Fire, close, 0)
[lastTime, lastPrice]
// Function to format the timestamp
formatTime(ts, isIntraday) =>
yr = year(ts)
mnth = month(ts)
day = dayofmonth(ts)
if isIntraday
hr = hour(ts)
min = minute(ts)
str.format("{0}-{1}-{2} {3}:{4}", str.tostring(day, '00'), str.tostring(mnth, '00'), str.tostring(yr), str.tostring(hr, '00'), str.tostring(min, '00'))
else
str.format("{0}-{1}-{2}", str.tostring(day, '00'), str.tostring(mnth, '00'), str.tostring(yr))
// Function to process each time frame
process_time_frame(tf, tf_label, row) =>
// Flower info
[lastFlowerTime, lastFlowerPrice] = request.security(syminfo.tickerid, tf, flower_info(), lookahead=barmerge.lookahead_off)
// Fire info
[lastFireTime, lastFirePrice] = request.security(syminfo.tickerid, tf, fire_info(), lookahead=barmerge.lookahead_off)
code
Assistant
if barstate.islast
table.cell(myTable, 0, row, tf_label, text_color=color.black)
// Flower data
if not na(lastFlowerTime)
table.cell(myTable, 1, row, "🌸", text_color=color.black)
table.cell(myTable, 2, row, formatTime(lastFlowerTime, tf == '60'), text_color=color.black)
table.cell(myTable, 3, row, str.format("{0,number,#.00}", lastFlowerPrice), text_color=color.black)
else
table.cell(myTable, 1, row, "No Data", text_color=color.black)
table.cell(myTable, 2, row, "N/A", text_color=color.black)
table.cell(myTable, 3, row, "N/A", text_color=color.black)
// Fire data
if not na(lastFireTime)
table.cell(myTable, 4, row, "🔥", text_color=color.black)
table.cell(myTable, 5, row, formatTime(lastFireTime, tf == '60'), text_color=color.black)
table.cell(myTable, 6, row, str.format("{0,number,#.00}", lastFirePrice), text_color=color.black)
else
table.cell(myTable, 4, row, "No Data", text_color=color.black)
table.cell(myTable, 5, row, "N/A", text_color=color.black)
table.cell(myTable, 6, row, "N/A", text_color=color.black)
// Process each time frame
process_time_frame('60', "1H", 1)
process_time_frame('D', "1D", 2)
process_time_frame('W', "1W", 3)
process_time_frame('M', "1M", 4)
// Plot 'Flower' symbols on the current chart's time frame
rsi9 = ta.rsi(close, 9)
ema20_high = ta.ema(high, 20)
rma20_low = ta.rma(low, 20)
Flower = ta.crossover(rsi9, 30) and ema20_high < rma20_low
plotshape(Flower, location=location.belowbar, color=color.yellow, style=shape.labelup, text="🌸", title="Flower")
// Plot 'Fire' symbols on the current chart's time frame
Fire = ta.crossover(rsi9, 90)
plotshape(Fire, location=location.abovebar, color=color.red, style=shape.labeldown, text="🔥", title="Fire")"
abhi ye code is for 1H 1D 1W 1M - > extend it for 1min 3min 5min 15min 30min 2H 4H 3M 6M 12M
Certainly! Below is the refined Pine Script code that extends your existing indicator to include additional time frames: 1m, 3m, 5m, 15m, 30m, 2H, 4H, 3M, 6M, and 12M. The table has been expanded to accommodate these new time frames, ensuring all relevant data is displayed seamlessly.
pinescript
//@version=5
indicator("20.1) Refined Flower and Fire tbl Multi-Time Frame", overlay=true, max_bars_back=500)
// Function to compute 'Flower' condition
flower_condition_tf() =>
rsi9 = ta.rsi(close, 9)
ema20_high = ta.ema(high, 20)
rma20_low = ta.rma(low, 20)
Flower = ta.crossover(rsi9, 30) and ema20_high < rma20_low
Flower
// Function to get last Flower time and price in higher time frame
flower_info() =>
Flower = flower_condition_tf()
lastTime = ta.valuewhen(Flower, time, 0)
lastPrice = ta.valuewhen(Flower, close, 0)
[lastTime, lastPrice]
// Function to compute 'Fire' condition
fire_condition_tf() =>
rsi9 = ta.rsi(close, 9)
Fire = ta.crossover(rsi9, 90)
Fire
// Function to get last Fire time and price in higher time frame
fire_info() =>
Fire = fire_condition_tf()
lastTime = ta.valuewhen(Fire, time, 0)
lastPrice = ta.valuewhen(Fire, close, 0)
[lastTime, lastPrice]
// Function to format the timestamp
formatTime(ts, isIntraday) =>
yr = year(ts)
mnth = month(ts)
day = dayofmonth(ts)
if isIntraday
hr = hour(ts)
min = minute(ts)
// Ensure two digits for day, month, hour, and minute
str_day = str.pad_left(str.tostring(day), 2, "0")
str_mnth = str.pad_left(str.tostring(mnth), 2, "0")
str_hr = str.pad_left(str.tostring(hr), 2, "0")
str_min = str.pad_left(str.tostring(min), 2, "0")
str.format("{0}-{1}-{2} {3}:{4}", str_day, str_mnth, str.tostring(yr), str_hr, str_min)
else
// Ensure two digits for day and month
str_day = str.pad_left(str.tostring(day), 2, "0")
str_mnth = str.pad_left(str.tostring(mnth), 2, "0")
str.format("{0}-{1}-{2}", str_day, str_mnth, str.tostring(yr))
// Create table with extended rows for additional time frames
// Total rows: Header (0) + 14 time frames (1-14)
var table myTable = table.new(position.top_right, 7, 15, bgcolor=color.white, frame_color=color.black, frame_width=1)
// Add table headers
if barstate.isfirst
table.cell(myTable, 0, 0, "Time Frame", text_color=color.black, bgcolor=color.gray)
table.cell(myTable, 1, 0, "Flower Event", text_color=color.black, bgcolor=color.gray)
table.cell(myTable, 2, 0, "Flower Date/Time", text_color=color.black, bgcolor=color.gray)
table.cell(myTable, 3, 0, "Flower LTP", text_color=color.black, bgcolor=color.gray)
table.cell(myTable, 4, 0, "Fire Event", text_color=color.black, bgcolor=color.gray)
table.cell(myTable, 5, 0, "Fire Date/Time", text_color=color.black, bgcolor=color.gray)
table.cell(myTable, 6, 0, "Fire LTP", text_color=color.black, bgcolor=color.gray)
// Function to process each time frame
process_time_frame(tf, tf_label, row) =>
// Determine if the time frame is intraday
is_intraday = tf == '1' or tf == '3' or tf == '5' or tf == '15' or tf == '30' or tf == '60' or tf == '120' or tf == '240'
// Flower info
[lastFlowerTime, lastFlowerPrice] = request.security(syminfo.tickerid, tf, flower_info(), lookahead=barmerge.lookahead_off)
// Fire info
[lastFireTime, lastFirePrice] = request.security(syminfo.tickerid, tf, fire_info(), lookahead=barmerge.lookahead_off)
if barstate.islast
// Time Frame Label
table.cell(myTable, 0, row, tf_label, text_color=color.black)
// Flower data
if not na(lastFlowerTime)
table.cell(myTable, 1, row, "🌸", text_color=color.black)
table.cell(myTable, 2, row, formatTime(lastFlowerTime, is_intraday), text_color=color.black)
table.cell(myTable, 3, row, str.format("{0,number,#.00}", lastFlowerPrice), text_color=color.black)
else
table.cell(myTable, 1, row, "No Data", text_color=color.black)
table.cell(myTable, 2, row, "N/A", text_color=color.black)
table.cell(myTable, 3, row, "N/A", text_color=color.black)
// Fire data
if not na(lastFireTime)
table.cell(myTable, 4, row, "🔥", text_color=color.black)
table.cell(myTable, 5, row, formatTime(lastFireTime, is_intraday), text_color=color.black)
table.cell(myTable, 6, row, str.format("{0,number,#.00}", lastFirePrice), text_color=color.black)
else
table.cell(myTable, 4, row, "No Data", text_color=color.black)
table.cell(myTable, 5, row, "N/A", text_color=color.black)
table.cell(myTable, 6, row, "N/A", text_color=color.black)
// Process each time frame
// Intraday Time Frames
process_time_frame('1', "1m", 1)
process_time_frame('3', "3m", 2)
process_time_frame('5', "5m", 3)
process_time_frame('15', "15m", 4)
process_time_frame('30', "30m", 5)
process_time_frame('60', "1H", 6)
process_time_frame('120', "2H", 7)
process_time_frame('240', "4H", 8)
// Daily and Beyond Time Frames
process_time_frame('D', "1D", 9)
process_time_frame('W', "1W", 10)
process_time_frame('M', "1M", 11)
process_time_frame('3M', "3M", 12)
process_time_frame('6M', "6M", 13)
process_time_frame('12M', "12M", 14)
// Plot 'Flower' symbols on the current chart's time frame
rsi9 = ta.rsi(close, 9)
ema20_high = ta.ema(high, 20)
rma20_low = ta.rma(low, 20)
Flower = ta.crossover(rsi9, 30) and ema20_high < rma20_low
plotshape(Flower, location=location.belowbar, color=color.yellow, style=shape.labelup, text="🌸", title="Flower")
// Plot 'Fire' symbols on the current chart's time frame
Fire = ta.crossover(rsi9, 90)
plotshape(Fire, location=location.abovebar, color=color.red, style=shape.labeldown, text="🔥", title="Fire")
Key Enhancements Explained
Expanded Table Rows:
The table was initially set up with 5 rows (0 to 4). To accommodate the additional 10 time frames, the table has been expanded to 15 rows (0 to 14), where:
Each time frame is processed with a unique row number to ensure accurate placement within the table.
Dynamic Date/Time Formatting:
The formatTime function intelligently formats the timestamp based on whether the time frame is intraday or not.
Intraday time frames display both date and time (e.g., 01-09-2023 14:30), while non-intraday time frames display only the date (e.g., 01-09-2023).
Enhanced Readability:
Time frame labels are now more descriptive (e.g., "1m", "3m", "1H", "2H", etc.) to clearly indicate the duration.
Icons for "Flower" (🌸) and "Fire" (🔥) events are maintained for visual clarity.
Handling No Data Scenarios:
If no "Flower" or "Fire" event data is available for a particular time frame, the table gracefully displays "No Data" and "N/A" to indicate the absence of relevant events.
Usage Notes
Performance Considerations:
Adding multiple time frames can increase the script's complexity and processing time, especially on charts with a large number of bars. Ensure that your TradingView setup can handle the extended computations without performance degradation.
Customization:
Feel free to adjust the list of time frames or their labels as per your specific requirements. Ensure that the process_time_frame function is called with the correct resolution string (e.g., '1' for 1 minute, 'D' for daily).
Visual Adjustments:
You can modify the table's appearance (e.g., colors, font sizes) by tweaking the parameters in the table.new and table.cell functions to better suit your chart's theme and readability preferences.
This enhanced script will provide a comprehensive overview of "Flower" and "Fire" events across a broader spectrum of time frames, enabling more informed trading decisions based on multi-time frame analysis.