//@version=5 strategy("Triple Pattern with Round Level Entry", overlay=true) // Inputs…
- User
//@version=5 strategy("Triple Pattern with Round Level Entry", overlay=true)
// Inputs min_move_pips = input.int(100, "Minimum Move (Pips)") target_extension_min = input.int(150, "Target Extension Min (Pips)") target_extension_max = input.int(200, "Target Extension Max (Pips)") stop_loss_pips = input.int(50, "Stop Loss (Pips)") take_profit_pips = input.int(150, "Take Profit (Pips)") recovery_threshold = input.float(0.8, "Recovery Threshold") short_sl_pips = input.int(30, "Short Stop Loss (Pips)") short_tp_pips = input.int(40, "Short Take Profit (Pips)")
// Pip conversion pip_value = syminfo.mintick * (syminfo.type == "forex" ? 10 : 1)
// Variables var sunday_open = 0.0 var weekly_high = 0.0 var weekly_low = 0.0 var drop_low = 0.0 var phase1_complete = false var phase2_complete = false var phase3_complete = false var phase4_complete = false var next_round_level = 0.0 var round_level_crossed = false
// Reset on new week is_new_week = ta.change(time("1W")) != 0 if is_new_week sunday_open := open weekly_high := high weekly_low := low drop_low := 0.0 phase1_complete := false phase2_complete := false phase3_complete := false phase4_complete := false next_round_level := 0.0 round_level_crossed := false
// Update weekly levels if not is_new_week weekly_high := math.max(weekly_high, high) weekly_low := math.min(weekly_low, low)
current_day = dayofweek(time)
// Phase detection if not phase1_complete and current_day >= 1 and current_day <= 3 and sunday_open > 0 move_from_sunday = (high - sunday_open) / pip_value if move_from_sunday >= min_move_pips phase1_complete := true
if phase1_complete and not phase2_complete and sunday_open > 0 extension_from_sunday = (high - sunday_open) / pip_value if extension_from_sunday >= target_extension_min and extension_from_sunday <= target_extension_max phase2_complete := true
if phase2_complete and not phase3_complete and weekly_high > 0 reversal_from_high = (weekly_high - low) / pip_value if reversal_from_high >= min_move_pips phase3_complete := true drop_low := low
if phase3_complete and not phase4_complete and weekly_high > 0 and drop_low > 0 total_drop_distance = weekly_high - drop_low current_recovery = high - drop_low recovery_percentage = current_recovery / total_drop_distance recovery_pips = (high - drop_low) / pip_value if recovery_percentage >= recovery_threshold and recovery_pips >= min_move_pips phase4_complete := true
// Calculate next round 100-pip level after pattern completion if phase4_complete and next_round_level == 0.0 current_price = close // Find next round 100-pip level (0.0100 increments for forex) current_major = math.floor(current_price * 100) / 100 next_round_level := current_major + 0.0100
// Check if round level has been crossed if phase4_complete and next_round_level > 0.0 and not round_level_crossed if high >= next_round_level round_level_crossed := true
// Entry condition - SHORT at 0.015 level after round level cross short_condition = false entry_price_target = 0.0
if phase4_complete and round_level_crossed and next_round_level > 0.0 entry_price_target := next_round_level + (15 * pip_value) // Trigger short when price reaches the 15 pip level above round number if high >= entry_price_target and strategy.position_size == 0 short_condition := true
// Execute SHORT trades if short_condition sl_price = entry_price_target + (short_sl_pips * pip_value) tp_price = entry_price_target - (short_tp_pips * pip_value)
strategy.entry("Short", strategy.short, stop=entry_price_target) strategy.exit("Exit Short", "Short", stop=sl_price, limit=tp_price)// Visual markers bgcolor(phase1_complete ? color.new(color.yellow, 90) : na, title="Phase 1") bgcolor(phase2_complete ? color.new(color.orange, 90) : na, title="Phase 2") bgcolor(phase3_complete ? color.new(color.blue, 90) : na, title="Phase 3") bgcolor(phase4_complete ? color.new(color.lime, 90) : na, title="Phase 4")
// Plot round levels and entry points plot(phase4_complete and next_round_level > 0.0 ? next_round_level : na, "Round Level", color.purple, 2) plot(phase4_complete and entry_price_target > 0.0 ? entry_price_target : na, "Entry Target", color.red, 2, plot.style_circles)
// Entry signals plotshape(short_condition, "Short Entry", shape.triangledown, location.abovebar, color.red, size=size.normal) plotshape(round_level_crossed and phase4_complete, "Round Level Crossed", shape.diamond, location.belowbar, color.purple, size=size.small)
// Labels for debugging if phase4_complete and next_round_level > 0.0 label.new(bar_index, high, "Round: " + str.tostring(next_round_level) + "\nEntry: " + str.tostring(entry_price_target), color=color.white, textcolor=color.black, style=label.style_label_down, size=size.small)
- Assistant
Your Pine Script strategy looks well-structured and implements a multi-phase pattern detection with a round-level entry for a short position. Here are some comments, suggestions, and potential improvements to help you refine or troubleshoot the script:
General Overview
- Phases: You detect four phases based on price moves relative to the Sunday open and weekly highs/lows.
- Round Level Entry: After phase 4 completes, you calculate the next 100-pip round level and wait for price to cross it.
- Short Entry: You enter a short position 15 pips above the round level once crossed.
- Stops and Targets: You set stop loss and take profit levels relative to the entry price.
Suggestions & Improvements
1. Pip Value Calculation
pip_value = syminfo.mintick * (syminfo.type == "forex" ? 10 : 1)- This assumes 1 pip = 10 * mintick for Forex, which is common for 5-digit brokers (e.g., EURUSD 1.12345).
- For 4-digit brokers or other instruments, this might be off.
- Consider adding an input to adjust pip multiplier or detect it dynamically.
2. Weekly Reset Logic
is_new_week = ta.change(time("1W")) != 0 if is_new_week sunday_open := open weekly_high := high weekly_low := low ...sunday_open := opensets the open of the first bar of the week.- Make sure your chart timeframe includes Sunday bars (e.g., 1H or higher). If your chart starts on Monday, this might not capture Sunday open correctly.
- You might want to use
request.security()to get the exact Sunday open from a higher timeframe.
3. Phase Detection Logic
- You use
current_day >= 1 and current_day <= 3for phase 1 (Mon-Wed). - Make sure your exchange timezone aligns with your expectations for dayofweek.
- You might want to add debug prints or labels to verify phase transitions.
4. Round Level Calculation
current_major = math.floor(current_price * 100) / 100 next_round_level := current_major + 0.0100- This assumes 100 pips = 0.0100 in price.
- This is correct for pairs like EURUSD, but for others (e.g., USDJPY), 100 pips = 1.00.
- Consider making this dynamic based on symbol or user input.
Example:
pip_in_price = pip_value round_pip_count = 100 round_level_increment = round_pip_count * pip_in_price current_major = math.floor(current_price / round_level_increment) * round_level_increment next_round_level := current_major + round_level_increment5. Entry Condition
- You enter short when price reaches
next_round_level + 15 pips. - You use a stop order at that price:
strategy.entry("Short", strategy.short, stop=entry_price_target)- This means the order triggers when price moves up to that level.
- Since you are shorting, this is a short entry on a price increase to a resistance level, which makes sense.
- Confirm that this matches your intended logic.
6. Stop Loss and Take Profit
- You set stop loss above entry and take profit below entry for shorts, which is correct.
- You use
strategy.exit()withstopandlimitparameters, which is good.
7. Visuals and Debugging
- You use
bgcolor()to highlight phases, which is helpful. - You plot round levels and entry targets.
- You add labels for debugging, which is great.
Minor Code Cleanup
- You can combine some conditions or add comments for clarity.
- Use consistent naming conventions.
- Add comments explaining each phase and calculation.
Example: Dynamic Round Level Calculation
round_pips = 100 round_level_increment = round_pips * pip_value current_major = math.floor(current_price / round_level_increment) * round_level_increment next_round_level := current_major + round_level_incrementThis will work for any symbol as long as
pip_valueis correct.
Final Notes
- Test your strategy on different symbols and timeframes.
- Use
strategy.performanceandstrategy.closedtradesto analyze results. - Add alerts or print statements to debug phase transitions and entries.
If you want, I can help you refactor or extend this script further! Just ask.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.