Untitled
unknown
plain_text
a year ago
20 kB
119
Indexable
//@version=5 indicator("Patanacci Range&Table", overlay=true) sembol = input.symbol("", "Symbol") showMondayData = input.bool(false, "Show Monday High/Low/Mid") // Yeni eklenen input mondayRangeDistance = input.int(5, "Monday Range Distance") // Monday Range için mesafe ayarı emaGoster = input.bool(true, "Show Ema's") period = input.timeframe(defval="", title="Time Period") ema1 = input.int(defval=50, title="EMA 1") ema2 = input.int(defval=100, title="EMA 2") ema3 = input.int(defval=200, title="EMA 3") atr = request.security(sembol, period, ta.atr(14)) hacim = request.security(sembol, period, volume) fark = request.security(sembol, period, (ta.change(close) / close[1]) * 100) // RSI hesaplama rsi = request.security(sembol, period, ta.rsi(close, 14)) // EMA hesaplamaları ema50 = request.security(sembol, period, ta.ema(close, ema1)) ema100 = request.security(sembol, period, ta.ema(close, ema2)) ema200 = request.security(sembol, period, ta.ema(close, ema3)) // Pazartesi günü verilerini hesaplama var float mondayHigh = na var float mondayLow = na var float mondayMid = na var int mondayStartIndex = na is_new_week = ta.change(time("W")) != 0 // Yeni hafta başlangıcını kontrol et if (is_new_week) mondayHigh := na mondayLow := na mondayMid := na mondayStartIndex := na if (dayofweek == dayofweek.monday) mondayHigh := na(mondayHigh) ? high : math.max(mondayHigh, high) mondayLow := na(mondayLow) ? low : math.min(mondayLow, low) mondayMid := (mondayHigh + mondayLow) / 2 if na(mondayStartIndex) mondayStartIndex := bar_index // Pazartesi günü verilerini çizgi olarak ekleme if (showMondayData) var line highLine = na var line lowLine = na var line midLine = na if (is_new_week) line.delete(highLine) line.delete(lowLine) line.delete(midLine) highLine := line.new(x1=mondayStartIndex, y1=mondayHigh, x2=bar_index + mondayRangeDistance, y2=mondayHigh, color=color.red, width=1) lowLine := line.new(x1=mondayStartIndex, y1=mondayLow, x2=bar_index + mondayRangeDistance, y2=mondayLow, color=color.green, width=1) midLine := line.new(x1=mondayStartIndex, y1=mondayMid, x2=bar_index + mondayRangeDistance, y2=mondayMid, color=color.blue, width=1) line.set_xy1(highLine, mondayStartIndex, mondayHigh) line.set_xy2(highLine, bar_index + mondayRangeDistance, mondayHigh) line.set_xy1(lowLine, mondayStartIndex, mondayLow) line.set_xy2(lowLine, bar_index + mondayRangeDistance, mondayLow) line.set_xy1(midLine, mondayStartIndex, mondayMid) line.set_xy2(midLine, bar_index + mondayRangeDistance, mondayMid) // Yazıları ekleme var label highText = na var label lowText = na var label midText = na label.delete(highText) label.delete(lowText) label.delete(midText) highText := label.new(x=bar_index + mondayRangeDistance, y=mondayHigh, text="MHigh", style=label.style_none, textcolor=color.black, size=size.normal, textalign=text.align_left) lowText := label.new(x=bar_index + mondayRangeDistance, y=mondayLow, text="MLow", style=label.style_none, textcolor=color.black, size=size.normal, textalign=text.align_left) midText := label.new(x=bar_index + mondayRangeDistance, y=mondayMid, text="MMid", style=label.style_none, textcolor=color.black, size=size.normal, textalign=text.align_left) var table tablo = table.new(position.top_right, 13, 12, border_width=1, border_color=color.rgb(197, 199, 207), frame_color=color.rgb(188, 190, 196), frame_width=1) if barstate.islast g3 = "%" g5 = "ATR" g8 = "RSI" g10 = "EMA" + str.tostring(ema1) g11 = "EMA" + str.tostring(ema2) g12 = "EMA" + str.tostring(ema3) text3 = str.tostring(math.round_to_mintick(fark)) + " %" text5 = str.tostring(math.round_to_mintick(atr)) text8 = str.tostring(math.round_to_mintick(rsi)) text10 = str.tostring(math.round_to_mintick(ema50)) text11 = str.tostring(math.round_to_mintick(ema100)) text12 = str.tostring(math.round_to_mintick(ema200)) table.cell(tablo, 2, 0, bgcolor=color.black, text_color=color.white, text=g3) table.cell(tablo, 4, 0, bgcolor=color.black, text_color=color.white, text=g5) table.cell(tablo, 8, 0, bgcolor=color.black, text_color=color.white, text=g8) table.cell(tablo, 10, 0, bgcolor=color.gray, text_color=color.white, text=g10) table.cell(tablo, 11, 0, bgcolor=color.gray, text_color=color.white, text=g11) table.cell(tablo, 12, 0, bgcolor=color.gray, text_color=color.white, text=g12) table.cell(tablo, 2, 1, bgcolor=fark > 0 ? color.green : color.red, text_color=color.white, text=text3) table.cell(tablo, 4, 1, bgcolor=color.black, text_color=color.white, text=text5) table.cell(tablo, 8, 1, bgcolor=rsi > 70 ? color.green : rsi < 30 ? color.red : color.teal, text_color=color.white, text=text8) table.cell(tablo, 10, 1, bgcolor=ema50 > close ? color.red : color.green, text_color=color.white, text=text10) table.cell(tablo, 11, 1, bgcolor=ema100 > close ? color.red : color.green, text_color=color.white, text=text11) table.cell(tablo, 12, 1, bgcolor=ema200 > close ? color.red : color.green, text_color=color.white, text=text12) // Range Başla bool range_sv = input.bool(true, title='Plot Range') bool range_eq_sv = input.bool(true, title='Plot Range 0.5 Line') bool range_q_sv = input.bool(true, title='Plot Range 0.25 and 0.75 Lines') bool log_sv = input.bool(true, title='Use Log Scale') bool r_a_sv = input.bool(true, title='Alert New Range') bool rt_a_sv = input.bool(true, title='Alert Range test') var float[] pvh1_price = array.new_float(30, na) // high var int[] pvh1_time = array.new_int(30, na) var float[] pvl1_price = array.new_float(30, na) // low var int[] pvl1_time = array.new_int(30, na) var float[] pvh2_price = array.new_float(10, na) // higher high var int[] pvh2_time = array.new_int(10, na) var float[] pvl2_price = array.new_float(10, na) // lower low var int[] pvl2_time = array.new_int(10, na) var line[] range_h_lines = array.new_line() // Range lines var line[] range_25_lines = array.new_line() var line[] range_m_lines = array.new_line() var line[] range_75_lines = array.new_line() var line[] range_l_lines = array.new_line() var label range_high_label = na var label range_low_label = na var label range_mid_label = na var float temp_pv_0 = na var float temp_pv_1 = na var float temp_pv_2 = na var int temp_time = na var float last_range_h = na var float last_range_l = na var line range_m = na var line range_25 = na var line range_75 = na var int rh_a_time = 0 var int rl_a_time = 0 bool pvh = high < high[1] and high[1] > high[2] bool pvl = low > low[1] and low[1] < low[2] int pv1_time = bar_index[1] float pv1_high = high[1] float pv1_low = low[1] bool new_ph_2nd = false bool new_pl_2nd = false string alert = na if barstate.isconfirmed if pvh array.pop(pvh1_price) array.pop(pvh1_time) array.unshift(pvh1_price, pv1_high) array.unshift(pvh1_time, pv1_time) if array.size(pvh1_price) > 2 temp_pv_0 := array.get(pvh1_price, 0) temp_pv_1 := array.get(pvh1_price, 1) temp_pv_2 := array.get(pvh1_price, 2) if temp_pv_0 < temp_pv_1 and temp_pv_1 > temp_pv_2 array.pop(pvh2_price) array.pop(pvh2_time) array.unshift(pvh2_price, temp_pv_1) array.unshift(pvh2_time, array.get(pvh1_time, 1)) new_ph_2nd := true if pvl array.pop(pvl1_price) array.pop(pvl1_time) array.unshift(pvl1_price, pv1_low) array.unshift(pvl1_time, pv1_time) if array.size(pvl1_price) > 2 temp_pv_0 := array.get(pvl1_price, 0) temp_pv_1 := array.get(pvl1_price, 1) temp_pv_2 := array.get(pvl1_price, 2) if temp_pv_0 > temp_pv_1 and temp_pv_1 < temp_pv_2 array.pop(pvl2_price) array.pop(pvl2_time) array.unshift(pvl2_price, temp_pv_1) array.unshift(pvl2_time, array.get(pvl1_time, 1)) new_pl_2nd := true if range_sv and (new_ph_2nd or new_pl_2nd) and (array.size(pvh2_price) > 1 and array.size(pvl2_price) > 1) and (array.get(pvh2_price, 0) < array.get(pvh2_price, 1) and array.get(pvl2_price, 0) > array.get(pvl2_price, 1) and array.get(pvh2_price, 0) > array.get(pvl2_price, 1) and array.get(pvl2_price, 0) < array.get(pvh2_price, 1)) and (array.get(pvl2_price, 1) > nz(last_range_h) or na(last_range_l) ? true : (array.get(pvh2_price, 1) < last_range_l)) temp_time := math.min(array.get(pvh2_time, 1), array.get(pvl2_time, 1)) last_range_h := array.get(pvh2_price, 1) last_range_l := array.get(pvl2_price, 1) temp_pv_0 := log_sv ? math.exp((math.log(last_range_h) + math.log(last_range_l)) / 2) : (last_range_h + last_range_l) / 2 temp_pv_1 := log_sv ? math.exp((math.log(last_range_h) + math.log(temp_pv_0)) / 2) : (last_range_h + temp_pv_0) / 2 temp_pv_2 := log_sv ? math.exp((math.log(last_range_l) + math.log(temp_pv_0)) / 2) : (last_range_l + temp_pv_0) / 2 array.push(range_h_lines, line.new(x1=temp_time, y1=last_range_h, x2=bar_index, y2=last_range_h, color=color.rgb(205, 29, 240), width=1, extend=extend.right)) array.push(range_l_lines, line.new(x1=temp_time, y1=last_range_l, x2=bar_index, y2=last_range_l, color=color.rgb(205, 29, 240), width=1, extend=extend.right)) if range_eq_sv array.push(range_m_lines, line.new(x1=temp_time, y1=temp_pv_0, x2=bar_index, y2=temp_pv_0, color=color.rgb(205, 29, 240), width=1, extend=extend.right)) if range_q_sv array.push(range_25_lines, line.new(x1=temp_time, y1=temp_pv_1, x2=bar_index, y2=temp_pv_1, style=line.style_dashed, color=color.gray, width=1, extend=extend.right)) array.push(range_75_lines, line.new(x1=temp_time, y1=temp_pv_2, x2=bar_index, y2=temp_pv_2, style=line.style_dashed, color=color.gray, width=1, extend=extend.right)) if r_a_sv alert := alert + 'New Range : ' + str.tostring(last_range_h) + ' - ' + str.tostring(last_range_l) + '. Mean = ' + str.tostring(temp_pv_0) + '\n' // Remove previous labels if they exist if na(range_high_label) == false label.delete(range_high_label) if na(range_low_label) == false label.delete(range_low_label) if na(range_mid_label) == false label.delete(range_mid_label) // Create new labels at the end of the lines range_high_label := label.new(x=temp_time, y=last_range_h, text='Range High', xloc=xloc.bar_index, yloc=yloc.price, style=label.style_none, color=color.rgb(0, 0, 0), textcolor=color.black, textalign=text.align_center) range_low_label := label.new(x=temp_time, y=last_range_l, text='Range Low', xloc=xloc.bar_index, yloc=yloc.price, style=label.style_none, color=color.rgb(0, 0, 0), textcolor=color.black, textalign=text.align_center) if range_eq_sv range_mid_label := label.new(x=temp_time, y=temp_pv_0, text='Range Mid', xloc=xloc.bar_index, yloc=yloc.price, style=label.style_none, color=color.rgb(0, 0, 0), textcolor=color.black, textalign=text.align_center) if array.size(range_h_lines) > 0 for i = array.size(range_h_lines) - 1 to 0 by 1 range_h = array.get(range_h_lines, i) top = line.get_y1(range_h) range_l = array.get(range_l_lines, i) bottom = line.get_y1(range_l) temp_time := line.get_x1(range_h) if array.size(pvh1_price) > 0 and array.get(pvh1_price, 0) > top if rt_a_sv and close < top if array.get(pvh1_time, 0) != rh_a_time rh_a_time := array.get(pvh1_time, 0) alert := alert + 'Range High Test @ ' + str.tostring(array.get(pvh1_price, 0)) + ' \n' if array.size(pvl1_price) > 0 and array.get(pvl1_price, 0) < bottom if rt_a_sv and close > bottom if array.get(pvl1_time, 0) != rl_a_time rl_a_time := array.get(pvl1_time, 0) alert := alert + 'Range Low Test @ ' + str.tostring(array.get(pvl1_price, 0)) + ' \n' if range_eq_sv range_m := array.get(range_m_lines, i) if range_q_sv range_25 := array.get(range_25_lines, i) range_75 := array.get(range_75_lines, i) if array.size(pvh1_price) > 0 and array.size(pvl1_price) > 0 and (array.get(pvh1_price, 0) < bottom or array.get(pvl1_price, 0) > top) line.delete(range_h) array.remove(range_h_lines, i) line.delete(range_l) array.remove(range_l_lines, i) if range_eq_sv line.delete(range_m) array.remove(range_m_lines, i) if range_q_sv line.delete(range_25) array.remove(range_25_lines, i) line.delete(range_75) array.remove(range_75_lines, i) last_range_h := na last_range_l := na alert := not na(alert) ? (alert + 'Current price = ' + str.tostring(close) + '\n') : na exec = not na(alert) ? true : false if exec==true alert(alert, alert.freq_once_per_bar_close) // © Patanacci //Quasimodo Başla PP = input.int(5 , 'Pivot Period') ATR = ta.atr(21) var ArrayType = array.new_string() var ArrayValue = array.new_float() var ArrayIndex = array.new_int() var Line = array.new_line() HighPivot = ta.pivothigh(PP,PP) LowPivot = ta.pivotlow(PP,PP) HighValue = ta.valuewhen(HighPivot ,high[PP], 0) LowValue = ta.valuewhen(LowPivot ,low[PP], 0) HighIndex = ta.valuewhen(HighPivot ,bar_index[PP], 0) LowIndex = ta.valuewhen(LowPivot ,bar_index[PP], 0) Correct_HighPivot = 0.0 Correct_LowPivot = 0.0 PASS = 0 if HighPivot and LowPivot if ArrayType.size() == 0 PASS := 1 else if ArrayType.size() >= 1 if ((ArrayType.get(ArrayType.size() - 1)) == "L" or (ArrayType.get(ArrayType.size() - 1)) == "LL") if LowPivot < ArrayValue.get(ArrayType.size() - 1) array.remove(ArrayType,ArrayType.size() - 1) array.remove(ArrayValue,ArrayValue.size() - 1) array.remove(ArrayIndex,ArrayIndex.size() - 1) array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here array.push(ArrayValue, LowValue) array.push(ArrayIndex, LowIndex) Correct_LowPivot := LowValue else array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H" ) ///////////////////////////////Here array.push(ArrayValue, HighValue) array.push(ArrayIndex, HighIndex) Correct_HighPivot := HighValue else if (ArrayType.get(ArrayType.size() - 1)) == "H" or (ArrayType.get(ArrayType.size() - 1)) == "HH" if HighPivot > ArrayValue.get(ArrayType.size() - 1) array.remove(ArrayType,ArrayType.size() - 1) array.remove(ArrayValue,ArrayValue.size() - 1) array.remove(ArrayIndex,ArrayIndex.size() - 1) array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here array.push(ArrayValue, HighValue) array.push(ArrayIndex, HighIndex) Correct_HighPivot := HighValue else array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here array.push(ArrayValue, LowValue) array.push(ArrayIndex, LowIndex) Correct_LowPivot := LowValue else if (ArrayType.get(ArrayType.size() - 1)) == "LH" if HighPivot < ArrayValue.get(ArrayType.size() - 1) array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here array.push(ArrayValue, LowValue) array.push(ArrayIndex, LowIndex) Correct_LowPivot := LowValue else if HighPivot > ArrayValue.get(ArrayType.size() - 1) if close < ArrayValue.get(ArrayType.size() - 1) array.remove(ArrayType,ArrayType.size() - 1) array.remove(ArrayValue,ArrayValue.size() - 1) array.remove(ArrayIndex,ArrayIndex.size() - 1) array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here array.push(ArrayValue, HighValue) array.push(ArrayIndex, HighIndex) Correct_HighPivot := HighValue else if close > ArrayValue.get(ArrayType.size() - 1) array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here array.push(ArrayValue, LowValue) array.push(ArrayIndex, LowIndex) Correct_LowPivot := LowValue else if (ArrayType.get(ArrayType.size() - 1)) == "HL" if LowPivot > ArrayValue.get(ArrayType.size() - 1) array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H" ) ///////////////////////////////Here array.push(ArrayValue, HighValue) array.push(ArrayIndex, HighIndex) Correct_HighPivot := HighValue else if LowPivot < ArrayValue.get(ArrayType.size() - 1) if close > ArrayValue.get(ArrayType.size() - 1) array.remove(ArrayType,ArrayType.size() - 1) array.remove(ArrayValue,ArrayValue.size() - 1) array.remove(ArrayIndex,ArrayIndex.size() - 1) array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here array.push(ArrayValue, LowValue) array.push(ArrayIndex, LowIndex) Correct_LowPivot := LowValue else if close < ArrayValue.get(ArrayType.size() - 1) array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here array.push(ArrayValue, HighValue) array.push(ArrayIndex, HighIndex) Correct_HighPivot := HighValue else if HighPivot if ArrayType.size() == 0 array.insert(ArrayType, 0, "H") array.insert(ArrayValue, 0, HighValue) array.insert(ArrayIndex, 0, HighIndex) Correct_HighPivot := HighValue else if ArrayType.size() >= 1 if ((ArrayType.get(ArrayType.size() - 1)) == "L" or (ArrayType.get(ArrayType.size() - 1)) == "HL" or (ArrayType.get(ArrayType.size() - 1)) == "LL") if HighPivot
Editor is loading...
Leave a Comment