1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
293 lines of Pine Script v6 from breakout-strategytest.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
breakout-strategytest.pine
//@version=6
strategy("Ede – MA + Breakout Strategie (Dynamic MAs)", overlay=true, max_lines_count=500, max_labels_count=500,
pyramiding=10, default_qty_type=strategy.percent_of_equity, default_qty_value=10,
commission_type=strategy.commission.percent, commission_value=0.1)
// === Input Options MA & HL ===
msr = input.bool(false, "Ma10 (MSR)")
milo = input.bool(false, "Ma50 and Ichimoku (MILO)")
m3 = input.bool(true, "Ma50, Ma100, Ma200 (3M)")
w52 = input.bool(false, "Line 52 Week High|Low")
ShowHL = input.bool(false, "Line High|Low")
// === Input Options Breakout ===
volMultiplier = input.float(1.5, title="Volumen-Multiplikator für Breakout", minval=0.5)
gap_required = input.bool(false, title="Gap erforderlich für Breakout?")
strongCandle_required = input.bool(false, title="Starke Kerze erforderlich für Breakout?")
breakout_candle_mode = input.int(2, title="Breakout-Candle Modus (1=Streng, 2=Locker)", options=[1,2])
use_stoploss = input.bool(true, title="Stop-Loss verwenden?")
stoploss_perc = input.float(3.0, title="Stop-Loss %", minval=0.1)
use_takeprofit = input.bool(true, title="Take-Profit verwenden?")
takeprofit_perc = input.float(6.0, title="Take-Profit %", minval=0.1)
// === Erweiterte Risk Management Optionen ===
use_trailing_stop = input.bool(true, title="Trailing-Stop verwenden?")
trailing_stop_perc = input.float(2.0, title="Trailing-Stop % Abstand", minval=0.1)
use_atr_stop = input.bool(false, title="ATR-basierten Stop verwenden?")
atr_multiplier = input.float(2.0, title="ATR Multiplikator für Stop", minval=0.5)
atr_length = input.int(14, title="ATR Periodenlänge", minval=1)
use_partial_exit = input.bool(false, title="Teilausstieg verwenden?")
partial_exit_perc = input.float(3.0, title="Teilausstieg bei % Gewinn", minval=0.1)
partial_exit_size = input.float(50.0, title="Teilausstieg Größe (%)", options=[25.0, 33.0, 50.0, 66.0, 75.0])
max_daily_loss = input.float(0.0, title="Maximaler täglicher Verlust %", tooltip="0 = deaktiviert", minval=0.0)
position_size_risk = input.float(1.0, title="Risiko pro Trade %", minval=0.1, maxval=10.0)
// Pyramiding Einstellungen
enable_pyramiding = input.bool(false, title="Pyramiding aktivieren?")
pyramiding_levels = input.int(3, title="Maximale Anzahl Pyramiding Levels", minval=1, maxval=10)
min_price_increase = input.float(1.0, title="Mindestpreisanstieg für Pyramiding (%)", minval=0.1)
// === Neue Input Options MA-Exit ===
exit_on_ma10 = input.bool(true, title="Exit bei Unterschreiten MA10 aktivieren")
exit_on_ma50 = input.bool(false, title="Exit bei Unterschreiten MA50 aktivieren")
// === Calculate Moving Averages ===
sma10 = ta.sma(close, 10)
sma50 = ta.sma(close, 50)
sma100 = ta.sma(close, 100)
sma150 = ta.sma(close, 150)
sma200 = ta.sma(close, 200)
// === Precompute MA Crossunder Signals ===
ma10CrossUnder = ta.crossunder(close, sma10)
ma50CrossUnder = ta.crossunder(close, sma50)
// === ATR Calculation ===
atr_value = ta.atr(atr_length)
// === Plot MAs ===
plot(msr ? sma10 : na, title="MA10", color=color.blue, linewidth=2)
plot(milo or m3 ? sma50 : na, title="MA50", color=color.orange, linewidth=2)
plot(m3 ? sma100 : na, title="MA100", color=color.green, linewidth=2)
plot(m3 ? sma200 : na, title="MA200", color=color.red, linewidth=2)
// === MSR Bar Highlight ===
msrbar = open < close and sma10 >= open and sma10 <= close and msr
barcolor(msrbar ? color.blue : na, show_last=3)
// === Ichimoku (MILO) ===
conversionPeriods = 9
basePeriods = 26
laggingSpan2Periods = 52
displacement = 26
donchian(len) => (ta.lowest(len) + ta.highest(len)) / 2
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = (conversionLine + baseLine) / 2
leadLine2 = donchian(laggingSpan2Periods)
p1 = plot(milo ? leadLine1 : na, offset=displacement, color=color.new(color.green, 0))
p2 = plot(milo ? leadLine2 : na, offset=displacement, color=color.new(color.red, 0))
fill(p1, p2, color = leadLine1 > leadLine2 ? color.new(color.green, 85) : color.new(color.red, 85))
// === 52-Week High/Low ===
weekly_hh = request.security(syminfo.tickerid, "W", ta.highest(high, 52), lookahead=barmerge.lookahead_on)
weekly_ll = request.security(syminfo.tickerid, "W", ta.lowest(low, 52), lookahead=barmerge.lookahead_on)
plot(w52 ? weekly_hh : na, title="52W High", trackprice=true, color=color.green)
plot(w52 ? weekly_ll : na, title="52W Low", trackprice=true, color=color.red)
// Dynamisches Management der 52W-Labels
var label highLabel = na
var label lowLabel = na
if w52 and bar_index % 10 == 0
if not na(highLabel)
label.delete(highLabel)
if not na(lowLabel)
label.delete(lowLabel)
highLabel := label.new(bar_index, weekly_hh, "52W High\n" + str.tostring(weekly_hh, format.mintick), style=label.style_label_down, color=color.green, textcolor=color.white, size=size.small)
lowLabel := label.new(bar_index, weekly_ll, "52W Low\n" + str.tostring(weekly_ll, format.mintick), style=label.style_label_up, color=color.red, textcolor=color.white, size=size.small)
// === High & Low (Recent) ===
window1 = 8
window2 = 21
top1 = ta.valuewhen(high >= ta.highest(high, window1), high, 0)
bot1 = ta.valuewhen(low <= ta.lowest(low, window1), low, 0)
top2 = ta.valuewhen(high >= ta.highest(high, window2), high, 0)
bot2 = ta.valuewhen(low <= ta.lowest(low, window2), low, 0)
plot(ShowHL ? top1 : na, color=color.red)
plot(ShowHL ? bot1 : na, color=color.green)
plot(ShowHL ? top2 : na, color=color.red)
plot(ShowHL ? bot2 : na, color=color.green)
// === Breakout Logik ===
avgVol = ta.sma(volume, 20)
volBreak = (volume > avgVol * volMultiplier)
gap = open > high[1]
body = math.abs(close - open)
candleSize = high - low
strongCandle = (close > open) and (body > candleSize * 0.5)
var bool candleOK = false
if breakout_candle_mode == 1
candleOK := strongCandle
else
candleOK := (close > open)
maTrend = sma50 > sma50[1]
isBreakout = volBreak and (close > sma50) and maTrend and candleOK
if gap_required
isBreakout := isBreakout and gap
if strongCandle_required
isBreakout := isBreakout and strongCandle
// === Entry / Exit ===
var bool inPosition = false
var float entryPrice = na
var float highestEntryPrice = na
var float stopPrice = na
var float targetPrice = na
var float trailingStopPrice = na
var float atrStopPrice = na
var bool partial_exit_taken = false
var float position_size = 1.0
var float daily_loss = 0.0
var int last_trade_day = 0
var int pyramid_count = 0
// Labels für Breakout und Exit
var label breakoutLabel = na
var label exitLabel = na
var label partialExitLabel = na
// Tageswechsel prüfen und Daily Loss zurücksetzen
if (dayofmonth != last_trade_day and last_trade_day != 0)
daily_loss := 0.0
last_trade_day := dayofmonth
else if (last_trade_day == 0)
last_trade_day := dayofmonth
// Position Sizing basierend auf Risk
calculate_position_size() =>
risk_amount = position_size_risk / 100
stop_distance = 0.0
if use_atr_stop
stop_distance := atr_value * atr_multiplier / close
else
stop_distance := stoploss_perc / 100
max_position = risk_amount / stop_distance
math.min(max_position, 1.0)
// Pyramiding Bedingung
pyramiding_condition = enable_pyramiding and
inPosition and
pyramid_count < pyramiding_levels and
close > highestEntryPrice * (1 + min_price_increase/100)
// Entry Logik
if (isBreakout and not inPosition and (max_daily_loss == 0.0 or daily_loss < max_daily_loss)) or pyramiding_condition
if not inPosition
inPosition := true
partial_exit_taken := false
pyramid_count := 1
else
pyramid_count := pyramid_count + 1
entryPrice := close
highestEntryPrice := math.max(highestEntryPrice, entryPrice)
position_size := calculate_position_size() / (enable_pyramiding ? pyramiding_levels : 1)
// Strategie Entry
strategy.entry("Breakout", strategy.long, qty=position_size * 100, comment="Breakout" + (pyramid_count > 1 ? " Pyramid " + str.tostring(pyramid_count) : ""))
// Stop-Loss berechnen
if use_atr_stop
atrStopPrice := close * (1 - (atr_value * atr_multiplier / close))
stopPrice := atrStopPrice
else
stopPrice := use_stoploss ? close * (1 - stoploss_perc/100) : na
trailingStopPrice := stopPrice
targetPrice := use_takeprofit ? close * (1 + takeprofit_perc/100) : na
label.delete(breakoutLabel)
breakoutLabel := label.new(bar_index, low, "Breakout" + (pyramid_count > 1 ? " P" + str.tostring(pyramid_count) : "") + "\nSize: " + str.tostring(position_size, "#.##"),
style=label.style_label_up, color=color.rgb(76, 175, 79, 70),
textcolor=color.white, size=size.small)
if inPosition
// Update trailing stop if price moves in our favor
if use_trailing_stop and close > entryPrice and close > high[1]
new_trailing_stop = close * (1 - trailing_stop_perc/100)
if new_trailing_stop > trailingStopPrice
trailingStopPrice := new_trailing_stop
strategy.exit("Trailing", "Breakout", stop=trailingStopPrice, comment="Trailing Stop")
// Check for partial exit
if use_partial_exit and not partial_exit_taken and close >= entryPrice * (1 + partial_exit_perc/100)
partial_exit_taken := true
strategy.order("PartialExit", strategy.short, strategy.position_size * (partial_exit_size/100), comment="Partial Exit " + str.tostring(partial_exit_size) + "%")
label.delete(partialExitLabel)
partialExitLabel := label.new(bar_index, close, "Partial Exit " + str.tostring(partial_exit_size) + "%",
style=label.style_label_lower_right, color=color.rgb(255, 193, 7, 70),
textcolor=color.white, size=size.small)
stopHit = (use_stoploss and close <= stopPrice) or (use_trailing_stop and close <= trailingStopPrice)
targetHit = use_takeprofit and close >= targetPrice
// Neuer MA-Exit unter Verwendung vorab berechneter Werte
ma10Exit = exit_on_ma10 and ma10CrossUnder
ma50Exit = exit_on_ma50 and ma50CrossUnder
maExitHit = ma10Exit or ma50Exit
// Set stop loss
if use_stoploss
strategy.exit("SL", "Breakout", stop=stopPrice, comment="Stop Loss")
// Set take profit
if use_takeprofit
strategy.exit("TP", "Breakout", limit=targetPrice, comment="Take Profit")
if stopHit or targetHit or maExitHit
// Track daily loss if stop was hit
if stopHit
loss_amount = ((close - entryPrice) / entryPrice) * position_size
daily_loss := daily_loss - loss_amount
// Exit Position mit dem entsprechenden Signal
if maExitHit
strategy.close("Breakout", comment=ma10Exit ? "MA10 Exit" : "MA50 Exit")
inPosition := false
pyramid_count := 0
highestEntryPrice := na
label.delete(exitLabel)
exitType = stopHit ? "Stop Exit" : targetHit ? "Target Exit" : "MA Exit"
exitLabel := label.new(bar_index, close, exitType,
style=label.style_label_lower_left, color=color.rgb(255, 82, 82, 70),
textcolor=color.white, size=size.small)
entryPrice := na
stopPrice := na
targetPrice := na
trailingStopPrice := na
atrStopPrice := na
// === Hintergrundfarbe bei aktivem Trade ===
bgcolor(inPosition ? color.new(color.green, 90) : na)
// === Stop-Loss Linie ===
stopLine = inPosition ? (use_trailing_stop ? trailingStopPrice : stopPrice) : na
plot(stopLine, style=plot.style_cross, color=color.rgb(203, 255, 82, 30), linewidth=2, title="Stop-Loss")
// === Target Line ===
targetLine = inPosition and use_takeprofit ? targetPrice : na
plot(targetLine, style=plot.style_circles, color=color.rgb(0, 255, 255, 30), linewidth=2, title="Target")
// === Trailing Stop Line ===
trailingLine = inPosition and use_trailing_stop ? trailingStopPrice : na
plot(trailingLine, style=plot.style_line, color=color.rgb(255, 165, 0, 30), linewidth=2, title="Trailing Stop")
// Pyramiding Info anzeigen
if inPosition and enable_pyramiding and pyramid_count > 0
label.new(bar_index, low, "Pyramiding: " + str.tostring(pyramid_count) + "/" + str.tostring(pyramiding_levels),
style=label.style_label_up, color=color.rgb(255, 193, 7, 70), textcolor=color.white, size=size.tiny)
// === Trendwechsel-Labels ===
var bool wasAbove10 = close[1] > sma10
var bool wasAbove50 = close[1] > sma50
if close > sma10 and not wasAbove10
label.new(bar_index, high, "Über MA10", style=label.style_label_up, color=color.rgb(33, 149, 243, 60), textcolor=color.white, size=size.small)
if close > sma50 and not wasAbove50
label.new(bar_index, high, "Über MA50", style=label.style_label_up, color=color.rgb(0, 137, 123, 60), textcolor=color.white, size=size.small)
wasAbove10 := close > sma10
wasAbove50 := close > sma50
Overview
Ede – MA + Breakout Strategie (Dynamic MAs) generates entry signals on breakouts that exceed a volume multiplier, with optional requirements for gaps or strong candles in the breakout_candle_mode. Positions can be exited on MA crossunders, and the strategy supports stop-loss, take-profit, trailing stop, and partial exits. Risk management includes pyramiding and position sizing per equity. Settings primarily control which MAs appear and the conditions for valid breakouts. It repaints on the live bar and allows pyramiding.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Ma10 (MSR)
bool
false
msr
Ma50 and Ichimoku (MILO)
bool
false
milo
Ma50, Ma100, Ma200 (3M)
bool
true
m3
Line 52 Week High|Low
bool
false
w52
Line High|Low
bool
false
ShowHL
Volumen-Multiplikator für Breakout
float
1.5
volMultiplier
Gap erforderlich für Breakout?
bool
false
gap_required
Starke Kerze erforderlich für Breakout?
bool
false
strongCandle_required
Breakout-Candle Modus (1=Streng, 2=Locker)
int
2
breakout_candle_mode
Stop-Loss verwenden?
bool
true
use_stoploss
Stop-Loss %
float
3.0
stoploss_perc
Take-Profit verwenden?
bool
true
use_takeprofit
Show all 28 settings
Setting
Type
Default
Variable
Take-Profit %
float
6.0
takeprofit_perc
Trailing-Stop verwenden?
bool
true
use_trailing_stop
Trailing-Stop % Abstand
float
2.0
trailing_stop_perc
ATR-basierten Stop verwenden?
bool
false
use_atr_stop
ATR Multiplikator für Stop
float
2.0
atr_multiplier
ATR Periodenlänge
int
14
atr_length
Teilausstieg verwenden?
bool
false
use_partial_exit
Teilausstieg bei % Gewinn
float
3.0
partial_exit_perc
Teilausstieg Größe (%)
float
50.0
partial_exit_size
Maximaler täglicher Verlust %
float
0.0
max_daily_loss
Risiko pro Trade %
float
1.0
position_size_risk
Pyramiding aktivieren?
bool
false
enable_pyramiding
Maximale Anzahl Pyramiding Levels
int
3
pyramiding_levels
Mindestpreisanstieg für Pyramiding (%)
float
1.0
min_price_increase
Exit bei Unterschreiten MA10 aktivieren
bool
true
exit_on_ma10
Exit bei Unterschreiten MA50 aktivieren
bool
false
exit_on_ma50
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This strategy plots running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos
This price-chart strategy plots a simple moving average and upper and lower bands built from the standard deviation of close, scaled by separate offset inputs. It enters a fixed quantity long when close crosses above the upper band and a fixed quantity short w
This strategy executes trades based on crossovers between a 12-period and a 26-period exponential moving average (EMA). Long positions can be filtered by pivot resistance breakouts and RSI boundary ranges. For trade management, it provides two configurable par
This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the
This strategy plots exponential-moving-average Bollinger bands on the price chart and calculates RSI. It opens a long position when close crosses above the upper band while RSI is at or above a threshold, the date filter allows trading, and no position is open
This strategy trades SOL perpetual candles on the price chart. It tracks confirmed pivot highs and lows as support and resistance circles, then compares close with a smoothed filter and a three-period EMA to mark long and short conditions after the bar closes.