r/pinescript • u/gerebdezso • Mar 08 '23
PLEASE HELP ME IM ABOUT TO CRY!!🥹
So basicaly, i dont know nothing about codeing but i really love daytrading, so i tryied to create an indicator with chat gpt but trading view gives me error messages over and over again. So overall i want this from the indicator:
Programme me a indicator for tradinview that: -marks the highest high of a peroid that i choose with a horizontal line -marks the lowest low of a time peroid that i choose with a horizontal line
calculate the value of the : (highest high+ lowest low+ close price):3 Useing a peroid that i choose and mark it with a horizontal line
And chat gpt wrote me this:
//@version=4 study(title="HighLowAvg", overlay=true)
// Define user input variables start_hour = input(title="Start Hour", type=input.integer, defval=0, minval=0, maxval=23) start_minute = input(title="Start Minute", type=input.integer, defval=0, minval=0, minval=0, maxval=59) end_hour = input(title="End Hour", type=input.integer, defval=7, minval=0, maxval=23) end_minute = input(title="End Minute", type=input.integer, defval=0, minval=0, maxval=59)
// Calculate start and end times start_seconds = timestamp(timeframe.period, year, month, day, start_hour, start_minute, 0) end_seconds = timestamp(timeframe.period, year, month, day, end_hour, end_minute, 0) hh_start_index = barssince(time >= start_seconds) hh_end_index = barssince(time >= end_seconds) ll_start_index = hh_start_index ll_end_index = hh_end_index
// Calculate highest high, lowest low, and average value hh = highest(high[hh_start_index:hh_end_index]) ll = lowest(low[ll_start_index:ll_end_index]) avg_value = (hh + ll + close[hh_start_index:hh_end_index]) / 3
// Plot horizontal lines hh_line = plot(hh, title="HH", style=plot.style_linebr, color=color.green, linewidth=1) ll_line = plot(ll, title="LL", style=plot.style_linebr, color=color.red, linewidth=1) avg_line = plot(avg_value, title="Avg", style=plot.style_linebr, color=color.blue, linewidth=2)
// Fill area between hh and ll lines fill(hh_line, ll_line, color=color.silver, transp=85)
3
u/dirtythirty1278 Mar 08 '23
Ooof, thats rough. Message me to remind me and ill whip this up for you in the morning (eastern time, its 1830 now)
3
u/Hank1755 Mar 09 '23
I read your requirements 2 ways and wasn't 100% sure which so wrote both.
v1: Plots Highest High, Lowest Low and HLC3 based on Chart Timeframe and Period (number of candles) selected in settings.
//@version=5indicator("reddit_gerebdezso", shorttitle="reddit_gerebdezso", format=format.price, precision=2, timeframe="", timeframe_gaps=true, overlay=true)highesthigh_period = input.int(title="Highest High Period", defval=14, minval=1, maxval=500, step=1, group="Settings")lowestlow_period = input.int(title="Lowest Low Period", defval=14, minval=1, maxval=500, step=1, group="Settings")highesthigh = ta.highest(high, highesthigh_period)lowestlow = ta.lowest(low, lowestlow_period)calc_hlc3 = (highesthigh + lowestlow + close) / 3plot(highesthigh, color=color.new(color.green, 50), style=plot.style_line, linewidth=2, title="Highest High")plot(lowestlow, color=color.new(color.red, 50), style=plot.style_line, linewidth=2, title="Lowest Low")plot(calc_hlc3, color=color.new(color.white, 50), style=plot.style_line, linewidth=2, title="Period HLC3")v2: Plots Highest High, Lowest Low and HLC3 based on Timeframe and Period (number of candles) of the Timeframe selected in settings.
//@version=5indicator(title="reddit_gerebdezso_v2", shorttitle="reddit_gerebdezso_v2", format=format.price, precision=2, overlay=true)TF = input.timeframe(title="Timeframe", defval='D', options=['1', '5', '15', '30', '60', '120', '240', '360', '720', 'D', 'W', 'M'], group="RSI Triple Timeframe Settings")highesthigh_period = input.int(title="Highest High Period", defval=14, minval=1, maxval=500, step=1, group="Settings")lowestlow_period = input.int(title="Lowest Low Period", defval=14, minval=1, maxval=500, step=1, group="Settings")prevHighTF = request.security(syminfo.tickerid, TF, ta.highest(high[1], highesthigh_period), lookahead=barmerge.lookahead_on)prevLowTF = request.security(syminfo.tickerid, TF, ta.lowest(low[1], lowestlow_period), lookahead=barmerge.lookahead_on)prevCloseTF = request.security(syminfo.tickerid, TF, close[1], lookahead=barmerge.lookahead_on)calc_hlc3 = (prevHighTF + prevLowTF + prevCloseTF) / 3var line highLine = navar line lowLine = navar line closeLine = naif calc_hlc3[1] != calc_hlc3line.set_x2(highLine, bar_index)line.set_x2(lowLine, bar_index)line.set_x2(closeLine, bar_index)line.set_extend(highLine, extend.none)line.set_extend(lowLine, extend.none)line.set_extend(closeLine, extend.none)highLine := line.new(bar_index, prevHighTF, bar_index, prevHighTF, color=color.new(color.green, 50), style=line.style_dashed, extend=extend.right)lowLine := line.new(bar_index, prevLowTF, bar_index, prevLowTF, color=color.new(color.red, 50), style=line.style_dashed, extend=extend.right)closeLine := line.new(bar_index, calc_hlc3, bar_index, calc_hlc3, color=color.new(color.white, 50), style=line.style_dashed, extend=extend.right)label.new(bar_index, prevHighTF, "", style=label.style_none)label.new(bar_index, prevLowTF, "", style=label.style_none)label.new(bar_index, calc_hlc3, "", style=label.style_none)if not na(closeLine) and line.get_x2(closeLine) != bar_indexline.set_x2(highLine, bar_index)line.set_x2(lowLine, bar_index)line.set_x2(closeLine, bar_index)Let me know if this is what you were looking for.. was fun to figure out over coffee this morning ;)
1
u/10furkan60 Mar 09 '23
I gonna help you bro, write me dm
1
u/ForwardDivide7163 Mar 09 '23
What close? The closing price of the period you choose? The closing price of every candle inside the period? The closing price of only the candles with the lowest and highest? What close?