Okay, let's transform the "Money Maker Model" indicator into a TradingView strategy based on your specific conditions. This involves adapting the session logic, breakout detection, market structure (ChoCH), and adding SL/TP management.
Key Requirements Recap:
- Session: Asian Range Breakout during London Session.
- Breakout Confirmation: 3-minute
close must be outside the Asian range.
- Entry: First confirmed ChoCH signal opposite to the breakout direction.
- SL: Fractal swing high/low before the ChoCH confirmation.
- TP: User-defined input.
Assumptions:
- This strategy is intended to be run on a 3-minute timeframe. The code includes checks for this.
- The "fractal swing before the choch" will be interpreted as the highest high (for a long entry) or lowest low (for a short entry) within a specified number of bars preceding the ChoCH confirmation bar.
- The "first confirmed choch" means we only enter once per Asian breakout event.
//@version=5
strategy("Money Maker Strategy", "Money Maker Strategy", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.075) // Example commission
// ---------------------------------------- Inputs --------------------------------------------------
// Timezone and Session Inputs (repurposed from indicator)
gmt_tz = input.string('America/New_York', "Timezone", options = ['America/New_York','GMT-12','GMT-11','GMT-10','GMT-9','GMT-8','GMT-7','GMT-6','GMT-5','GMT-4','GMT-3','GMT-2','GMT-1','GMT+0','GMT+1','GMT+2','GMT+3','GMT+4','GMT+5','GMT+6','GMT+7','GMT+8','GMT+9','GMT+10','GMT+11','GMT+12','GMT+13','GMT+14'], group = "Sessions")
asia_session_input = input.session("2000-0000", "Asia Session", group = "Sessions")
london_session_input= input.session("0200-0500", "London Session", group = "Sessions")
// Breakout Confirmation
breakout_confirm_bars = input.int(1, "Breakout Confirm Bars (Close Outside)", minval = 1, group = "Breakout Rules")
// Market Structure (ChoCH) Inputs (simplified from indicator)
ms_length = input.int(5, minval = 3, title = "MS Fractal Lookback", group = "Market Structure")
// Stop Loss and Take Profit
sl_fractal_lookback = input.int(5, minval = 1, title = "SL Fractal Lookback (Bars Before ChoCH)", group = "Risk Management")
tp_percent = input.float(1.0, title = "Take Profit %", minval = 0.1, step = 0.1, group = "Risk Management") / 100.0 // Convert percentage to decimal
// ---------------------------------------- Helper Functions --------------------------------------------------
// Function to get session times for the current bar
getSessionTime(session_str, tz) =>
time(timeframe.period, session_str, tz) != na
// Function to check if a bar is within a specific session
isWithinSession(session_str, tz) =>
time(timeframe.period, session_str, tz)
// Function to check if the current TF is 3 minutes
is3MinTF() =>
timeframe.period == "3"
// ---------------------------------------- State Variables --------------------------------------------------
// Session State
var bool isAsiaActive = false
var bool isLondonActive = false
var bool isPostAsia = false // True after Asian session closes but before London potentially starts or breaks out
// Asian Range State
var float asiaHigh = na
var float asiaLow = na
var float asiaRangeHigh = na
var float asiaRangeLow = na
var bool asianRangeCaptured = false
var int asiaSessionEndBar = na
// Breakout State
var int breakoutDirection = 0 // 1 = Bullish, -1 = Bearish, 0 = None
var bool breakoutConfirmed = false
var int breakoutConfirmBarCount = 0 // Count consecutive bars closing outside
// Entry State
var bool entrySignal = false
var int entryDirection = 0 // 1 = Long, -1 = Short
var float chochBarIndex = na
var float chochValue = na
var float slLevel = na
var float tpLevel = na
// Market Structure State (simplified for strategy)
var bool msBullFractal = false
var bool msBearFractal = false
// ---------------------------------------- Timeframe Check --------------------------------------------------
if not is3MinTF()
runtime.error("This strategy is designed for the 3-minute timeframe. Please switch charts.")
// ---------------------------------------- Session & Range Logic --------------------------------------------------
// Determine current session status
isAsiaActive := getSessionTime(asia_session_input, gmt_tz)
isLondonActive := getSessionTime(london_session_input, gmt_tz)
// Capture Asian Session Range
var float currentAsiaHigh = na
var float currentAsiaLow = na
if isAsiaActive
currentAsiaHigh := math.max(high, nz(currentAsiaHigh, high))
currentAsiaLow := math.min(low, nz(currentAsiaLow, low))
isPostAsia := false // Reset if we are back in Asia (e.g., overnight)
// Capture the end of the Asian session and store the range
bool asiaSessionJustEnded = isAsiaActive[1] and not isAsiaActive
if asiaSessionJustEnded
asiaRangeHigh := currentAsiaHigh
asiaRangeLow := currentAsiaLow
asianRangeCaptured := true
asiaSessionEndBar := bar_index // Store the index of the last bar of Asia
// Reset for the next day's calculation
currentAsiaHigh := na
currentAsiaLow := na
breakoutDirection := 0 // Reset breakout direction for the new day/session
breakoutConfirmed := false
breakoutConfirmBarCount := 0
entrySignal := false
entryDirection := 0
chochBarIndex := na
chochValue := na
slLevel := na
tpLevel := na
msBullFractal := false // Reset MS flags
msBearFractal := false
// ---------------------------------------- Breakout Detection --------------------------------------------------
if asianRangeCaptured and isLondonActive and not entrySignal
// Check for Bullish Breakout
if high > asiaRangeHigh and breakoutDirection[1] == 0 // First touch of breakout level
breakoutDirection := 1
breakoutConfirmBarCount := 0 // Reset counter
// Check for Bearish Breakout
if low < asiaRangeLow and breakoutDirection[1] == 0 // First touch of breakout level
breakoutDirection := -1
breakoutConfirmBarCount := 0 // Reset counter
// Confirmation Logic
if breakoutDirection == 1 and close > asiaRangeHigh
breakoutConfirmBarCount += 1
else if breakoutDirection == -1 and close < asiaRangeLow
breakoutConfirmBarCount += 1
else // If price moves back inside the range before confirmation
if breakoutDirection != 0
breakoutConfirmBarCount := 0 // Reset count if bar closes inside
// Potentially reset breakoutDirection if price fails to stay outside
// For now, keep direction but reset count
// Set confirmed flag if count meets requirement
if breakoutConfirmBarCount >= breakout_confirm_bars
breakoutConfirmed := true
else
breakoutConfirmed := false // Ensure it's false if count isn't met
// ---------------------------------------- Market Structure (ChoCH) Logic --------------------------------------------------
// Calculate fractals based on the specified length
// Note: Using indicator's MS logic for fractals, simplified
int ms_p = math.floor(ms_length / 2)
msBullFractal := ta.pivothigh(high, ms_p, ms_p)
msBearFractal := ta.pivotlow(low, ms_p, ms_p)
// Define Target ChoCH based on breakout direction
bool targetChoCHBullish = msBullFractal and breakoutDirection == -1 // Bullish fractal after bearish breakout
bool targetChoCHBearish = msBearFractal and breakoutDirection == 1 // Bearish fractal after bullish breakout
// Detect the FIRST ChoCH signal after breakout confirmation
bool firstChoCHDetected = false
if breakoutConfirmed and not entrySignal
if targetChoCHBullish
firstChoCHDetected := true
entryDirection := 1 // Enter Long
chochBarIndex := bar_index - ms_p // Bar index of the fractal high
chochValue := high[ms_p]
else if targetChoCHBearish
firstChoCHDetected := true
entryDirection := -1 // Enter Short
chochBarIndex := bar_index - ms_p // Bar index of the fractal low
chochValue := low[ms_p]
// ---------------------------------------- Entry Signal Generation --------------------------------------------------
if firstChoCHDetected
entrySignal := true
// ---------------------------------------- Calculate SL and TP --------------------------------------------------
// Calculate SL based on fractal swing BEFORE the ChoCH
// We need to find the highest high (for long) or lowest low (for short)
// within 'sl_fractal_lookback' bars PRIOR to the chochBarIndex
float potentialSLLevel = na
float potentialTPLevel = na
if entrySignal and not na(chochBarIndex)
// Find the relevant fractal swing point
if entryDirection == 1 // Long Entry (ChoCH was bullish, need previous swing LOW)
// Look for the lowest low in the bars before the ChoCH fractal high
// Add 1 to lookback because fractal peak is at ms_p offset from current bar
potentialSLLevel := ta.lowest(low, sl_fractal_lookback) // Lookback from current bar index where signal is detected
// Ensure the SL is below the choch value itself if needed (can refine this)
// potentialSLLevel := math.min(potentialSLLevel, chochValue - (chochValue * 0.001)) // Example: Ensure SL is slightly below ChoCH if needed
else if entryDirection == -1 // Short Entry (ChoCH was bearish, need previous swing HIGH)
// Look for the highest high in the bars before the ChoCH fractal low
potentialSLLevel := ta.highest(high, sl_fractal_lookback)
// potentialSLLevel := math.max(potentialSLLevel, chochValue + (chochValue * 0.001)) // Example: Ensure SL is slightly above ChoCH if needed
// Set final SL and TP levels
slLevel := potentialSLLevel
// Calculate TP based on entry price (use the close of the entry bar)
float entryPrice = close
if entryDirection == 1 // Long
potentialTPLevel := entryPrice * (1 + tp_percent)
else if entryDirection == -1 // Short
potentialTPLevel := entryPrice * (1 - tp_percent)
tpLevel := potentialTPLevel
// ---------------------------------------- Strategy Execution --------------------------------------------------
// Entry Logic
if entrySignal and entryDirection == 1 // Long Entry Condition
strategy.entry("Long", strategy.long)
// Use strategy.exit immediately after entry to set SL and TP
strategy.exit("Exit Long", "Long", stop=slLevel, limit=tpLevel)
if entrySignal and entryDirection == -1 // Short Entry Condition
strategy.entry("Short", strategy.short)
// Use strategy.exit immediately after entry to set SL and TP
strategy.exit("Exit Short", "Short", stop=slLevel, limit=tpLevel)
// ---------------------------------------- Plotting for Visualization (Optional) --------------------------------------------------
// Plot Asian Range
var box asiaBox = na
if asianRangeCaptured and na(asiaBox)
asiaBox := box.new(asiaSessionEndBar + 1, asiaRangeHigh, bar_index, asiaRangeLow,
border_color = color.blue, bgcolor = color.new(color.blue, 85), xloc = xloc.bar_index, extend = extend.right)
else if asianRangeCaptured and not na(asiaBox)
// Extend the box if needed, or redraw if session end changes
if bar_index > asiaBox.get_right() // If current bar is past the box's end
if not entrySignal // Only redraw if no trade has been taken yet
asiaBox.delete()
asiaBox := box.new(asiaSessionEndBar + 1, asiaRangeHigh, bar_index, asiaRangeLow,
border_color = color.blue, bgcolor = color.new(color.blue, 85), xloc = xloc.bar_index, extend = extend.right)
// Plot Breakout Direction Arrow
plotshape(breakoutDirection == 1 and breakoutConfirmed ? high + syminfo.mintick * 5 : na, style=shape.triangleup, location=location.abovebar, color=color.green, size=size.small, tooltip="Bullish Breakout")
plotshape(breakoutDirection == -1 and breakoutConfirmed ? low - syminfo.mintick * 5 : na, style=shape.triangledown, location=location.belowbar, color=color.red, size=size.small, tooltip="Bearish Breakout")
// Plot ChoCH Signal (Green Up Arrow for Long Entry, Red Down Arrow for Short Entry)
plotshape(entrySignal and entryDirection == 1 ? chochValue : na, style=shape.triangleup, location=location.absolute, color=color.green, size=size.small, tooltip="Long Entry Signal (ChoCH)")
plotshape(entrySignal and entryDirection == -1 ? chochValue : na, style=shape.triangledown, location=location.absolute, color=color.red, size=size.small, tooltip="Short Entry Signal (ChoCH)")
// Plot SL and TP levels when entry signal is active
plot(entrySignal and entryDirection == 1 ? slLevel : na, title="Long SL", color=color.red, style=plot.style_linebr, linewidth=1)
plot(entrySignal and entryDirection == 1 ? tpLevel : na, title="Long TP", color=color.green, style=plot.style_linebr, linewidth=1)
plot(entrySignal and entryDirection == -1 ? slLevel : na, title="Short SL", color=color.red, style=plot.style_linebr, linewidth=1)
plot(entrySignal and entryDirection == -1 ? tpLevel : na, title="Short TP", color=color.green, style=plot.style_linebr, linewidth=1)
// Alert for Entry Signal
alertcondition(entrySignal and entryDirection == 1, title="MM Strategy Long Entry", message="Money Maker Strategy: Bullish Breakout Confirmed, Long Entry triggered by ChoCH.")
alertcondition(entrySignal and entryDirection == -1, title="MM Strategy Short Entry", message="Money Maker Strategy: Bearish Breakout Confirmed, Short Entry triggered by ChoCH.")
Explanation and How to Use:
- Strategy Conversion: Changed
indicator to strategy. Added strategy-specific parameters like pyramiding=0 (only one trade at a time) and commission settings.
- Inputs:
- Reused
gmt_tz, asia_session_input, london_session_input.
- Added
breakout_confirm_bars (default 1, meaning the 3-min close must be outside).
- Simplified MS inputs to just
ms_length for fractal calculation.
- Added
sl_fractal_lookback for determining the swing point for the SL.
- Added
tp_percent for take profit target.
- Timeframe Check: The script will throw an error if not applied to a 3-minute chart.
- State Management: Several
var variables are introduced to keep track of the state (e.g., asianRangeCaptured, breakoutDirection, entrySignal). This is crucial for strategies.
- Session & Range Logic:
- It detects when the Asian session is active and captures the highest high (
currentAsiaHigh) and lowest low (currentAsiaLow) during that time.
- When the Asian session ends (
asiaSessionJustEnded), it stores the final range (asiaRangeHigh, asiaRangeLow) and the bar index where it ended (asiaSessionEndBar). State variables are reset for the next day.
- Breakout Detection:
- Once the Asian range is captured and the London session is active, it monitors for price breaking above
asiaRangeHigh or below asiaRangeLow.
breakoutDirection is set (1 for up, -1 for down).
breakoutConfirmBarCount tracks consecutive bars closing outside the range.
breakoutConfirmed becomes true when the count reaches breakout_confirm_bars.
- Market Structure (ChoCH):
- It uses a simplified version of the fractal calculation (
ta.pivothigh, ta.pivotlow) based on ms_length.
- It checks if a fractal occurs that is opposite to the
breakoutDirection. For example, if the breakout was bullish (breakoutDirection == 1), it looks for a bearish fractal ().
How to Use:
- Apply to Chart: Load this script onto a TradingView chart.
- Set Timeframe: Ensure the chart timeframe is set to 3 minutes.
- Configure Inputs:
- Set your correct
Timezone.
- Adjust
Asia Session and London Session times if needed.
- Set
Breakout Confirm Bars (usually 1 is sufficient for a clean breakout).
- Adjust
MS Fractal Lookback for ChoCH detection sensitivity.
- Crucially, set
SL Fractal Lookback (how many bars back to find the swing for SL) and Take Profit %.
- Backtest: Use the Strategy Tester in TradingView to evaluate its performance on historical data.
- Alerts: Set up alerts based on the
alertcondition messages in TradingView's alert settings if you want notifications.
Important Considerations:
- Market Structure Complexity: The definition of "fractal swing before the choch" can be interpreted in many ways. The current implementation uses a simple lookback. You might need to refine this based on how you visually identify those swings.
- ChoCH Robustness: The MS logic is simplified. Ensure the
ms_length parameter provides reliable fractal points for your analysis.
- Session Timing: Timezones and daylight saving can sometimes cause edge cases. Ensure your
gmt_tz setting is accurate.
- Risk Management: Always use appropriate position sizing and stop losses. Test different
sl_fractal_lookback and tp_percent values.
- No Re-entry: This strategy is designed for a single entry per Asian breakout event. It does not re-enter if the stop loss is hit.