//@version=5 strategy("MOEX Momentum Breakout Strategy", overlay=true,…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
//@version=5 strategy("MOEX Momentum Breakout Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Параметры стратегии lookback = input.int(20, "Период для определения уровней", minval=5, maxval=50) momentum_period = input.int(10, "Период импульса", minval=3, maxval=20) volume_threshold = input.float(1.8, "Множитель объема для подтверждения", minval=1.2, maxval=3.0) breakout_threshold = input.float(0.5, "Процент пробоя (%)", minval=0.1, maxval=2.0) / 100 consolidation_threshold = input.float(1.0, "Максимальный диапазон консолидации (%)", minval=0.5, maxval=5.0) / 100 profit_target = input.float(2.0, "Множитель для тейк-профита", minval=1.0, maxval=5.0) stop_loss = input.float(1.0, "Множитель для стоп-лосса", minval=0.5, maxval=2.0) use_atr_for_sl_tp = input.bool(true, "Использовать ATR для стопов и целей") atr_period = input.int(14, "Период ATR", minval=5, maxval=30) atr_multiplier = input.float(2.0, "Множитель ATR", minval=0.5, maxval=5.0) require_consolidation = input.bool(true, "Требовать консолидацию перед пробоем") min_consolidation_bars = input.int(5, "Минимальное количество баров консолидации", minval=3, maxval=20)
// Расчет индикаторов atr_value = ta.atr(atr_period) highest_high = ta.highest(high, lookback) lowest_low = ta.lowest(low, lookback) prev_highest_high = ta.highest(high[1], lookback) prev_lowest_low = ta.lowest(low[1], lookback)
// Расчет импульса momentum = close - close[momentum_period] momentum_percentage = momentum / close[momentum_period] positive_momentum = momentum_percentage > 0 negative_momentum = momentum_percentage < 0
// Объемный анализ vol_ma = ta.sma(volume, 20) high_volume = volume > vol_ma * volume_threshold
// Определение консолидации is_consolidating = false consolidation_range = 0.0 consolidation_bars = 0
if require_consolidation // Проверяем последние n баров на консолидацию recent_high = ta.highest(high, min_consolidation_bars) recent_low = ta.lowest(low, min_consolidation_bars) consolidation_range = (recent_high - recent_low) / recent_low is_consolidating = consolidation_range <= consolidation_threshold
// Подсчитываем количество баров в консолидации
for i = 0 to 50
bar_range = (high[i] - low[i]) / low[i]
if bar_range <= consolidation_threshold
consolidation_bars := consolidation_bars + 1
else
break
is_consolidating := is_consolidating and consolidation_bars >= min_consolidation_bars
else is_consolidating := true
// Определение пробоя уровней breakout_up = high > prev_highest_high * (1 + breakout_threshold) and positive_momentum breakout_down = low < prev_lowest_low * (1 - breakout_threshold) and negative_momentum
// Сигналы для входа long_signal = breakout_up and high_volume and is_consolidating short_signal = breakout_down and high_volume and is_consolidating
// Расчет стоп-лосса и тейк-профита var float long_entry_price = na var float short_entry_price = na var float long_stop = na var float long_target = na var float short_stop = na var float short_target = na
if long_signal and strategy.position_size == 0 long_entry_price := close if use_atr_for_sl_tp long_stop := close - atr_value * stop_loss long_target := close + atr_value * profit_target else long_stop := close * (1 - stop_loss / 100) long_target := close * (1 + profit_target / 100)
if short_signal and strategy.position_size == 0 short_entry_price := close if use_atr_for_sl_tp short_stop := close + atr_value * stop_loss short_target := close - atr_value * profit_target else short_stop := close * (1 + stop_loss / 100) short_target := close * (1 - profit_target / 100)
// Торговые сигналы if long_signal strategy.entry("Long", strategy.long) strategy.exit("Long Exit", "Long", stop=long_stop, limit=long_target)
if short_signal strategy.entry("Short", strategy.short) strategy.exit("Short Exit", "Short", stop=short_stop, limit=short_target)
// Визуализация // Отрисовка уровней var line resistance_line = na var line support_line = na
if ta.change(highest_high) line.delete(resistance_line) resistance_line := line.new(bar_index - lookback, highest_high, bar_index, highest_high, color=color.red, width=2)
if ta.change(lowest_low) line.delete(support_line) support_line := line.new(bar_index - lookback, lowest_low, bar_index, lowest_low, color=color.green, width=2)
// Отрисовка зоны консолидации bgcolor(is_consolidating ? color.new(color.blue, 90) : na)
// Отметки сигналов plotshape(long_signal, title="Long Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small) plotshape(short_signal, title="Short Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
// Отображение стопов и целей для открытых позиций if strategy.position_size > 0 line.new(bar_index, long_stop, bar_index + 1, long_stop, color=color.red, width=2, style=line.style_dashed) line.new(bar_index, long_target, bar_index + 1, long_target, color=color.green, width=2, style=line.style_dashed) if strategy.position_size < 0 line.new(bar_index, short_stop, bar_index + 1, short_stop, color=color.red, width=2, style=line.style_dashed) line.new(bar_index, short_target, bar_index + 1, short_target, color=color.green, width=2, style=line.style_dashed)
// Добавление информации на график var table info = table.new(position.top_right, 5, 5, color.black, color.white, 2, color.gray, 2) table.cell(info, 0, 0, "MOEX Momentum Breakout", text_color=color.white, bgcolor=color.blue) table.cell(info, 0, 1, "Консолидация: " + (is_consolidating ? "Да" : "Нет"), text_color=is_consolidating ? color.green : color.red) table.cell(info, 0, 2, "Баров в консолидации: " + str.tostring(consolidation_bars), text_color=color.white) table.cell(info, 0, 3, "Объем: " + (high_volume ? "Высокий" : "Нормальный"), text_color=high_volume ? color.green : color.gray) table.cell(info, 0, 4, "Импульс: " + str.tostring(math.round(momentum_percentage * 100, 2)) + "%", text_color=positive_momentum ? color.green : color.red)
' recent_high = ta.highestOkay, let's break down this TradingView Pine Script code for the "MOEX Momentum Breakout Strategy".
Strategy Overview:
This strategy is designed to identify and trade breakouts from periods of price consolidation, specifically targeting instruments on the MOEX (Moscow Exchange), although it can be applied to any market. It looks for price to break above a recent high or below a recent low, confirming the breakout with momentum and increased trading volume. It includes options for defining consolidation, setting profit targets and stop losses (either percentage-based or ATR-based), and visualizing the key elements on the chart.
Core Logic:
lookback period to establish