I have tried to code the above requirement in pine script as an indicator, for india time where the market starts at 9:15 a.m and closes at 3:30 p.m. the indicator to work on all time frames.
- In the inputs tab of the indicator, i want that the two scripts be selected manually.
- in the style tab, a)i want the average Previous Day high to be displayed with a check box and color and line width and if possible with a price and label check boxes.
3)I need to find the previous day high of two scripts and finding their average previous day high (ie PDH script A + PDH script B)/2. Currently i am concentrating only on the average PD high but will later build up the code for average PD low and average PD close as well. - i need to plot this average PDH as a straight horizontal line when the market opens today at 9:15 a.m
- display the price value and label on the price scale
In the below code, i am able to select the two scripts. I am also able to get horizontal line for the average PDH, but the horizontal line is not as per the values (ie PDH script A + PDH script B)/2. only the last candle is showing the correct value.
In the style tab, I am also not able to get the check boxes 1)Average high 2)Price on status line 3) labels price scale.
I am right now coding only for the average high, but once i get the pine script right, i will add for average previous day low and average previous day close.Trading View Chart of both scripts
//@version=5
indicator("Average: Previous Day Levels", overlay=true)
// Input for dynamically selecting CE and PE option symbols from the TradingView symbol list
ce_symbol = input.symbol("NSE:NIFTY21SEP25500CE", title="Select CE Option Symbol")
pe_symbol = input.symbol("NSE:NIFTY21SEP25500PE", title="Select PE Option Symbol")
// Define the time range in India time (9:15 AM to 3:30 PM)
start_time = timestamp("Asia/Kolkata", year, month, dayofmonth, 9, 15)
end_time = timestamp("Asia/Kolkata", year, month, dayofmonth, 15, 30)
// Fetch Previous Day's High, Low, and Close for CE using the selected CE symbol
ce_pdh = request.security(ce_symbol, "D", high[1]) // Previous Day High for CE
// Fetch Previous Day's High, Low, and Close for PE using the selected PE symbol
pe_pdh = request.security(pe_symbol, "D", high[1]) // Previous Day High for PE
//find averages of high value
high1=(ce_pdh + pe_pdh)/2
// Check if the current bar time is within the session (9:15 AM to 3:30 PM India time)
in_session = (time >= start_time and time <= end_time)
// Plot the previous day's high, low, and close for CE and PE if within the time range
plot(in_session ? high1 : na, color=color.red, linewidth=2, title="Average High")
Victor Griffiths is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.