Candle_body = input.float(0.5, 'Height of Engulfing candle body (%)', group = OSB_up_down) //scan nến osb-eng - mera mera// osb_up = high > high[1] and low < low[1] and close > close[1] osb_down = high > high[1] and low < low[1] and close < close[1] eng_up = open >= close[1] and close > high[1] and (close - open) >= Candle_body*(high - low) eng_down = open <= close[1] and close < low[1] and (open - close) >= Candle_body*(high - low) mm_up = osb_up and close[2] > close[3] and close[1] > close[2] mm_down = osb_down and close[2] < close[3] and close[1] < close[2] cande_up = close > close[1] cande_down = close < close[1]
//cảnh báo khi xuất hiện nến/ close_osb_up = close close_osb_down = close close_eng_up = close close_eng_down = close close_mm_up = close close_mm_down = close time_h4 = request.security(syminfo.tickerid, "240",close) time_D1 = request.security(syminfo.tickerid, "D",close)
if (osb_up and barstate.isconfirmed) if (close_osb_up > ema) alert("OSB_UP: Above Ema: " + str.tostring(close_osb_up)) if volUltraHigh alert("OSB_UP + Volume: Above Ema: " + str.tostring(close_osb_up)) else if (close_osb_up < ema) alert("OSB_UP: Below Ema: " + str.tostring(close_osb_up)) if volUltraHigh alert("OSB_UP + Volume: Below Ema: " + str.tostring(close_osb_up))
if (osb_down and barstate.isconfirmed) if (close_osb_down > ema) alert("OSB_DOWN: Above Ema: " + str.tostring(close_osb_down)) if volUltraHigh alert("OSB_DOWN + Volume: Above Ema: " + str.tostring(close_osb_down)) else if (close_osb_down < ema) alert("OSB_DOWN: Below Ema: " + str.tostring(close_osb_down)) if volUltraHigh alert("OSB_DOWN + Volume: Below Ema: " + str.tostring(close_osb_down))
if (eng_up and barstate.isconfirmed) if (close_eng_up > ema) alert("Bar_UP: Above Ema: " + str.tostring(close_eng_up)) if volUltraHigh alert("Bar_UP + Volume: Above Ema: " + str.tostring(close_eng_up)) else if (close_eng_up < ema) alert("Bar_UP: Below Ema: " + str.tostring(close_eng_up)) if volUltraHigh alert("Bar_UP + Volume: Below Ema: " + str.tostring(close_eng_up))
if (eng_down and barstate.isconfirmed) if (close_eng_down > ema) alert("Bar_DOWN: Above Ema: " + str.tostring(close_eng_down)) if volUltraHigh alert("Bar_DOWN + Volume: Above Ema: " + str.tostring(close_eng_down)) else if (close_eng_down < ema) alert("Bar_DOWN: Below Ema: " + str.tostring(close_eng_down)) if volUltraHigh alert("Bar_DOWN + Volume: Below Ema: " + str.tostring(close_eng_down))
if (mm_up and barstate.isconfirmed) if (close_mm_up > ema) alert("Mera_UP: Above Ema: " + str.tostring(close_mm_up)) if volUltraHigh alert("Mera_UP + Volume: Above Ema: " + str.tostring(close_mm_up)) else if (close_mm_up < ema) alert("Mera_UP: Below Ema: " + str.tostring(close_mm_up)) if volUltraHigh alert("Mera_UP + Volume: Below Ema: " + str.tostring(close_mm_up))
if (mm_down and barstate.isconfirmed) if (close_mm_down > ema) alert("Mera_DOWN: Above Ema: " + str.tostring(close_mm_down)) if volUltraHigh alert("Mera_DOWN + Volume: Above Ema: " + str.tostring(close_mm_down)) else if (close_mm_down < ema) alert("Mera_DOWN: Below Ema: " + str.tostring(close_mm_down)) if volUltraHigh alert("Mera_DOWN + Volume: Below Ema: " + str.tostring(close_mm_down))
get_line_style(s) => s == "Solid" ? line.style_solid : s == "Dotted" ? line.style_dotted : line.style_dashed
get_levels(n) => h = high[1] l = low[1] for i=1 to n if low < l l := low if high > h h := high [h, l, (h+l)/2]
var line ibh = na var line ibl = na var line ibm = na var line ib_plus = na var line ib_minus = na var line ib_plus2 = na var line ib_minus2 = na var line ibm_plus = na var line ibm_minus = na
var label labelh = na var label labell = na var label labelm = na var label label_plus = na var label label_minus = na var label label_plus2 = na var label label_minus2 = na var label labelm_plus = na var label labelm_minus = na var box ib_area = na
bgcolor(show_ib_calculation_area and ins ? #673ab730 : na, title="IB calculation zone") var float ib_delta = na
if ins offset += 1 if ins[1] and not ins [h, l, m] = get_levels(offset) ib_delta := h - l if array.size(delta_history) >= 20 array.shift(delta_history) array.push(delta_history, ib_delta)
getprice(TimeFrame, Index)=> // Get Open, High, Low, Close, Time data i = Index tf = TimeFrame [O, H, L, C, T] = request.security(syminfo.tickerid, tf, [open, high, low, close, time], lookahead=barmerge.lookahead_on) [O, H, L, C, T]
[cDopen, cDhigh, cDlow, cDclose, cDtime] = getprice('D', 0+index) // Get Current Day Open, High, Low, Close, Time [cWopen, cWhigh, cWlow, cWclose, cWtime] = getprice('W', 0+index) // Get Current Weekly Open, High, Low, Close, Time [cMopen, cMhigh, cMlow, cMclose, cMtime] = getprice('M', 0+index) // Get Current Mounth Open, High, Low, Close, Time [cQopen, cQhigh, cQlow, cQclose, cQtime] = getprice('3M', 0+index) // Get Current Quarter Open, High, Low, Close, Time [cYopen, cYhigh, cYlow, cYclose, cYtime] = getprice('12M', 0+index) // Get Current Year Open, High, Low, Close, Time [pDopen, pDhigh, pDlow, pDclose, pDtime] = getprice('D', 1+index) // Get Previous Day Open, High, Low, Close, Time [pWopen, pWhigh, pWlow, pWclose, pWtime] = getprice('W', 1+index) // Get Previous Weekly Open, High, Low, Close, Time [pMopen, pMhigh, pMlow, pMclose, pMtime] = getprice('M', 1+index) // Get Previous Mounth Open, High, Low, Close, Time [pQopen, pQhigh, pQlow, pQclose, pQtime] = getprice('3M', 1+index) // Get Previous Quarter Open, High, Low, Close, Time [pYopen, pYhigh, pYlow, pYclose, pYtime] = getprice('12M', 1+index) // Get Previous Year Open, High, Low, Close, Time
extend(bars) => // Extends the current time by the product of the time difference between elements and the number of bars. timenow + (time - time[1]) * bars
getlevel(time, level, txtcolor, linecolor, txtlabel)=> // Get draws a line and a label on the chart if barstate.islast // The following code doesn't need to be processed on every candle xindex = displaystyle == 'Standard' ? time : bar_index+bar_offset xloc = displaystyle == 'Standard' ? xloc.bar_time : xloc.bar_index xid = displaystyle == 'Standard' ? extend(bar_offset) : bar_index+bar_offset+1 lblpos = labelpos == 'Middle' ? label.style_label_center : label.style_none lines = line.new (x1=xindex, x2=xid, y1=level, y2=level, xloc=xloc, style=linestyles, extend=displaystyles, color=linecolor) labels = label.new(x=xid, y=level, text=txtlabel, style=lblpos, xloc=xloc, text_font_family=fontstyles, textcolor=txtcolor, color = #ffffff00) line.delete(lines[1]) // remove the previous line when new bar appears label.delete(labels[1]) // remove the previous label when new bar appears [lines, labels]
// Сollecting labels into an array for normalization labels = array.from(cDOlabel,cDHlabel,cDLlabel,pDOlabel,pDHlabel,pDLlabel,cWOlabel,cWHlabel,cWLlabel,pWOlabel,pWHlabel,pWLlabel,cMOlabel,cMHlabel,cMLlabel,pMOlabel,pMHlabel,pMLlabel,cQOlabel,cQHlabel,cQLlabel,pQOlabel,pQHlabel,pQLlabel,cYOlabel,cYHlabel,cYLlabel,pYOlabel,pYHlabel,pYLlabel)
// This loop merge items in arrays "labels" into a single label if their difference is less than a certain threshold, and updates the label text. for i = 0 to array.size(labels) - 2 // Loop through all the labels txt = label.get_text(array.get(labels, i)) // Get the text of the current label price_i = label.get_y(array.get(labels, i)) // Get the y coordinate of the current label label_i = array.get(labels, i) // Store the current label for j = i + 1 to array.size(labels) - 1 // Loop through the remaining labels price_j = label.get_y(array.get(labels, j)) // Get the y coordinate of the current label if math.abs(price_i - price_j) < (threshold/100) * price_i // Compare the prices txt := txt + ' / ' + label.get_text(array.get(labels, j)) // Add the text of the second label label.delete(array.get(labels, j)) // Delete the second label label.set_text(label_i, txt) // Set the text of the current label
repeat(str, num) => // Returns a string that is created by repeating the input str num times res = "" len = str.length(str) if num > 0 and len * num <= 4096 for r = 1 to num res := res + str res // Loop to change the position of the Label if labelpos == 'Middle' for z = 0 to array.size(labels) - 1 label_z = array.get(labels, z) // Get the label at position z texts = label.get_text(label_z) // Get the text of the label spaces = fontstyle=='Default' ? repeat(' ', math.ceil(str.length(texts))*2) : repeat(' ', math.ceil(str.length(texts))) // Calculate the number of spaces needed label.set_text(label_z, displaystyle=='Right'? texts + spaces + ' ' : spaces+' ' + texts) // Set the label text with the calculated spaces //
Congestion_Zone = "Congestio_Zone" Show_CZ = input.bool(true, title="On/off Congestion Zone", group="Congestion_Zone") minbar = input(title="Minimum Bars in Zone", defval=5, group="Congestion_Zone", inline="Box",tooltip = "Số lượng nến tối thiểu để có 1 vùng CZ") border_width = input.int(title="CZ boder width", defval=1, inline="Box1", group="Congestion_Zone", step=1,tooltip = "Viền CZ") max_boxes = input.int(title="Max CZ", defval=50, group="Congestion_Zone", minval=1,tooltip = "Số vùng box tối đa muốn hiển thị để tránh rối mắt")
boxcolor_basic = input.color(title="CZ Color Basic", defval=color.new(color.orange, 80), group="Congestion_Zone",tooltip = "Nến thoát khỏi box không có xu hướng rõ ràng") boxcolor_up = input.color(title="CZ Color Up", defval=color.new(color.green, 80), group="Congestion_Zone",tooltip = "Nến thoát khỏi box có giá đóng cửa > vùng CZ") boxcolor_down = input.color(title="CZ Color Dowwn", defval=color.new(color.red, 80), group="Congestion_Zone",tooltip = "Nến thoát khỏi box có đóng cửa < vùng CZ")
var boxopen = array.new_float() var boxclose = array.new_float() var boxes = array.new_box()
congestion_condition = close >= low[1] and close <= high[1] and open >= low[1] and open <= high[1]
if congestion_condition and Show_CZ array.push(boxopen, open > close ? open : close) array.push(boxclose, open > close ? close : open) else if array.size(boxopen) < minbar array.clear(boxopen) array.clear(boxclose)
if not congestion_condition and array.size(boxopen) >= minbar and Show_CZ box_max = array.max(boxopen) box_min = array.min(boxclose) box_color = close >= box_max ? boxcolor_up : close <= box_min ? boxcolor_down : boxcolor_basic if box_color == boxcolor_basic alert("CZ basic") else if box_color == boxcolor_up alert("CZ UP") else if box_color == boxcolor_down alert("CZ DOWN") // Determine box color based on last candle new_box = box.new(bar_index - array.size(boxopen), box_max, bar_index - 1, box_min, bgcolor=box_color, border_width=border_width,border_color = box_color) array.push(boxes, new_box) array.clear(boxopen) array.clear(boxclose)
//Remove old boxes if limit is reached while array.size(boxes) > max_boxes box.delete(array.shift(boxes))