//version=5
indicator("WT SETUP WITH LINES AND LABELS", "WT SETUP", overlay=true, max_lines_count=500, max_labels_count=500)

// Timeframe selection
tf = input.string("D", "Timeframe", options=["D", "W", "M"])

// Level selection
level_selection = input.string("Yesterday", "Level Calculation", options=["Latest", "Yesterday"])


// Color input options
color pivotColor = input.color(color.white, "Pivot Color", group="Colors")
color highColor = input.color(color.red, "High Color", group="Colors")
color lowColor = input.color(color.green, "Low Color", group="Colors")
color closeColor = input.color(color.white, "Close Color", group="Colors")
color r1Color = input.color(color.red, "R1 Color", group="Colors")
color r2Color = input.color(color.red, "R2 Color", group="Colors")
color r3Color = input.color(color.red, "R3 Color", group="Colors")
color r4Color = input.color(color.red, "R4 Color", group="Colors")
color s1Color = input.color(color.green, "S1 Color", group="Colors")
color s2Color = input.color(color.green, "S2 Color", group="Colors")
color s3Color = input.color(color.green, "S3 Color", group="Colors")
color s4Color = input.color(color.green, "S4 Color", group="Colors")

offset = level_selection == "Yesterday" ? 1 : 0

float lowPrev = request.security(syminfo.tickerid, tf, low[offset])
float highPrev = request.security(syminfo.tickerid, tf, high[offset])
float closePrev = request.security(syminfo.tickerid, tf, close[offset])

float pivot = (lowPrev + highPrev + closePrev) / 3
float s1 = (2 * pivot) - highPrev
float r1 = (2 * pivot) - lowPrev
float rangeValue = highPrev - lowPrev
float s2 = pivot - rangeValue
float r2 = pivot + rangeValue
float s3 = lowPrev - 2 * (highPrev - pivot)
float r3 = highPrev + 2 * (pivot - lowPrev)
float s4 = pivot * 3 - (3 * highPrev - lowPrev)
float r4 = pivot * 3 + (highPrev - 3 * lowPrev)


var line pivotLine = na
var line r1Line = na
var line r2Line = na
var line r3Line = na
var line r4Line = na
var line s1Line = na
var line s2Line = na
var line s3Line = na
var line s4Line = na
var line highLine = na
var line lowLine = na
var line closeLine = na

var label pivotLabel = na
var label r1Label = na
var label r2Label = na
var label r3Label = na
var label r4Label = na
var label s1Label = na
var label s2Label = na
var label s3Label = na
var label s4Label = na
var label highLabel = na
var label lowLabel = na
var label closeLabel = na

if barstate.islast
pivotLine := line.new(bar_index, pivot, bar_index + 1, pivot, extend=extend.right, color=pivotColor, width=1)
r1Line := line.new(bar_index, r1, bar_index + 1, r1, extend=extend.right, color=r1Color, width=1)
r2Line := line.new(bar_index, r2, bar_index + 1, r2, extend=extend.right, color=r2Color, width=1)
r3Line := line.new(bar_index, r3, bar_index + 1, r3, extend=extend.right, color=r3Color, width=1)
r4Line := line.new(bar_index, r4, bar_index + 1, r4, extend=extend.right, color=r4Color, width=1)
s1Line := line.new(bar_index, s1, bar_index + 1, s1, extend=extend.right, color=s1Color, width=1)
s2Line := line.new(bar_index, s2, bar_index + 1, s2, extend=extend.right, color=s2Color, width=1)
s3Line := line.new(bar_index, s3, bar_index + 1, s3, extend=extend.right, color=s3Color, width=1)
s4Line := line.new(bar_index, s4, bar_index + 1, s4, extend=extend.right, color=s4Color, width=1)
highLine := line.new(bar_index, highPrev, bar_index + 1, highPrev, extend=extend.right, color=highColor, width=1)
lowLine := line.new(bar_index, lowPrev, bar_index + 1, lowPrev, extend=extend.right, color=lowColor, width=1)
closeLine := line.new(bar_index, closePrev, bar_index + 1, closePrev, extend=extend.right, color=closeColor, width=1)

tfString = tf == "D" ? "Daily" : (tf == "W" ? "Weekly" : "Monthly")
levelString = level_selection == "Yesterday" ? "Yesterday's" : "Latest"
pivotLabel := label.new(bar_index, pivot, tfString + " " + levelString + " Pivot " + str.tostring(pivot, "(#.##)"), color=color.gray, style=label.style_label_down, textcolor=color.white)
r1Label := label.new(bar_index, r1, "R1 " + str.tostring(r1, "(#.##)"), color=r1Color, style=label.style_label_down, textcolor=color.white)
r2Label := label.new(bar_index, r2, "R2 " + str.tostring(r2, "(#.##)"), color=r2Color, style=label.style_label_down, textcolor=color.white)
r3Label := label.new(bar_index, r3, "R3 " + str.tostring(r3, "(#.##)"), color=r3Color, style=label.style_label_down, textcolor=color.white)
r4Label := label.new(bar_index, r4, "R4 " + str.tostring(r4, "(#.##)"), color=r4Color, style=label.style_label_down, textcolor=color.white)
s1Label := label.new(bar_index, s1, "S1 " + str.tostring(s1, "(#.##)"), color=s1Color, style=label.style_label_up, textcolor=color.white)
s2Label := label.new(bar_index, s2, "S2 " + str.tostring(s2, "(#.##)"), color=s2Color, style=label.style_label_up, textcolor=color.white)
s3Label := label.new(bar_index, s3, "S3 " + str.tostring(s3, "(#.##)"), color=s3Color, style=label.style_label_up, textcolor=color.white)
s4Label := label.new(bar_index, s4, "S4 " + str.tostring(s4, "(#.##)"), color=s4Color, style=label.style_label_up, textcolor=color.white)
highLabel := label.new(bar_index, highPrev, "High " + str.tostring(highPrev, "(#.##)"), color=highColor, style=label.style_label_down, textcolor=color.white)
lowLabel := label.new(bar_index, lowPrev, "Low " + str.tostring(lowPrev, "(#.##)"), color=lowColor, style=label.style_label_up, textcolor=color.white)
closeLabel := label.new(bar_index, closePrev, "Close " + str.tostring(closePrev, "(#.##)"), color=color.gray, style=label.style_label_down, textcolor=color.white)
else
line.delete(pivotLine)
line.delete(r1Line)
line.delete(r2Line)
line.delete(r3Line)
line.delete(r4Line)
line.delete(s1Line)
line.delete(s2Line)
line.delete(s3Line)
line.delete(s4Line)
line.delete(highLine)
line.delete(lowLine)
line.delete(closeLine)

label.delete(pivotLabel)
label.delete(r1Label)
label.delete(r2Label)
label.delete(r3Label)
label.delete(r4Label)
label.delete(s1Label)
label.delete(s2Label)
label.delete(s3Label)
label.delete(s4Label)
label.delete(highLabel)
label.delete(lowLabel)
label.delete(closeLabel)
concepteducationalforecasting

نص برمجي مفتوح المصدر

قام مؤلف هذا النص البرمجي بنشره وجعله مفتوح المصدر، بحيث يمكن للمتداولين فهمه والتحقق منه، وهو الأمر الذي يدخل ضمن قيم TradingView. تحياتنا للمؤلف! يمكنك استخدامه مجانًا، ولكن إعادة استخدام هذا الرمز في المنشور يخضع لقواعد‎‎قوانين الموقع. يمكنك جعله مفضلاً لاستخدامه على الرسم البياني.

هل تريد استخدام هذا النص البرمجي على الرسم البياني؟

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