OPEN-SOURCE SCRIPT
ที่อัปเดต: Martingale Range Breakout

# Martingale Range Breakout
**Martingale Range Breakout** is a session-based breakout and flip-tracking indicator designed to study range expansion behavior after a defined range.
This script builds a custom time-based range, tracks breakout direction, monitors flip attempts, and displays live trade-state data with rolling performance stats directly on the chart.
---
## Core Concept
The indicator creates a range from a selected session window.
By default, the range is built from:
**8:00 AM – 8:50 AM New York Time**
Once the range locks, the script watches for price to break above or below the range.
* Break above the range = **Long Active**
* Break below the range = **Short Active**
* If price reverses and breaks the opposite side, the script counts that as a **flip**
* If price reaches the full range extension before 4 flips, it marks the setup as a **WIN**
* If the setup reaches 4 flips, it marks the setup as a **LOSS**
---
## Martingale Flip Logic
This indicator is based on a Martingale-style flip model.
The idea is that when a breakout fails and price flips to the opposite side of the range, the next position size is increased to help recover the previous failed attempt.
Example position sequence:
* Flip 1: **1 contract**
* Flip 2: **2 contracts**
* Flip 3: **4 contracts**
* Flip 4: **Loss**
Each flip represents the market failing in one direction and then triggering the opposite side of the range.
The goal of the Martingale model is for the final successful breakout to recover the previous failed flips and still finish the sequence in profit.
The table tracks the current trade state and flip count, allowing traders to see what stage of the Martingale sequence the setup is currently in.
---
## Visual Range Boxes
The script draws two clean visual zones on the chart.
**Yellow Box**
Shows the original session range.
**Green Box**
Shows the full expansion zone based on the range size.
The final target levels are calculated as:
* Buy final target = **Range High + Full Range Distance**
* Sell final target = **Range Low - Full Range Distance**
This makes it easy to see both the breakout levels and the final expansion targets.
---
## Live Trade State Tracking
The table displays the current setup condition in real time.
Possible states include:
* **WAITING**
* **LONG ACTIVE**
* **SHORT ACTIVE**
* **WIN**
* **LOSS**
The table also shows the current flip count, helping traders quickly identify how many times the setup has reversed.
---
## Built-In Rolling Statistics
The indicator tracks the last selected number of completed setups and displays performance data inside the chart table.
Stats include:
* Last N trade count
* Wins and losses
* Rolling win rate
* Rolling R total
* Average winning range size
* Average losing range size
* Current range size
* Win sample count
* Loss sample count
* Average minutes to win
* Average minutes to loss
The rolling sample size can be adjusted in the settings.
---
## Breakeven Win Rate Requirement
This model uses a negative-risk-reward structure, meaning each win is smaller than each full loss.
The R Total calculation is based on:
* Win = **+0.14285R**
* Loss = **-1R**
Because each full loss is much larger than each win, the system needs a very high win rate to be profitable.
The approximate breakeven win rate is:
**87.5%**
That means the strategy must win more than **87.5%** of completed setups to show positive expectancy under this model.
* Below **87.5% win rate** = negative expectancy
* At **87.5% win rate** = around breakeven
* Above **87.5% win rate** = positive expectancy
This is why the rolling win-rate tracker is important. It helps traders quickly see whether the most recent sample is performing above or below the required profitability threshold.
Even though the Martingale flip model can create a high win rate, the full loss is much larger than the average win. Because of that, risk management is extremely important.
---
## R-Multiple Model
The R Total section helps estimate whether the recent rolling sample is profitable based on the script’s fixed reward-to-risk model.
Instead of only showing win rate, the script also calculates the overall R performance across the selected sample.
This helps traders avoid focusing only on a high win rate and instead evaluate whether the system is actually profitable after accounting for the larger full-loss event.
---
## Customizable Settings
You can adjust:
* Session start hour
* Session start minute
* Session end hour
* Session end minute
* Rolling trade sample size
* Show or hide the stats section
* Table position:
* Top Right
* Middle Right
* Bottom Right
---
## Best Use Case
This indicator is best used as a visual research tool for traders studying:
* Morning range breakouts
* Range expansion behavior
* Flip-based entry models
* Martingale-style recovery logic
* High-win-rate breakout systems
* Negative-risk-reward models
* Breakeven win-rate requirements
* Time-to-outcome behavior
* Rolling sample performance
---
## Important Risk Notice
This is an indicator only. It does not place trades automatically and should not be considered financial advice.
Martingale-style systems can increase risk quickly because each failed flip requires a larger position size. While the model may recover losses when the breakout eventually succeeds, the downside can become large when multiple flips fail.
A system like this does not only need to win often — it needs to win enough to overcome the size of its losses. Under this model, that means maintaining a win rate above approximately **87.5%**.
Always test thoroughly, use proper risk management, and understand the full risk before applying any strategy live.
**Martingale Range Breakout** is a session-based breakout and flip-tracking indicator designed to study range expansion behavior after a defined range.
This script builds a custom time-based range, tracks breakout direction, monitors flip attempts, and displays live trade-state data with rolling performance stats directly on the chart.
---
## Core Concept
The indicator creates a range from a selected session window.
By default, the range is built from:
**8:00 AM – 8:50 AM New York Time**
Once the range locks, the script watches for price to break above or below the range.
* Break above the range = **Long Active**
* Break below the range = **Short Active**
* If price reverses and breaks the opposite side, the script counts that as a **flip**
* If price reaches the full range extension before 4 flips, it marks the setup as a **WIN**
* If the setup reaches 4 flips, it marks the setup as a **LOSS**
---
## Martingale Flip Logic
This indicator is based on a Martingale-style flip model.
The idea is that when a breakout fails and price flips to the opposite side of the range, the next position size is increased to help recover the previous failed attempt.
Example position sequence:
* Flip 1: **1 contract**
* Flip 2: **2 contracts**
* Flip 3: **4 contracts**
* Flip 4: **Loss**
Each flip represents the market failing in one direction and then triggering the opposite side of the range.
The goal of the Martingale model is for the final successful breakout to recover the previous failed flips and still finish the sequence in profit.
The table tracks the current trade state and flip count, allowing traders to see what stage of the Martingale sequence the setup is currently in.
---
## Visual Range Boxes
The script draws two clean visual zones on the chart.
**Yellow Box**
Shows the original session range.
**Green Box**
Shows the full expansion zone based on the range size.
The final target levels are calculated as:
* Buy final target = **Range High + Full Range Distance**
* Sell final target = **Range Low - Full Range Distance**
This makes it easy to see both the breakout levels and the final expansion targets.
---
## Live Trade State Tracking
The table displays the current setup condition in real time.
Possible states include:
* **WAITING**
* **LONG ACTIVE**
* **SHORT ACTIVE**
* **WIN**
* **LOSS**
The table also shows the current flip count, helping traders quickly identify how many times the setup has reversed.
---
## Built-In Rolling Statistics
The indicator tracks the last selected number of completed setups and displays performance data inside the chart table.
Stats include:
* Last N trade count
* Wins and losses
* Rolling win rate
* Rolling R total
* Average winning range size
* Average losing range size
* Current range size
* Win sample count
* Loss sample count
* Average minutes to win
* Average minutes to loss
The rolling sample size can be adjusted in the settings.
---
## Breakeven Win Rate Requirement
This model uses a negative-risk-reward structure, meaning each win is smaller than each full loss.
The R Total calculation is based on:
* Win = **+0.14285R**
* Loss = **-1R**
Because each full loss is much larger than each win, the system needs a very high win rate to be profitable.
The approximate breakeven win rate is:
**87.5%**
That means the strategy must win more than **87.5%** of completed setups to show positive expectancy under this model.
* Below **87.5% win rate** = negative expectancy
* At **87.5% win rate** = around breakeven
* Above **87.5% win rate** = positive expectancy
This is why the rolling win-rate tracker is important. It helps traders quickly see whether the most recent sample is performing above or below the required profitability threshold.
Even though the Martingale flip model can create a high win rate, the full loss is much larger than the average win. Because of that, risk management is extremely important.
---
## R-Multiple Model
The R Total section helps estimate whether the recent rolling sample is profitable based on the script’s fixed reward-to-risk model.
Instead of only showing win rate, the script also calculates the overall R performance across the selected sample.
This helps traders avoid focusing only on a high win rate and instead evaluate whether the system is actually profitable after accounting for the larger full-loss event.
---
## Customizable Settings
You can adjust:
* Session start hour
* Session start minute
* Session end hour
* Session end minute
* Rolling trade sample size
* Show or hide the stats section
* Table position:
* Top Right
* Middle Right
* Bottom Right
---
## Best Use Case
This indicator is best used as a visual research tool for traders studying:
* Morning range breakouts
* Range expansion behavior
* Flip-based entry models
* Martingale-style recovery logic
* High-win-rate breakout systems
* Negative-risk-reward models
* Breakeven win-rate requirements
* Time-to-outcome behavior
* Rolling sample performance
---
## Important Risk Notice
This is an indicator only. It does not place trades automatically and should not be considered financial advice.
Martingale-style systems can increase risk quickly because each failed flip requires a larger position size. While the model may recover losses when the breakout eventually succeeds, the downside can become large when multiple flips fail.
A system like this does not only need to win often — it needs to win enough to overcome the size of its losses. Under this model, that means maintaining a win rate above approximately **87.5%**.
Always test thoroughly, use proper risk management, and understand the full risk before applying any strategy live.
Release Note
focus on the closeสคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน