- เทคนิคที่ใช้:
- แสดงระดับสำคัญบนกราฟปัจจุบัน เช่น จุดสูง/ต่ำของวันก่อนหน้า, ข้อมูลก่อนตลาดเปิด, การปิดวันก่อน, การเปิดวันนี้, จุดพิศวง, และอื่นๆ
- ปรับแต่งได้หลากหลาย เช่น สี, สไตล์เส้น, และตัวเลือกข้อความ
- รวมระดับสำคัญที่เกิดขึ้นซ้ำกัน เพื่อความชัดเจนในกราฟ
- สัญญาณซื้อเกิดเมื่อ:
- ราคาทะลุผ่านระดับสำคัญขึ้นไปด้านบน
- ตลาดแสดงสัญญาณกลับตัวจากระดับสำคัญ
- สัญญาณขายเกิดเมื่อ:
- ราคาทะลุผ่านระดับสำคัญลงไปด้านล่าง
- ตลาดแสดงสัญญาณกลับตัวจากระดับสำคัญ
- ใช้งานในโปรแกรม TradingView https://www.tradingview.com/?aff_id=134641
- เปิดบัญชีทดลอง: การเริ่มต้นของ Passive Income https://bit.ly/3Sdkir2
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © fluxchart
//@version=5
indicator("Key Levels | FluxCharts", overlay = true, max_bars_back = 5000, max_labels_count = 500, max_lines_count = 500)
const bool DEBUG = false
const float epsilon = 0.02 / 100.0
const int showLastXPivots = 50
todayEnabled = input.bool(true, "Today ", group = "General Configuration", inline = "Today")
todayLineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "Today", display = display.none)
todayHighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "Today", display = display.none)
todayLowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "Today", display = display.none)
todayOpenLineColor = input.color(color.blue, "Open", group = "General Configuration", inline = "Today", display = display.none)
yesterdayEnabled = input.bool(true, "Yesterday ", group = "General Configuration", inline = "Yesterday")
yesterdayLineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "Yesterday", display = display.none)
yesterdayHighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "Yesterday", display = display.none)
yesterdayLowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "Yesterday", display = display.none)
yesterdayCloseLineColor = input.color(color.fuchsia, "Close", group = "General Configuration", inline = "Yesterday", display = display.none)
day3 = input.bool(false, "3rd Day ", group = "General Configuration", inline = "day3")
day3LineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "day3", display = display.none)
day3HighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "day3", display = display.none)
day3LowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "day3", display = display.none)
day4 = input.bool(false, "4th Day ", group = "General Configuration", inline = "day4")
day4LineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "day4", display = display.none)
day4HighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "day4", display = display.none)
day4LowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "day4", display = display.none)
day5 = input.bool(false, "5th Day ", group = "General Configuration", inline = "day5")
day5LineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "day5", display = display.none)
day5HighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "day5", display = display.none)
day5LowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "day5", display = display.none)
day6 = input.bool(false, "6th Day ", group = "General Configuration", inline = "day6")
day6LineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "day6", display = display.none)
day6HighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "day6", display = display.none)
day6LowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "day6", display = display.none)
day7 = input.bool(false, "7th Day ", group = "General Configuration", inline = "day7")
day7LineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "day7", display = display.none)
day7HighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "day7", display = display.none)
day7LowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "day7", display = display.none)
day8 = input.bool(false, "8th Day ", group = "General Configuration", inline = "day8")
day8LineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "day8", display = display.none)
day8HighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "day8", display = display.none)
day8LowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "day8", display = display.none)
day9 = input.bool(false, "9th Day ", group = "General Configuration", inline = "day9")
day9LineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "day9", display = display.none)
day9HighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "day9", display = display.none)
day9LowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "day9", display = display.none)
day10 = input.bool(false, "10th Day ", group = "General Configuration", inline = "day10")
day10LineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "day10", display = display.none)
day10HighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "day10", display = display.none)
day10LowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "day10", display = display.none)
preMarketEnabled = input.bool(false, "Pre-Market ", group = "General Configuration", inline = "premarket")
preMarketLineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "premarket", display = display.none)
preMarketHighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "premarket", display = display.none)
preMarketLowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "premarket", display = display.none)
previousMonthEnabled = input.bool(false, "Previous Month ", group = "General Configuration", inline = "month")
monthLineStyle = input.string("____", " ", options = ["____", "----", "...."], group = "General Configuration", inline = "month", display = display.none)
monthHighLineColor = input.color(color.green, "High", group = "General Configuration", inline = "month", display = display.none)
monthLowLineColor = input.color(color.red, "Low", group = "General Configuration", inline = "month", display = display.none)
pivotsEnabled = input.bool(false, "Enabled", group = "High & Low Pivots")
pivotRange = input.int(14, "Pivot Range", options = [7, 14, 21], group = "High & Low Pivots")
pivotHighColor = input.color(color.green, "High", group = "High & Low Pivots", inline = "style", display = display.none)
pivotLowColor = input.color(color.red, "Low", group = "High & Low Pivots", inline = "style", display = display.none)
textSizePivotIn = input.string("Normal", "Size", ["Large", "Normal", "Small"], group = "High & Low Pivots", inline = "style", display = display.none)
barOffset = input.int(20, "Text Offset", group = "Style Settings", display = display.none)
lineThickness = input.int(2, "Thickness", group = "Style Settings", options = [1,2,3,4], display = display.none)
extendLines = input.bool(true, "Extend Lines", group = "Style Settings", tooltip = "Enabled -> Extend lines infinitely.\nDisabled -> Clamp lines in their timestamps.", display = display.none)
showLineValues = input.bool(true, "Show Line Values", group = "Style Settings", display = display.none)
labelsAlign = input.string("Right", "Align Labels", options = ["Right", "Center"], group = "Style Settings", display = display.none)
textColor = input.color(color.white, "Text Color", group = "Style Settings", inline = "text", display = display.none)
textSizeIn = input.string("Normal", "Size", ["Large", "Normal", "Small"], group = "Style Settings", inline = "text", display = display.none)
textSize = (textSizeIn == "Normal" ? size.normal : (textSizeIn == "Small" ? size.small : size.large))
textSizePivot = (textSizePivotIn == "Normal" ? size.normal : (textSizePivotIn == "Small" ? size.small : size.large))
type bInfo
float h = high
float l = low
float o = open
float c = close
int t = time
curBInfo = bInfo.new()
doValuesTouch (float value1, float value2) =>
if math.abs(value1 - value2) / ((value1 + value2) / 2.0) <= epsilon
true
else
false
f_newLine(_color, _lineStyle) => line.new(na, na, na, na, xloc.bar_time, width = lineThickness ,extend = extendLines ? extend.both : extend.none, color = _color, style = _lineStyle == "____" ? line.style_solid : _lineStyle == "----" ? line.style_dashed : line.style_dotted)
f_moveLine(_line, _x, _y, _x2) =>
line.set_xy1(_line, _x, _y)
line.set_xy2(_line, _x2, _y)
f_getInfo (timeframe) =>
request.security(syminfo.tickerid, timeframe, [curBInfo, curBInfo[1], curBInfo[2], curBInfo[3], curBInfo[4], curBInfo[5], curBInfo[6], curBInfo[7], curBInfo[8], curBInfo[9]], calc_bars_count = 30)
f_calculatePreMarketHighLow (isFirstBarSeries, isPreMarketSeries, highs, lows) =>
curIndex = 0
float preMarketHighF = 0
float preMarketLowF = -1
bool foundPreMarket = false
while (isFirstBarSeries[curIndex] == false)
if isPreMarketSeries[curIndex]
foundPreMarket := true
preMarketHighF := math.max(preMarketHighF, highs[curIndex])
preMarketLowF := preMarketLowF == -1 ? lows[curIndex] : math.min(preMarketLowF, lows[curIndex])
if not isPreMarketSeries[curIndex] and foundPreMarket
break
curIndex += 1
if curIndex > 4000
break
[preMarketHighF, preMarketLowF]
type lineInfo
string[] timeNames
string[] infos
float price
int startTime
int endTime
color col
string lStyle
line zone
label lbl
bool disabled = false
type pivot
bool isHigh = false
int index
float price
float atr
label textLabel
safeDeletePivot (pivot p) =>
label.delete(p.textLabel)
createLineInfo (string timeName, string info, float p, int t, int tend, color col, string sty) =>
newLI = lineInfo.new(array.new<string>(0), array.new<string>(0), p, t, tend, col, sty)
if not na(timeName)
newLI.timeNames.unshift(timeName)
if not na (info)
newLI.infos.unshift(info)
newLI
safeDeleteLineInfo (lineInfoF) =>
line.delete(lineInfoF.zone)
label.delete(lineInfoF.lbl)
var allLineInfos = array.new<lineInfo>(0)
var allPivots = array.new<pivot>(0)
extendedTicker = ticker.modify(syminfo.tickerid, session = session.extended)
[isFirstBarSeries, preMarketSeries, preMarketLowSeries, preMarketHighSeries] = request.security(extendedTicker, "60", [session.isfirstbar, session.ispremarket, low, high])
[preMarketHigh, preMarketLow] = f_calculatePreMarketHighLow(isFirstBarSeries, preMarketSeries, preMarketHighSeries,preMarketLowSeries)
[bInfo1, bInfo2, bInfo3, bInfo4, bInfo5, bInfo6, bInfo7, bInfo8, bInfo9, bInfo10] = f_getInfo("D")
[mInfo1, mInfo2] = f_getInfo("M")
calculateLineInfos () =>
if allLineInfos.size() > 0
for i = 0 to allLineInfos.size() - 1
safeDeleteLineInfo(allLineInfos.get(i))
allLineInfos.clear()
if todayEnabled and not na(bInfo1)
allLineInfos.unshift(createLineInfo("Today", "High", bInfo1.h, bInfo1.t, time, todayHighLineColor, todayLineStyle))
allLineInfos.unshift(createLineInfo("Today", "Low", bInfo1.l, bInfo1.t, time, todayLowLineColor, todayLineStyle))
allLineInfos.unshift(createLineInfo("Today", "Open", bInfo1.o, bInfo1.t, time, todayOpenLineColor, todayLineStyle))
if yesterdayEnabled and not na(bInfo2)
allLineInfos.unshift(createLineInfo("Yesterday", "High", bInfo2.h, bInfo2.t, bInfo1.t, yesterdayHighLineColor, yesterdayLineStyle))
allLineInfos.unshift(createLineInfo("Yesterday", "Low", bInfo2.l, bInfo2.t, bInfo1.t, yesterdayLowLineColor, yesterdayLineStyle))
allLineInfos.unshift(createLineInfo("Yesterday", "Close", bInfo2.c, bInfo2.t, bInfo1.t, yesterdayCloseLineColor, yesterdayLineStyle))
if day3 and not na(bInfo3)
allLineInfos.unshift(createLineInfo("3rd Day", "High", bInfo3.h, bInfo3.t, bInfo2.t, day3HighLineColor, day3LineStyle))
allLineInfos.unshift(createLineInfo("3rd Day", "Low", bInfo3.l, bInfo3.t, bInfo2.t, day3LowLineColor, day3LineStyle))
if day4 and not na(bInfo4)
allLineInfos.unshift(createLineInfo("4th Day", "High", bInfo4.h, bInfo4.t, bInfo3.t, day4HighLineColor, day4LineStyle))
allLineInfos.unshift(createLineInfo("4th Day", "Low", bInfo4.l, bInfo4.t, bInfo3.t, day4LowLineColor, day4LineStyle))
if day5 and not na(bInfo5)
allLineInfos.unshift(createLineInfo("5th Day", "High", bInfo5.h, bInfo5.t, bInfo4.t, day5HighLineColor, day5LineStyle))
allLineInfos.unshift(createLineInfo("5th Day", "Low", bInfo5.l, bInfo5.t, bInfo4.t, day5LowLineColor, day5LineStyle))
if day6 and not na(bInfo6)
allLineInfos.unshift(createLineInfo("6th Day", "High", bInfo6.h, bInfo6.t, bInfo5.t, day6HighLineColor, day6LineStyle))
allLineInfos.unshift(createLineInfo("6th Day", "Low", bInfo6.l, bInfo6.t, bInfo5.t, day6LowLineColor, day6LineStyle))
if day7 and not na(bInfo7)
allLineInfos.unshift(createLineInfo("7th Day", "High", bInfo7.h, bInfo7.t, bInfo6.t, day7HighLineColor, day7LineStyle))
allLineInfos.unshift(createLineInfo("7th Day", "Low", bInfo7.l, bInfo7.t, bInfo6.t, day7LowLineColor, day7LineStyle))
if day8 and not na(bInfo8)
allLineInfos.unshift(createLineInfo("8th Day", "High", bInfo8.h, bInfo8.t, bInfo7.t, day8HighLineColor, day8LineStyle))
allLineInfos.unshift(createLineInfo("8th Day", "Low", bInfo8.l, bInfo8.t, bInfo7.t, day8LowLineColor, day8LineStyle))
if day9 and not na(bInfo9)
allLineInfos.unshift(createLineInfo("9th Day", "High", bInfo9.h, bInfo9.t, bInfo8.t, day9HighLineColor, day9LineStyle))
allLineInfos.unshift(createLineInfo("9th Day", "Low", bInfo9.l, bInfo9.t, bInfo8.t, day9LowLineColor, day9LineStyle))
if day10 and not na(bInfo10)
allLineInfos.unshift(createLineInfo("10th Day", "High", bInfo10.h, bInfo10.t, bInfo9.t, day10HighLineColor, day10LineStyle))
allLineInfos.unshift(createLineInfo("10th Day", "Low", bInfo10.l, bInfo10.t, bInfo9.t, day10LowLineColor, day10LineStyle))
if preMarketEnabled and not na(preMarketHigh) and not na(bInfo1)
allLineInfos.unshift(createLineInfo("Pre-Market", "High", preMarketHigh, bInfo1.t, time, preMarketHighLineColor, preMarketLineStyle))
allLineInfos.unshift(createLineInfo("Pre-Market", "Low", preMarketLow, bInfo1.t, time, preMarketHighLineColor, preMarketLineStyle))
if previousMonthEnabled and not na(mInfo2)
allLineInfos.unshift(createLineInfo("Previous Month", "High", mInfo2.h, mInfo2.t, mInfo1.t, monthLowLineColor, monthLineStyle))
allLineInfos.unshift(createLineInfo("Previous Month", "Low", mInfo2.l, mInfo2.t, mInfo1.t, monthHighLineColor, monthLineStyle))
calculateLineInfos()
combineLineInfos () =>
if allLineInfos.size() > 0
lastCombinations = 999
while lastCombinations > 0
lastCombinations := 0
for i = 0 to allLineInfos.size() - 1
curLI1 = allLineInfos.get(i)
for j = 0 to allLineInfos.size() - 1
curLI2 = allLineInfos.get(j)
if i == j
continue
if curLI1.disabled or curLI2.disabled
continue
if doValuesTouch(curLI1.price, curLI2.price) and extendLines
curLI1.disabled := true
curLI2.disabled := true
newLI = createLineInfo(na, na, curLI1.price, na, na, na, na)
if curLI1.timeNames.size() > 0
for a = 0 to curLI1.timeNames.size() - 1
newLI.timeNames.unshift(curLI1.timeNames.get(a))
for a = 0 to curLI1.infos.size() - 1
newLI.infos.unshift(curLI1.infos.get(a))
if curLI2.timeNames.size() > 0
for a = 0 to curLI2.timeNames.size() - 1
newLI.timeNames.unshift(curLI2.timeNames.get(a))
for a = 0 to curLI2.infos.size() - 1
newLI.infos.unshift(curLI2.infos.get(a))
newLI.startTime := math.min(curLI1.startTime, curLI2.startTime)
newLI.endTime := math.max(curLI1.endTime, curLI2.endTime)
newLI.col := curLI1.col
newLI.lStyle := curLI1.lStyle
allLineInfos.unshift(newLI)
lastCombinations += 1
renderPivot (pivot pivotF) =>
pivotF.textLabel := label.new(pivotF.index, pivotF.price + (pivotF.atr * 1 * (pivotF.isHigh ? 1 : -1)), str.tostring(pivotF.price, format.mintick), style = label.style_none, size = textSizePivot, textcolor = (pivotF.isHigh ? pivotHighColor : pivotLowColor))
renderLineInfo (lineInfoF) =>
safeDeleteLineInfo(lineInfoF)
if not lineInfoF.disabled
lineInfoF.zone := f_newLine(lineInfoF.col, lineInfoF.lStyle)
if lineInfoF.startTime == lineInfoF.endTime
lineInfoF.endTime += 1
f_moveLine(lineInfoF.zone, lineInfoF.startTime, lineInfoF.price, lineInfoF.endTime)
lblText = ""
if lineInfoF.timeNames.size() > 0
for i = 0 to lineInfoF.timeNames.size() - 1
lblText += lineInfoF.timeNames.get(i) + " "
lblText += lineInfoF.infos.get(i)
if i != lineInfoF.timeNames.size() - 1
lblText += " & "
if showLineValues
lblText += " (" + str.tostring(lineInfoF.price, format.mintick) + ")"
if extendLines
lineInfoF.lbl := label.new(labelsAlign == "Center" ? ((chart.right_visible_bar_time + chart.left_visible_bar_time) / 2) : (last_bar_index + barOffset), lineInfoF.price, textcolor = textColor, text = lblText, style = label.style_none, xloc = labelsAlign == "Center" ? xloc.bar_time : xloc.bar_index, size = textSize)
else
lineInfoF.lbl := label.new(labelsAlign == "Center" ? (lineInfoF.startTime + lineInfoF.endTime) / 2 : lineInfoF.endTime, lineInfoF.price, xloc = xloc.bar_time, textcolor = textColor, text = lblText, style = label.style_none, size = textSize)
renderLineInfos () =>
if allLineInfos.size() > 0
for i = 0 to allLineInfos.size() - 1
curLineInfo = allLineInfos.get(i)
renderLineInfo(curLineInfo)
renderPivots () =>
if allPivots.size() > 0
for i = 0 to allPivots.size() - 1
curPivot = allPivots.get(i)
safeDeletePivot(curPivot)
renderPivot(curPivot)
combineLineInfos()
renderLineInfos()
pivotHigh = ta.pivothigh(pivotRange, pivotRange)
pivotLow = ta.pivotlow(pivotRange, pivotRange)
curAtr = ta.atr(5)
if not na(pivotHigh)
allPivots.unshift(pivot.new(true, bar_index - pivotRange, pivotHigh, curAtr))
if not na(pivotLow)
allPivots.unshift(pivot.new(false, bar_index - pivotRange, pivotLow, curAtr))
if allPivots.size() > showLastXPivots
allPivots.remove(allPivots.size() - 1)
if barstate.islast
if pivotsEnabled
renderPivots()
https://www.tradingview.com/script/sKL8A9lE-Key-Levels-Flux-Charts/