OPEN-SOURCE SCRIPT

Previous candle - byDen (Body % line & Wick size)

133
Pine Script®
//@version=6 indicator("Previous candle - byDen (Body % line & Wick size) [FIXED2]", overlay=true, max_boxes_count=200, max_lines_count=200, max_labels_count=200) // ---------------- Inputs ---------------- showHighLow = input.bool(true, "Show High/Low lines") showHLBox = input.bool(true, "Show High-Low Box (full range)") showMidLine = input.bool(true, "Show Middle Line") showCloseLine = input.bool(true, "Show Close Line") showBodyPct = input.bool(true, "Show Body % Line") enableWickBox = input.bool(true, "Show Wick-Body Box (previous candle)") keepLastWick = input.bool(false, "Keep last Wick-Box when disabled") bodyPct = input.float(25.0, "Body % Level", step=0.1, minval=0.0, maxval=100.0) // colors / styles cHighLow = input.color(color.white, "H/L Line Color") hlStyleStr = input.string("solid", "H/L Style", options=["solid","dashed","dotted"]) hlWidth = input.int(1, "H/L Width", minval=1, maxval=5) cMid = input.color(color.yellow, "Mid Line Color") midStyleStr = input.string("dashed", "Mid Style", options=["solid","dashed","dotted"]) midWidth = input.int(1, "Mid Width", minval=1, maxval=5) cClose = input.color(color.yellow, "Close Line Color") closeStyleStr = input.string("dotted", "Close Style", options=["solid","dashed","dotted"]) closeWidth = input.int(1, "Close Width", minval=1, maxval=5) cBoxBorder = input.color(color.red, "HL Box Border") cBoxFill = color.new(input.color(color.gray, "HL Box Fill"), 85) cBullBox = color.new(input.color(color.green, "Bull WickBox"), 80) cBearBox = color.new(input.color(color.red, "Bear WickBox"), 80) cWboxBorder = input.color(color.white, "WickBox Border") cBodyPct = input.color(color.blue, "Body % Line Color") bodyPctStyle = input.string("dashed", "Body % Line Style", options=["solid","dashed","dotted"]) bodyPctWidth = input.int(1, "Body % Line Width", minval=1, maxval=5) // wick label cPipBox = input.color(color.new(color.blue, 80), "Wick Box Color") cPipText = input.color(color.white, "Wick Text Color") pipSize = input.float(0.1, "Pip size (XAUUSD=0.1)", step=0.01) // Label settings showLabels = input.bool(true, "Show Line Labels") labelAbove = input.bool(true, "Labels Above Line?") fontSizeStr = input.string("normal", "Label Font Size", options=["tiny","small","normal","large","huge"]) labelAlignX = input.string("center", "Label Alignment", options=["left","center","right"]) // custom texts for labels txtHigh = input.string("High", "Label Text - High") txtLow = input.string("Low", "Label Text - Low") txtMid = input.string("Mid", "Label Text - Mid") txtClose = input.string("Close", "Label Text - Close") txtBody = input.string("Body %", "Label Text - Body %") // Wick pips font size (same options) wickFontSizeStr = input.string("normal", "Wick Pips Font Size", options=["tiny","small","normal","large","huge"]) // timeframe filter enabledTFs = input.string("1,5,15,30,60,240,D", "Enable on timeframes") // ---------------- Helpers ---------------- is_tf_enabled(tfStr) => str.contains("," + enabledTFs + ",", "," + tfStr + ",") line_style_from_str(s) => s == "dotted" ? line.style_dotted : s == "dashed" ? line.style_dashed : line.style_solid get_label_style(_align) => _align == "left" ? label.style_label_left : _align == "right" ? label.style_label_right : label.style_label_center get_font_size(fs) => if fs == "tiny" size.tiny else if fs == "small" size.small else if fs == "large" size.large else if fs == "huge" size.huge else size.normal // ---------------- Data ---------------- tf = timeframe.period [prevO, prevH, prevL, prevC] = request.security(syminfo.tickerid, tf, [open, high, low, close], lookahead=barmerge.lookahead_off) midLevel = (prevH + prevL) / 2 isBull = prevC > prevO // ---------------- Persistent ---------------- var line lHigh = na var line lLow = na var line lMid = na var line lClose = na var line lBodyPct = na var box bHL = na var box wickBox = na var table wickTable = na // labels var label labHigh = na var label labLow = na var label labMid = na var label labClose = na var label labBody = na offsetBars = input.int(20, "Bars right", minval=1, maxval=500) leftX_base = bar_index rightX_base = bar_index + offsetBars if na(wickTable) wickTable := table.new(position.bottom_right, 1, 1, border_width=1, frame_color=color.white) // ---------------- DRAW ---------------- if barstate.isconfirmed and is_tf_enabled(tf) // clean old labels if not na(labHigh) label.delete(labHigh) if not na(labLow) label.delete(labLow) if not na(labMid) label.delete(labMid) if not na(labClose) label.delete(labClose) if not na(labBody) label.delete(labBody) // style for labels labStyle = get_label_style(labelAlignX) labSize = get_font_size(fontSizeStr) wickSize = get_font_size(wickFontSizeStr) yOffset = labelAbove ? 1 : -1 if showHighLow if not na(lHigh) line.delete(lHigh) if not na(lLow) line.delete(lLow) lHigh := line.new(leftX_base, prevH, rightX_base, prevH, xloc=xloc.bar_index, color=cHighLow, width=hlWidth, style=line_style_from_str(hlStyleStr)) lLow := line.new(leftX_base, prevL, rightX_base, prevL, xloc=xloc.bar_index, color=cHighLow, width=hlWidth, style=line_style_from_str(hlStyleStr)) if showLabels labHigh := label.new(rightX_base, prevH + yOffset*syminfo.mintick, txtHigh, xloc=xloc.bar_index, yloc=yloc.price, style=labStyle, textcolor=cHighLow, size=labSize) labLow := label.new(rightX_base, prevL + yOffset*syminfo.mintick, txtLow, xloc=xloc.bar_index, yloc=yloc.price, style=labStyle, textcolor=cHighLow, size=labSize) if showMidLine if not na(lMid) line.delete(lMid) lMid := line.new(leftX_base, midLevel, rightX_base, midLevel, xloc=xloc.bar_index, color=cMid, width=midWidth, style=line_style_from_str(midStyleStr)) if showLabels labMid := label.new(rightX_base, midLevel + yOffset*syminfo.mintick, txtMid, xloc=xloc.bar_index, yloc=yloc.price, style=labStyle, textcolor=cMid, size=labSize) if showCloseLine if not na(lClose) line.delete(lClose) lClose := line.new(leftX_base, prevC, rightX_base, prevC, xloc=xloc.bar_index, color=cClose, width=closeWidth, style=line_style_from_str(closeStyleStr)) if showLabels labClose := label.new(rightX_base, prevC + yOffset*syminfo.mintick, txtClose, xloc=xloc.bar_index, yloc=yloc.price, style=labStyle, textcolor=cClose, size=labSize) if showBodyPct if not na(lBodyPct) line.delete(lBodyPct) float bodySize = math.abs(prevC - prevO) if bodySize > 0 float levelPct = isBull ? (prevC - (bodyPct/100.0) * bodySize) : (prevC + (bodyPct/100.0) * bodySize) lBodyPct := line.new(leftX_base, levelPct, rightX_base, levelPct, xloc=xloc.bar_index, color=cBodyPct, width=bodyPctWidth, style=line_style_from_str(bodyPctStyle)) if showLabels labBody := label.new(rightX_base, levelPct + yOffset*syminfo.mintick, txtBody + " " + str.tostring(bodyPct), xloc=xloc.bar_index, yloc=yloc.price, style=labStyle, textcolor=cBodyPct, size=labSize) if showHLBox if not na(bHL) box.delete(bHL) bHL := box.new(leftX_base, prevH, rightX_base, prevL, xloc=xloc.bar_index, border_color=cBoxBorder, bgcolor=cBoxFill) if not enableWickBox if not na(wickBox) and not keepLastWick box.delete(wickBox) wickBox := na else float topP = isBull ? prevH : prevC float botP = isBull ? prevC : prevL if not na(topP) and not na(botP) if not na(wickBox) box.delete(wickBox) wickBox := box.new(leftX_base, topP, rightX_base, botP, xloc=xloc.bar_index, border_color=cWboxBorder, bgcolor=(isBull ? cBullBox : cBearBox)) // wick izračun (v pipih) float wickPips = isBull ? prevH - prevC : prevC - prevL float wickInPips = math.round(wickPips / pipSize) // prikaži samo številko v desnem spodnjem kotu (z nastavljivo velikostjo) table.cell(wickTable, 0, 0, str.tostring(wickInPips), text_color=cPipText, bgcolor=cPipBox, text_size=wickSize)

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.