OPEN-SOURCE SCRIPT
OBV ATR Strategy (OBV Breakout Channel) bas20230503

ผมแก้ไขจาก OBV+SMA อันเดิม ของเดิม ดูที่เส้น SMA สองเส้นตัดกันมั่นห่วยแตกสำหรับที่ผมลองเทรดจริง และหลักการเบรค ได้แรงบันดาลใจ ATR จาก เทพคอย ที่ใช้กับราคา แต่นี้ใช้กับ OBV แทน
และผมใช้เจมินี้ เพื่อแก้ ให้ เป็น strategy เพื่อเช็คย้อนหลังได้ง่ายกว่าเดิม
หลักการง่ายคือถ้ามันขึ้น มันจะขึ้นเรื่อยๆ
เขียน แบบสุภาพ (น่าจะอ่านได้ง่ายกว่าผมเขียน)
สคริปต์นี้ได้รับการพัฒนาต่อยอดจากแนวคิด OBV+SMA Crossover แบบดั้งเดิม ซึ่งจากการทดสอบส่วนตัวพบว่าประสิทธิภาพยังไม่น่าพอใจ กลยุทธ์ใหม่นี้จึงเปลี่ยนมาใช้หลักการ "Breakout" ซึ่งได้รับแรงบันดาลใจมาจากการใช้ ATR สร้างกรอบของราคา แต่เราได้นำมาประยุกต์ใช้กับ On-Balance Volume (OBV) แทน นอกจากนี้ สคริปต์ได้ถูกแปลงเป็น Strategy เต็มรูปแบบ (โดยความช่วยเหลือจาก Gemini AI) เพื่อให้สามารถทดสอบย้อนหลัง (Backtest) และประเมินประสิทธิภาพได้อย่างแม่นยำ
หลักการของกลยุทธ์: กลยุทธ์นี้ทำงานบนแนวคิดโมเมนตัมที่ว่า "เมื่อแนวโน้มได้เกิดขึ้นแล้ว มีโอกาสที่มันจะดำเนินต่อไป" โดยจะมองหาการทะลุของพลังซื้อ-ขาย (OBV) ที่แข็งแกร่งเป็นพิเศษเป็นสัญญาณเข้าเทร
----
สคริปต์นี้เป็นกลยุทธ์ (Strategy) ที่ใช้ On-Balance Volume (OBV) ซึ่งเป็นอินดิเคเตอร์ที่วัดแรงซื้อและแรงขายสะสม แทนที่จะใช้การตัดกันของเส้นค่าเฉลี่ย (SMA Crossover) ที่เป็นแบบพื้นฐาน กลยุทธ์นี้จะมองหาการ "ทะลุ" (Breakout) ของพลัง OBV ออกจากกรอบสูงสุด-ต่ำสุดของตัวเองในรอบที่ผ่านมา
สัญญาณกระทิง (Bull Signal): เกิดขึ้นเมื่อพลังการซื้อ (OBV) แข็งแกร่งจนสามารถทะลุจุดสูงสุดของตัวเองในอดีตได้ บ่งบอกถึงโอกาสที่แนวโน้มจะเปลี่ยนเป็นขาขึ้น
สัญญาณหมี (Bear Signal): เกิดขึ้นเมื่อพลังการขาย (OBV) รุนแรงจนสามารถกดดันให้ OBV ทะลุจุดต่ำสุดของตัวเองในอดีตได้ บ่งบอกถึงโอกาสที่แนวโน้มจะเปลี่ยนเป็นขาลง
ส่วนประกอบบนกราฟ (Indicator Components)
เส้น OBV
เส้นหลัก ที่เปลี่ยนเขียวเป็นแดง เป็นทั้งแนวรับและแนวต้าน และ จุด stop loss
เส้นนี้คือหัวใจของอินดิเคเตอร์ ที่แสดงถึงพลังสะสมของ Volume
เมื่อเส้นเป็นสีเขียว (แนวรับ): จะปรากฏขึ้นเมื่อกลยุทธ์เข้าสู่ "โหมดกระทิง" เส้นนี้คือระดับต่ำสุดของ OBV ในอดีต และทำหน้าที่เป็นแนวรับไดนามิก
เมื่อเส้นกลายเป็นสีแดงสีแดง (แนวต้าน): จะปรากฏขึ้นเมื่อกลยุทธ์เข้าสู่ "โหมดหมี" เส้นนี้คือระดับสูงสุดของ OBV ในอดีต และทำหน้าที่เป็นแนวต้านไดนามิก
สัญลักษณ์สัญญาณ (Signal Markers):
Bull 🔼 (สามเหลี่ยมขึ้นสีเขียว): คือสัญญาณ "เข้าซื้อ" (Long) จะปรากฏขึ้น ณ จุดที่ OBV ทะลุขึ้นไปเหนือกรอบด้านบนเป็นครั้งแรก
Bear 🔽 (สามเหลี่ยมลงสีแดง): คือสัญญาณ "เข้าขาย" (Short) จะปรากฏขึ้น ณ จุดที่ OBV ทะลุลงไปต่ำกว่ากรอบด้านล่างเป็นครั้งแรก
วิธีการใช้งาน (How to Use)
เพิ่มสคริปต์นี้ลงบนกราฟราคาที่คุณสนใจ
ไปที่แท็บ "Strategy Tester" ด้านล่างของ TradingView เพื่อดูผลการทดสอบย้อนหลัง (Backtest) ของกลยุทธ์บนสินทรัพย์และไทม์เฟรมต่างๆ
ใช้สัญลักษณ์ "Bull" และ "Bear" เป็นตัวช่วยในการตัดสินใจเข้าเทรด
ข้อควรจำ: ไม่มีกลยุทธ์ใดที่สมบูรณ์แบบ 100% ควรใช้สคริปต์นี้ร่วมกับการวิเคราะห์ปัจจัยอื่นๆ เช่น โครงสร้างราคา, แนวรับ-แนวต้านของราคา และการบริหารความเสี่ยง (Risk Management) ของตัวคุณเองเสมอ
การตั้งค่า (Inputs)
SMA Length 1 / SMA Length 2: ใช้สำหรับพล็อตเส้นค่าเฉลี่ยของ OBV เพื่อดูเป็นภาพอ้างอิง ไม่มีผลต่อตรรกะการเข้า-ออกของ Strategy อันใหม่ แต่มันเป็นของเก่า ถ้าชอบ ก็ใช้ได้ เมื่อ SMA สองเส้นตัดกัน หรือตัดกับเส้น OBV
High/Low Lookback Length: (ค่าพื้นฐาน30/แก้ตรงนี้ให้เหมาะสมกับ coin หรือหุ้น ตามความผันผวน ) คือระยะเวลาที่ใช้ในการคำนวณกรอบสูงสุด-ต่ำสุดของ OBV
ค่าน้อย: ทำให้กรอบแคบลง สัญญาณจะเกิดไวและบ่อยขึ้น แต่อาจมีสัญญาณหลอก (False Signal) เยอะขึ้น
ค่ามาก: ทำให้กรอบกว้างขึ้น สัญญาณจะเกิดช้าลงและน้อยลง แต่มีแนวโน้มที่จะเป็นสัญญาณที่แข็งแกร่งกว่า
แน่นอนครับ นี่คือคำแปลฉบับภาษาอังกฤษที่สรุปใจความสำคัญ กระชับ และสุภาพ เหมาะสำหรับนำไปใช้ในคำอธิบายสคริปต์ (Description) ของ TradingView ครับ
---Translate to English---
OBV Breakout Channel Strategy
[ Developer's Note ]
This script is an evolution of a traditional OBV+SMA Crossover concept. Through personal testing, the original crossover method was found to have unsatisfactory performance. This new strategy, therefore, uses a "Breakout" principle. The inspiration comes from using ATR to create price channels, but this concept has been adapted and applied to On-Balance Volume (OBV) instead.
Furthermore, the script has been converted into a full Strategy (with assistance from Gemini AI) to enable precise backtesting and performance evaluation.
The strategy's core principle is momentum-based: "once a trend is established, it is likely to continue." It seeks to enter trades on exceptionally strong breakouts of buying or selling pressure as measured by OBV.
Core Concept
This is a Strategy that uses On-Balance Volume (OBV), an indicator that measures cumulative buying and selling pressure. Instead of relying on a basic Simple Moving Average (SMA) Crossover, this strategy identifies a "Breakout" of the OBV from its own highest-high and lowest-low channel over a recent period.
Bull Signal: Occurs when the buying pressure (OBV) is strong enough to break above its own recent highest high, indicating a potential shift to an upward trend.
Bear Signal: Occurs when the selling pressure (OBV) is intense enough to push the OBV below its own recent lowest low, indicating a potential shift to a downward trend.
On-Screen Components
1. OBV Line
This is the main indicator line, representing the cumulative volume. Its color changes to green when OBV is rising and red when it is falling.
2. Dynamic Support & Resistance Line
This is the thick Green or Red line that appears based on the strategy's current "mode." This line serves as a dynamic support/resistance level and can be used as a reference for stop-loss placement.
Green Line (Support): Appears when the strategy enters "Bull Mode." This line represents the lowest low of the OBV in the recent past and acts as dynamic support.
Red Line (Resistance): Appears when the strategy enters "Bear Mode." This line represents the highest high of the OBV in the recent past and acts as dynamic resistance.
3. Signal Markers
Bull 🔼 (Green Up Triangle): This is the "Long Entry" signal. It appears at the moment the OBV first breaks out above its high-low channel.
Bear 🔽 (Red Down Triangle): This is the "Short Entry" signal. It appears at the moment the OBV first breaks down below its high-low channel.
How to Use
Add this script to the price chart of your choice.
Navigate to the "Strategy Tester" panel at the bottom of TradingView to view the backtesting results for the strategy on different assets and timeframes.
Use the "Bull" and "Bear" signals as aids in your trading decisions.
Disclaimer: No strategy is 100% perfect. This script should always be used in conjunction with other forms of analysis, such as price structure, key price-based support/resistance levels, and your own personal risk management rules.
Inputs
SMA Length 1 / SMA Length 2: These are used to plot moving averages on the OBV for visual reference. They are part of the legacy logic and do not affect the new breakout strategy. However, they are kept for traders who may wish to observe their crossovers for additional confirmation.
High/Low Lookback Length: (Most Important Setting) This determines the period used to calculate the highest-high and lowest-low OBV channel. (Default is 30; adjust this to suit the asset's volatility).
A smaller value: Creates a narrower channel, leading to more frequent and faster signals, but potentially more false signals.
A larger value: Creates a wider channel, leading to fewer and slower signals, which are likely to be more significant.
และผมใช้เจมินี้ เพื่อแก้ ให้ เป็น strategy เพื่อเช็คย้อนหลังได้ง่ายกว่าเดิม
หลักการง่ายคือถ้ามันขึ้น มันจะขึ้นเรื่อยๆ
เขียน แบบสุภาพ (น่าจะอ่านได้ง่ายกว่าผมเขียน)
สคริปต์นี้ได้รับการพัฒนาต่อยอดจากแนวคิด OBV+SMA Crossover แบบดั้งเดิม ซึ่งจากการทดสอบส่วนตัวพบว่าประสิทธิภาพยังไม่น่าพอใจ กลยุทธ์ใหม่นี้จึงเปลี่ยนมาใช้หลักการ "Breakout" ซึ่งได้รับแรงบันดาลใจมาจากการใช้ ATR สร้างกรอบของราคา แต่เราได้นำมาประยุกต์ใช้กับ On-Balance Volume (OBV) แทน นอกจากนี้ สคริปต์ได้ถูกแปลงเป็น Strategy เต็มรูปแบบ (โดยความช่วยเหลือจาก Gemini AI) เพื่อให้สามารถทดสอบย้อนหลัง (Backtest) และประเมินประสิทธิภาพได้อย่างแม่นยำ
หลักการของกลยุทธ์: กลยุทธ์นี้ทำงานบนแนวคิดโมเมนตัมที่ว่า "เมื่อแนวโน้มได้เกิดขึ้นแล้ว มีโอกาสที่มันจะดำเนินต่อไป" โดยจะมองหาการทะลุของพลังซื้อ-ขาย (OBV) ที่แข็งแกร่งเป็นพิเศษเป็นสัญญาณเข้าเทร
----
สคริปต์นี้เป็นกลยุทธ์ (Strategy) ที่ใช้ On-Balance Volume (OBV) ซึ่งเป็นอินดิเคเตอร์ที่วัดแรงซื้อและแรงขายสะสม แทนที่จะใช้การตัดกันของเส้นค่าเฉลี่ย (SMA Crossover) ที่เป็นแบบพื้นฐาน กลยุทธ์นี้จะมองหาการ "ทะลุ" (Breakout) ของพลัง OBV ออกจากกรอบสูงสุด-ต่ำสุดของตัวเองในรอบที่ผ่านมา
สัญญาณกระทิง (Bull Signal): เกิดขึ้นเมื่อพลังการซื้อ (OBV) แข็งแกร่งจนสามารถทะลุจุดสูงสุดของตัวเองในอดีตได้ บ่งบอกถึงโอกาสที่แนวโน้มจะเปลี่ยนเป็นขาขึ้น
สัญญาณหมี (Bear Signal): เกิดขึ้นเมื่อพลังการขาย (OBV) รุนแรงจนสามารถกดดันให้ OBV ทะลุจุดต่ำสุดของตัวเองในอดีตได้ บ่งบอกถึงโอกาสที่แนวโน้มจะเปลี่ยนเป็นขาลง
ส่วนประกอบบนกราฟ (Indicator Components)
เส้น OBV
เส้นหลัก ที่เปลี่ยนเขียวเป็นแดง เป็นทั้งแนวรับและแนวต้าน และ จุด stop loss
เส้นนี้คือหัวใจของอินดิเคเตอร์ ที่แสดงถึงพลังสะสมของ Volume
เมื่อเส้นเป็นสีเขียว (แนวรับ): จะปรากฏขึ้นเมื่อกลยุทธ์เข้าสู่ "โหมดกระทิง" เส้นนี้คือระดับต่ำสุดของ OBV ในอดีต และทำหน้าที่เป็นแนวรับไดนามิก
เมื่อเส้นกลายเป็นสีแดงสีแดง (แนวต้าน): จะปรากฏขึ้นเมื่อกลยุทธ์เข้าสู่ "โหมดหมี" เส้นนี้คือระดับสูงสุดของ OBV ในอดีต และทำหน้าที่เป็นแนวต้านไดนามิก
สัญลักษณ์สัญญาณ (Signal Markers):
Bull 🔼 (สามเหลี่ยมขึ้นสีเขียว): คือสัญญาณ "เข้าซื้อ" (Long) จะปรากฏขึ้น ณ จุดที่ OBV ทะลุขึ้นไปเหนือกรอบด้านบนเป็นครั้งแรก
Bear 🔽 (สามเหลี่ยมลงสีแดง): คือสัญญาณ "เข้าขาย" (Short) จะปรากฏขึ้น ณ จุดที่ OBV ทะลุลงไปต่ำกว่ากรอบด้านล่างเป็นครั้งแรก
วิธีการใช้งาน (How to Use)
เพิ่มสคริปต์นี้ลงบนกราฟราคาที่คุณสนใจ
ไปที่แท็บ "Strategy Tester" ด้านล่างของ TradingView เพื่อดูผลการทดสอบย้อนหลัง (Backtest) ของกลยุทธ์บนสินทรัพย์และไทม์เฟรมต่างๆ
ใช้สัญลักษณ์ "Bull" และ "Bear" เป็นตัวช่วยในการตัดสินใจเข้าเทรด
ข้อควรจำ: ไม่มีกลยุทธ์ใดที่สมบูรณ์แบบ 100% ควรใช้สคริปต์นี้ร่วมกับการวิเคราะห์ปัจจัยอื่นๆ เช่น โครงสร้างราคา, แนวรับ-แนวต้านของราคา และการบริหารความเสี่ยง (Risk Management) ของตัวคุณเองเสมอ
การตั้งค่า (Inputs)
SMA Length 1 / SMA Length 2: ใช้สำหรับพล็อตเส้นค่าเฉลี่ยของ OBV เพื่อดูเป็นภาพอ้างอิง ไม่มีผลต่อตรรกะการเข้า-ออกของ Strategy อันใหม่ แต่มันเป็นของเก่า ถ้าชอบ ก็ใช้ได้ เมื่อ SMA สองเส้นตัดกัน หรือตัดกับเส้น OBV
High/Low Lookback Length: (ค่าพื้นฐาน30/แก้ตรงนี้ให้เหมาะสมกับ coin หรือหุ้น ตามความผันผวน ) คือระยะเวลาที่ใช้ในการคำนวณกรอบสูงสุด-ต่ำสุดของ OBV
ค่าน้อย: ทำให้กรอบแคบลง สัญญาณจะเกิดไวและบ่อยขึ้น แต่อาจมีสัญญาณหลอก (False Signal) เยอะขึ้น
ค่ามาก: ทำให้กรอบกว้างขึ้น สัญญาณจะเกิดช้าลงและน้อยลง แต่มีแนวโน้มที่จะเป็นสัญญาณที่แข็งแกร่งกว่า
แน่นอนครับ นี่คือคำแปลฉบับภาษาอังกฤษที่สรุปใจความสำคัญ กระชับ และสุภาพ เหมาะสำหรับนำไปใช้ในคำอธิบายสคริปต์ (Description) ของ TradingView ครับ
---Translate to English---
OBV Breakout Channel Strategy
[ Developer's Note ]
This script is an evolution of a traditional OBV+SMA Crossover concept. Through personal testing, the original crossover method was found to have unsatisfactory performance. This new strategy, therefore, uses a "Breakout" principle. The inspiration comes from using ATR to create price channels, but this concept has been adapted and applied to On-Balance Volume (OBV) instead.
Furthermore, the script has been converted into a full Strategy (with assistance from Gemini AI) to enable precise backtesting and performance evaluation.
The strategy's core principle is momentum-based: "once a trend is established, it is likely to continue." It seeks to enter trades on exceptionally strong breakouts of buying or selling pressure as measured by OBV.
Core Concept
This is a Strategy that uses On-Balance Volume (OBV), an indicator that measures cumulative buying and selling pressure. Instead of relying on a basic Simple Moving Average (SMA) Crossover, this strategy identifies a "Breakout" of the OBV from its own highest-high and lowest-low channel over a recent period.
Bull Signal: Occurs when the buying pressure (OBV) is strong enough to break above its own recent highest high, indicating a potential shift to an upward trend.
Bear Signal: Occurs when the selling pressure (OBV) is intense enough to push the OBV below its own recent lowest low, indicating a potential shift to a downward trend.
On-Screen Components
1. OBV Line
This is the main indicator line, representing the cumulative volume. Its color changes to green when OBV is rising and red when it is falling.
2. Dynamic Support & Resistance Line
This is the thick Green or Red line that appears based on the strategy's current "mode." This line serves as a dynamic support/resistance level and can be used as a reference for stop-loss placement.
Green Line (Support): Appears when the strategy enters "Bull Mode." This line represents the lowest low of the OBV in the recent past and acts as dynamic support.
Red Line (Resistance): Appears when the strategy enters "Bear Mode." This line represents the highest high of the OBV in the recent past and acts as dynamic resistance.
3. Signal Markers
Bull 🔼 (Green Up Triangle): This is the "Long Entry" signal. It appears at the moment the OBV first breaks out above its high-low channel.
Bear 🔽 (Red Down Triangle): This is the "Short Entry" signal. It appears at the moment the OBV first breaks down below its high-low channel.
How to Use
Add this script to the price chart of your choice.
Navigate to the "Strategy Tester" panel at the bottom of TradingView to view the backtesting results for the strategy on different assets and timeframes.
Use the "Bull" and "Bear" signals as aids in your trading decisions.
Disclaimer: No strategy is 100% perfect. This script should always be used in conjunction with other forms of analysis, such as price structure, key price-based support/resistance levels, and your own personal risk management rules.
Inputs
SMA Length 1 / SMA Length 2: These are used to plot moving averages on the OBV for visual reference. They are part of the legacy logic and do not affect the new breakout strategy. However, they are kept for traders who may wish to observe their crossovers for additional confirmation.
High/Low Lookback Length: (Most Important Setting) This determines the period used to calculate the highest-high and lowest-low OBV channel. (Default is 30; adjust this to suit the asset's volatility).
A smaller value: Creates a narrower channel, leading to more frequent and faster signals, but potentially more false signals.
A larger value: Creates a wider channel, leading to fewer and slower signals, which are likely to be more significant.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。