OPEN-SOURCE SCRIPT
已更新 LANZ Strategy 5.0 [Backtest]

🔷 LANZ Strategy 5.0 [Backtest] — Rule-Based BUY Logic with Time Filter, Session Limits and Auto SL/TP Execution
This is the backtest version of LANZ Strategy 5.0, built as a strategy script to evaluate real performance under fixed intraday conditions. It automatically places BUY and SELL trades based on structured candle confirmation, EMA trend alignment, and session-based filters. The system simulates real-time execution with precise Stop Loss and Take Profit levels.
📌 Built for traders seeking to simulate clean intraday logic with fully automated entries and performance metrics.
🧠 Core Logic & Strategy Conditions
✅ BUY Signal Conditions:
If all are true, a BUY order is executed at market, with SL and TP set immediately.
🔻 SELL Signal Conditions (Optional):
Exactly inverse to BUY (below EMA + 3 bearish candles). Disabled by default.
🕐 Operational Time Filter (New York Time)
You can fully customize your intraday window:
The system evaluates signals only within this range, even across midnight if configured.
🔁 Trade Management System
🧪 Backtest Accuracy
This version uses:
This ensures realistic behavior in the TradingView strategy tester.
⚙️ Flow Summary (Step-by-Step)
On every bar, check:
If conditions met → A BUY trade is opened:
Trade closes:
📊 Settings Overview
👨💻 Credits:
💡 Developed by: LANZ
🧠 Strategy logic & execution: LANZ
✅ Designed for: Clean backtesting, clarity in execution, and intraday logic simulation
This is the backtest version of LANZ Strategy 5.0, built as a strategy script to evaluate real performance under fixed intraday conditions. It automatically places BUY and SELL trades based on structured candle confirmation, EMA trend alignment, and session-based filters. The system simulates real-time execution with precise Stop Loss and Take Profit levels.
📌 Built for traders seeking to simulate clean intraday logic with fully automated entries and performance metrics.
🧠 Core Logic & Strategy Conditions
✅ BUY Signal Conditions:
- Price is above the EMA200
- The last 3 candles are bullish (close > open)
- The signal occurs within the defined session window (NY time)
- Daily trade limit has not been exceeded
If all are true, a BUY order is executed at market, with SL and TP set immediately.
🔻 SELL Signal Conditions (Optional):
Exactly inverse to BUY (below EMA + 3 bearish candles). Disabled by default.
🕐 Operational Time Filter (New York Time)
You can fully customize your intraday window:
- Start Time: e.g., 01:15 NY
- End Time: e.g., 16:00 NY
The system evaluates signals only within this range, even across midnight if configured.
🔁 Trade Management System
- One trade at a time per signal
- Trades include a Stop Loss (SL) and Take Profit (TP) based on pip distance
- Trade result is calculated automatically
- Each signal is shown with a triangle marker (BUY only, by default)
🧪 Backtest Accuracy
This version uses:
- strategy.order() for entries
- strategy.exit() for SL and TP
- strategy.close_all() at the configured manual closing time
This ensures realistic behavior in the TradingView strategy tester.
⚙️ Flow Summary (Step-by-Step)
On every bar, check:
- Is the time within the operational session?
- Is the price above the EMA?
- Are the last 3 candles bullish?
If conditions met → A BUY trade is opened:
- SL = entry – X pips
- TP = entry + Y pips
Trade closes:
- If SL or TP is hit
- Or at the configured manual close time (e.g., 16:00 NY)
📊 Settings Overview
- Timeframe: 1-hour (ideal)
- SL/TP: Configurable in pips
- Max trades/day: User-defined (default = 99 = unlimited)
- Manual close: Adjustable by time
- Entry type: Market (not limit)
- Visuals: Plotshape triangle for BUY entry
👨💻 Credits:
💡 Developed by: LANZ
🧠 Strategy logic & execution: LANZ
✅ Designed for: Clean backtesting, clarity in execution, and intraday logic simulation
版本注释
Update 🎁The LANZ Strategy 5.0 [Backtest] now includes a smart distance filter to prevent redundant entries at similar price levels. A new input parameter allows users to define a minimum pip distance required between trades. The system stores the price of the last executed order and blocks new trades unless the price has moved beyond the specified threshold. This logic resets automatically after any trade closure—whether by Stop Loss, Take Profit, or manual close—allowing the next signal to be evaluated fresh. This ensures cleaner entry logic and avoids clustered trades in tight ranges.
版本注释
Update (Backtest): added ⏳ Entry Cutoff (Bars) to block new orders N bars before session end (NY). The cutoff converts bars→minutes from the active timeframe, is validated to be shorter than the session, and works across midnight. From now on, orders are only allowed inside isWithinEntryWindow; canOpen = daily limit + distance filter + this window. If the cutoff ≥ session duration, no entries are allowed (failsafe). Core logic remains the same: Buy/Sell rules (EMA + 3 candles), minimum distance between entries, daily counter and resets after SL/TP, and strategy.close_all at the configured NY time. Position sizing (percent_of_equity), pyramiding, risk inputs, and the Buy plotshape are unchanged.开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。