make me a pine script v5 indicator in proper format and correct syntax. heres what i…
- User
make me a pine script v5 indicator in proper format and correct syntax. heres what i want the indicator to do: at the beginning of every week take the high and low and close of previous week. take high and low and 50% of the high and low of previous month (i will refer to this as previous month 50%) as well. based on if previous week closed above previous month 50%; call it a buy bias and put a short blue line on previous week high with the label buy bias. if below previous month 50%, then give it a blue line on previous week low with the label sell bias. now look on 4h timeframe; if buy bias, if during this week, there is a 4h close > previous week high then set a flag at the high of this 4h candle. if sell bias, if during this week there is a 4h close <previous week low then set a flat at the low of this 4h candle. then if both conditions have been met, from 1 flag to the next during a buy bias week find the highest 4h candle and on that high make a blue line labelled 007 buy. delete buy bias blue line when this occurs. or from the the first flag to the second, during a sell bias week find the lowest 4h candle and on that low make a blue line labelled 007 sell. delete sell bias blue line when this occurs. make sure all lines are only drawn 1 time during the week, and deleted at end of week so next week can have new lines and labels.
- Assistant
Sure, here's the pine script code for the indicator you described:
//@version=5 indicator("007 Bias Indicator", shorttitle="007", overlay=true) prevWeekHigh = request.security(syminfo.tickerid, "W", high[1]) prevWeekLow = request.security(syminfo.tickerid, "W", low[1]) prevWeekClose = request.security(syminfo.tickerid, "W", close[1]) prevMonth50 = (request.security(syminfo.tickerid, "M", high[1]) + request.security(syminfo.tickerid, "M", low[1])) / 2 buyBias = prevWeekClose > prevMonth50 sellBias = prevWeekClose < prevMonth50 var line buyLine = line.new(na,na,na,na) var line sellLine = line.new(na,na,na,na) var bool flagExists = false if barstate.isfirst line.set_extend(buyLine, extend.none) line.set_extend(sellLine, extend.none) line.set_width(buyLine, 1) line.set_width(sellLine, 1) line.set_color(buyLine, color.blue) line.set_color(sellLine, color.blue) if not flagExists if buyBias and close > prevWeekHigh line.set_xy1(buyLine, bar_index[1], high) line.set_xy2(buyLine, bar_index, high) line.set_text(buyLine, "007 Buy") flagExists := true else if sellBias and close < prevWeekLow line.set_xy1(sellLine, bar_index[1], low) line.set_xy2(sellLine, bar_index, low) line.set_text(sellLine, "007 Sell") flagExists := true if barstate.islast or (buyBias and not sellBias and dayofweek[1] == 1) or (not buyBias and sellBias and dayofweek[1] == 1) if buyBias line.delete(buyLine) if sellBias line.delete(sellLine) flagExists := false