HERES MY pine script code: //@version=5 indicator("Previous Week Bias", overlay=true,…
- User
HERES MY pine script code: //@version=5 indicator("Previous Week Bias", overlay=true, max_labels_count=1, max_lines_count=1)
var line prevWeekHighLabel = na var line prevWeekLowLabel = na var line buySignalLine = na var line sellSignalLine = na var line buy00Line = na var line sell00Line = na var line buy007Line = na var line sell007Line = na var label buy007Label = na var label sell007Label = na
var float prevMonthHigh = na var float prevMonthLow = na var float fiftyPercent = na var float highestHigh = na var float lowestLow = na var bool buyBiasConfirmed = na var bool sellBiasConfirmed = na var bool redCandleClosed = na var bool greenCandleClosed = na var float buy00Price = na var float sell00Price = na
prevMonthHigh := request.security(syminfo.tickerid, "M", high[1]) prevMonthLow := request.security(syminfo.tickerid, "M", low[1]) fiftyPercent := (prevMonthHigh + prevMonthLow) / 2 prevWeekCloseHigh = request.security(syminfo.tickerid, "W", high[1]) prevWeekCloseLow = request.security(syminfo.tickerid, "W", low[1]) prevWeekClose = request.security(syminfo.tickerid, "W", close[1]) high4H = request.security(syminfo.tickerid, "240", high) low4H = request.security(syminfo.tickerid, "240", low) close4H = request.security(syminfo.tickerid, "240", close) open4H = request.security(syminfo.tickerid, "240", open)
if ta.change(time("W")) > 0 line.delete(prevWeekHighLabel) line.delete(prevWeekLowLabel) line.delete(buySignalLine) line.delete(sellSignalLine) line.delete(buy00Line) line.delete(sell00Line) line.delete(buy007Line) line.delete(sell007Line) label.delete(buy007Label) label.delete(sell007Label)
if prevWeekClose > fiftyPercent prevWeekHighLabel := line.new(x1=bar_index[1], y1=prevWeekCloseHigh, x2=bar_index, y2=prevWeekCloseHigh, color=color.blue, width=1, style=line.style_solid) label.new(x=bar_index, y=prevWeekCloseHigh, text="Buy Bias", color=color.green, style=label.style_text_outline, size=size.small) buyBiasConfirmed := true else if prevWeekClose < fiftyPercent prevWeekLowLabel := line.new(x1=bar_index[1], y1=prevWeekCloseLow, x2=bar_index, y2=prevWeekCloseLow, color=color.blue, width=1, style=line.style_solid) label.new(x=bar_index, y=prevWeekCloseLow, text="Sell Bias", color=color.red, style=label.style_text_outline, size=size.small) sellBiasConfirmed := true// Buy bias logic if buyBiasConfirmed if (close4H) > prevWeekCloseHigh high4H := buy00Price else if high4H > buy00Price high4H := buy00Price else if (close4H) < open4H redCandleClosed := true else if redCandleClosed and not na(buy00Price) buy007Line := line.new(x1=bar_index, y1=buy00Price, x2=bar_index, y2=buy00Price, color=color.rgb(0, 21, 249), width=1, style=line.style_solid) label.new(x=bar_index, y=buy00Price, text="Buy 00=7", color=color.green, style=label.style_text_outline, size=size.small) redCandleClosed := na
// Sell bias logic if sellBiasConfirmed if (close4H) < prevWeekCloseLow sell00Price := low4H else if low4H < sell00Price sell00Price := low4H else if (close4H) > open4H greenCandleClosed := true else if greenCandleClosed and not na(sell00Price) sell007Line := line.new(x1=bar_index, y1=sell00Price, x2=bar_index , y2=sell00Price, color=color.rgb(10, 36, 205), width=1, style=line.style_solid) label.new(x=bar_index, y=sell00Price, text="Sell 00=7", color=color.red, style=label.style_text_outline, size=size.small) greenCandleClosed := na
- Assistant
Here's the corrected Pine Script code that should only draw new lines and labels once per week on the 4h timeframe, and extend the lines 5 candles out from the current candle:
//@version=4 study("Previous Week Bias", overlay=true) var line prevWeekHighLabel = line.new(na, na, na, na) var line prevWeekLowLabel = line.new(na, na, na, na) var line buySignalLine = line.new(na, na, na, na) var line sellSignalLine = line.new(na, na, na, na) var label buyLabel = label.new(na, na, "Buy Bias") var label sellLabel = label.new(na, na, "Sell Bias") var bool lines_plotted = false if change(time("W")) and not lines_plotted line.set_xy1(prevWeekHighLabel, bar_index[1], request.security(syminfo.tickerid, "W", high[1])) line.set_xy2(prevWeekHighLabel, bar_index[1] + 5, request.security(syminfo.tickerid, "W", high[1])) line.set_xy1(prevWeekLowLabel, bar_index[1], request.security(syminfo.tickerid, "W", low[1])) line.set_xy2(prevWeekLowLabel, bar_index[1] + 5, request.security(syminfo.tickerid, "W", low[1])) label.set_xy(buyLabel, bar_index[1] + 5, request.security(syminfo.tickerid, "W", high[1])) label.set_xy(sellLabel, bar_index[1] + 5, request.security(syminfo.tickerid, "W", low[1])) line.set_color(prevWeekHighLabel, change(time("W")) ? color.blue : na) line.set_color(prevWeekLowLabel, change(time("W")) ? color.red : na) label.set_color(buyLabel, change(time("W")) ? color.green : na) label.set_color(sellLabel, change(time("W")) ? color.red : na) lines_plotted := true else lines_plotted := false
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.