OPEN-SOURCE SCRIPT
Telah dikemas kini 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.
Nota Keluaran
new มีการอัพเดตใหม่ จาก การแจ้งเตือนของ modeโดยที่เพิ่มค่าคอมมิตชั่นเป็น 0.2% และ ใช้เงินในพอร์ต 5% และขนาดของพอร์ต เหลืออ 1,000.- หรือ เทรดครั้งละ 50
เพิ่มค่า Slippage =5 (ความคลาดเคลื่อนของราคา)
New Update: Based on a notification from the moderator.
I have updated the strategy with the following settings for more realistic backtesting:
Added a commission of 0.2%.
Set the initial capital to 1,000, with each trade using 5% of the portfolio's equity (trade size of 50).
Added a slippage of 5 ticks to account for price deviation.
// bas20230503 แก้ไขจาก OBV+SMA อันเดิมที่โดนแบนไปก่อนหน้า เปลี่ยนจาก indicator เป็น strategy แก้ไขโดย เจมมินี้ เพื่อเช็คย้อนหลังได้ และ ของเดิม ดูที่เส้น SMA สองเส้นตัดกันมั่นห่วยแตก และใช้ได้แรงบันดาลใจ ATR จาก เทพคอย ที่ใช้กับราคา แต่นี้ใช้กับ OBV แทน
strategy(title="OBV ATR Strategy v1.4 (OBV Breakout Channel) bas20230503 v0.3",
shorttitle="OBV Breakout3",
overlay=false,
precision=0,
//เงิน
initial_capital=1000,
// เพิ่มค่าคอมมิชชั่น
commission_value=0.2,
commission_type=strategy.commission.percent,
// เพิ่มค่า Slippage (ความคลาดเคลื่อนของราคา)
slippage = 5,
// การบริหารเงินทุน
default_qty_type=strategy.percent_of_equity,
//เงินที่ลงจากพอร์ต %
default_qty_value=5,
pyramiding=0)
// === Inputs1 ===
// สร้างช่องสำหรับกรอกค่า Slippage โดยมีค่าเริ่มต้น = 5
slippage_input = input.int(defval=5, title="Slippage (in Ticks)", minval=0)
//ระยะเลนส์ใคาการคำนวน ปกติ ใช้ 100 จะดี เริ่มต้นให้มีค่า 30
len_high_low = input.int(30, minval=1, title="High/Low Lookback Length")
// === Inputs2 === ลบออกดีไหม
len1 = input.int(30, minval=1, title="SMA Length 1")
len2 = input.int(14, minval=2, title="SMA Length 2")
// === Calculate OBV manually ===
// OBV = cumulative sum of volume signed by price change
obvVal = ta.cum(volume * math.sign(close - close[1]))
// === Compute SMAs on OBV ===
sma1 = ta.sma(obvVal, len1)
sma2 = ta.sma(obvVal, len2)
// === ลูกเล่นเปลี่ยนสี ===
isObvUp = obvVal > obvVal[1]
isObvDown = obvVal < obvVal[1]
obvColor = isObvUp ? color.new(color.green, 15) : isObvDown ? color.new(color.red, 15) : color.new(color.gray, 15)
// === Plot OBV & SMAs ===
plot(obvVal, title="OBV", color=obvColor, linewidth=2, style=plot.style_stepline)
plot(sma1, title="SMA1", color=color.new(#33AEC4, 0), linewidth=2)
plot(sma2, title="SMA2", color=color.new(color.orange, 0), style=plot.style_circles)
// === หาจุดสูงสุดตำสุดของ OBV ===
obv_high = ta.highest(obvVal, len_high_low)
obv_low = ta.lowest(obvVal, len_high_low)
// เพิ่มโค้ด 2 บรรทัดนี้เพื่อวาดเส้นสีเทา บนล่าง ของ OBV
plot(obv_high, title="OBV High", color=color.new(color.gray, 30), style=plot.style_stepline, linewidth=1)
plot(obv_low, title="OBV Low", color=color.new(color.gray, 30), style=plot.style_stepline, linewidth=1)
// === START: Dynamic TRACKING S/R Logic (ตรรกะใหม่แบบขยับตาม ของเดิม มันห่างไม่แนบ) ===
// 1. สร้างตัวแปร "mode" เพื่อจำสภาวะปัจจุบัน
// mode = 1 หมายถึง วัว (ตามเส้น High)
// mode = -1 หมายถึง หมีตะปบปากจ้า (ตามเส้น Low)
var int mode = 0
// 2. ตรวจจับการเปลี่ยน
if ta.crossover(obvVal, obv_high[1])
mode := 1 // เปลี่ยนเป็นโหมดกระทิง
if ta.crossunder(obvVal, obv_low[1])
mode := -1 // เปลี่ยนเป็นโหมดหมี
// 3. กำหนดค่าและสีที่จะพล็อตตาม "mode" ปัจจุบัน
float plotValue = na
color plotColor = na
if mode == 1
// ถ้าอยู่ในโหมดกระทิง ให้เส้นอยู่ล่าง และเป็นสีเขียว
plotValue := obv_low
plotColor := color.new(color.green, 0)
else if mode == -1
// ถ้าอยู่ในโหมดหมี เส้นอยู่บนดิ และเป็นสีแดง
plotValue := obv_high
plotColor := color.new(color.red, 0)
// 4. วาดเส้น Trendline
plot(plotValue, title="Dynamic Tracking S/R", color=plotColor, linewidth=2)
// === START: Bull/Bear Signals based on mode change ===
// ตรวจจับสัญญาณ Bull (เมื่อ mode เปลี่ยนเป็น 1 จากค่าอื่น)
bool bullSignal = mode == 1 and mode[1] != 1
// ตรวจจับสัญญาณ Bear (เมื่อ mode เปลี่ยนเป็น -1 จากค่าอื่น)
bool bearSignal = mode == -1 and mode[1] != -1
// พล็อตสัญลักษณ์ Bull โดยอยู่ใต้เส้น OBV เล็กน้อย
plotshape(bullSignal ? obv_low: na, title="Bull Signal", style=shape.triangleup, location=location.absolute, color=color.new(color.lime, 0), size=size.small, text="Bull",textcolor = color.green)
// พล็อตสัญลักษณ์ Bear โดยอยู่เหนือเส้น OBV เล็กน้อย
plotshape(bearSignal ? obv_high : na, title="Bear Signal", style=shape.triangledown, location=location.absolute, color=color.new(color.red, 0), size=size.small, text="Bear",textcolor = color.red)
// === END: Bull/Bear Signals ===
// === START: Strategy Logic (ปรับปรุงใหม่) ===
// เงื่อนไขในการเปิด Long Position (Buy)
if bullSignal
// ปิดออร์เดอร์ Short ที่อาจจะเปิดอยู่ก่อนหน้า (ถ้ามี)
strategy.close("Short", comment="Close Short for new Long")
// แล้วจึงเปิดออร์เดอร์ Long ใหม่
strategy.entry("Long", strategy.long)
// เงื่อนไขในการเปิด Short Position (Sell)
if bearSignal
// ปิดออร์เดอร์ Long ที่อาจจะเปิดอยู่ก่อนหน้า (ถ้ามี) ตามที่ต้องการ
strategy.close("Long", comment="Close Long for new Short")
// แล้วจึงเปิดออร์เดอร์ Short ใหม่
strategy.entry("Short", strategy.short)
// === END: Strategy Logic ===
Nota Keluaran
การปรับปรุงล่าสุดจากที่modแจ้งเตือน:ใช้เงินในพอร์ต 5% ต่อไม้
ค่าคอมมิชชัน 0.2%
Slippage = 5
พอร์ตจำลองขนาด 1,000.- (เทรดไม้ละ 50)
กลยุทธ์ OBV Breakout Strategy
สคริปต์นี้พัฒนาต่อยอด และได้รับแรงบันดาลใจจากการใช้ เทพคอยน์-ATR สร้างกรอบเบรก โดยเปลี่ยนจากราคาเป็น OBV
กลยุทธ์นี้ตั้งอยู่บนแนวคิดว่า "เมื่อแนวโน้มเริ่มแล้ว มักจะต่อเนื่อง" หาก OBV ทะลุกรอบสูงสุดหรือต่ำสุดในอดีต จะเกิดสัญญาณเข้าเทรด
หลักการทำงาน:
Bull Signal 🔼: OBV ทะลุจุดสูงสุดในอดีต = สัญญาณ Long
Bear Signal 🔽: OBV ทะลุจุดต่ำสุดในอดีต = สัญญาณ Short
เส้น OBV: ใช้เป็นแนวรับ/แนวต้าน และ Stop Loss ตามโหมดตลาด (สีเขียว/แดง)
การตั้งค่า:
OBV High/Low Lookback: กำหนดช่วงเวลาสำหรับหากรอบเบรก (ค่าน้อย = สัญญาณไว/หลอก, ค่ามาก = นาน/ช้า/หลอกน้อย)
SMA 1 / SMA 2:เป็นเส้นอ้างอิงจากกลยุทธ์เวอร์ชันเก่า ไม่ได้มีผลต่อตรรกะการ Breakout ในปัจจุบัน แต่ถูกคงไว้สำหรับผู้ที่ต้องการใช้ดูการตัดกันของเส้นเพื่อเป็นข้อมูลประกอบ
และ จริงๆ ไว้ดูความผิดปกติของเทรนระยะยาว ในบ้างครั้งที่ราคา สวนทางกับ OBV ต้องเตรียมตัว
ไม่มีกลยุทธ์ใดที่สมบูรณ์แบบ 100% ควรใช้สคริปต์นี้ร่วมกับการวิเคราะห์ปัจจัยอื่น ๆ และการบริหารความเสี่ยงของตนเองเสมอ
---Translate to English---
Recent Update (To Comply with Moderator Requirements):
Order Size: 5% of equity per trade
Commission: 0.2%
Slippage: 5 ticks
Initial Capital: 1,000 (resulting in a trade size of 50)
OBV Breakout Strategy
This script is an evolution inspired by the "Thepcoin-ATR" concept of creating breakout channels, but it applies this principle to On-Balance Volume (OBV) instead of price.
The strategy is based on the momentum principle that "once a trend begins, it often continues." A trade signal is generated when the OBV breaks out of its recent highest-high or lowest-low channel.
How It Works:
Bull Signal 🔼: Occurs when OBV breaks above its recent highest high, signaling a Long entry.
Bear Signal 🔽: Occurs when OBV breaks below its recent lowest low, signaling a Short entry.
OBV Line: Serves as a dynamic support/resistance level and a reference for a Stop Loss, depending on the market mode (indicated by green/red color).
Additional Use: Spotting Divergence
This script is also highly effective for observing long-term trend anomalies. For instance, when the price moves contrary to the OBV (e.g., price makes a new high while OBV does not), it serves as an early warning to prepare for a potential trend reversal.
Inputs:
OBV High/Low Lookback: Defines the period for calculating the breakout channel.
A smaller value creates a narrower channel, leading to faster, more frequent signals but with potentially more false signals.
A larger value creates a wider channel, leading to slower, less frequent signals that are generally more reliable.
SMA 1 / SMA 2: These are reference lines from a legacy version of the strategy. They do not affect the current breakout logic but are kept for users who wish to observe their crossovers for additional information.
Disclaimer: No strategy is 100% perfect. This script should always be used in conjunction with other forms of analysis and your own personal risk management rules.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.