OPEN-SOURCE SCRIPT
Actualizado Smart MACD + KNN (Dynamic SL Fix)

This script is a comprehensive trading system designed for TradingView that combines traditional momentum indicators with machine learning concepts and advanced trade management logic.
Here is a detailed description of its features:
1. Signal Generation (The "Brain")
Smart MACD: Uses a standard MACD (Moving Average Convergence Divergence) to identify buy and sell opportunities.
KNN Machine Learning: Filters every MACD signal using a K-Nearest Neighbors algorithm. It analyzes historical market data (RSI, CCI, Volatility, Volume) to determine if the current signal is statistically likely to be profitable. If the ML prediction is negative, the signal is ignored.
Trend Filter: An optional 200 EMA filter ensures you only trade with the long-term trend (Buy above EMA 200, Sell below).
Volatility Guard: Automatically blocks signals during extreme volatility spikes (like news events) to prevent bad entries.
2. Trade Management (The Logic)
Single Trade Mode: The script enforces a "one trade at a time" rule. It will not generate a new "Buy" signal if a "Buy" trade is already active. It waits for the trade to hit Take Profit (TP) or Stop Loss (SL) before resetting.
Flip Capability: While it blocks same-direction signals, it allows opposite signals. If you are in a Long trade and a valid Short signal appears, it effectively "flips" the trade—closing the Long and opening the Short immediately.
Dynamic Stop Loss (Stepped ROI): This is a profit-locking feature.
Trigger 1: When price moves X% in profit, the SL moves to a specified ROI % (e.g., Break Even).
Trigger 2: When price moves further to Y% profit, the SL moves again to lock in a larger profit.
3. Automation & Alerts
Customizable Messages: You can input your own text or JSON commands for Entry, TP, and SL alerts directly in the settings menu.
3x Trigger Safety: Every alert fires 3 times continuously to ensure that external bots or webhooks receive the signal, minimizing the risk of missed trades due to network lag.
4. Visuals
TP/SL Lines: Draws active Stop Loss and Take Profit lines on the chart that update in real-time.
Dashboard Table: A panel in the top-right corner displays the precise price levels for the current TP and SL.
Fog & Colors: The background and candles change color based on the trend direction, giving you an immediate visual cue of market sentiment.
Here is a detailed description of its features:
1. Signal Generation (The "Brain")
Smart MACD: Uses a standard MACD (Moving Average Convergence Divergence) to identify buy and sell opportunities.
KNN Machine Learning: Filters every MACD signal using a K-Nearest Neighbors algorithm. It analyzes historical market data (RSI, CCI, Volatility, Volume) to determine if the current signal is statistically likely to be profitable. If the ML prediction is negative, the signal is ignored.
Trend Filter: An optional 200 EMA filter ensures you only trade with the long-term trend (Buy above EMA 200, Sell below).
Volatility Guard: Automatically blocks signals during extreme volatility spikes (like news events) to prevent bad entries.
2. Trade Management (The Logic)
Single Trade Mode: The script enforces a "one trade at a time" rule. It will not generate a new "Buy" signal if a "Buy" trade is already active. It waits for the trade to hit Take Profit (TP) or Stop Loss (SL) before resetting.
Flip Capability: While it blocks same-direction signals, it allows opposite signals. If you are in a Long trade and a valid Short signal appears, it effectively "flips" the trade—closing the Long and opening the Short immediately.
Dynamic Stop Loss (Stepped ROI): This is a profit-locking feature.
Trigger 1: When price moves X% in profit, the SL moves to a specified ROI % (e.g., Break Even).
Trigger 2: When price moves further to Y% profit, the SL moves again to lock in a larger profit.
3. Automation & Alerts
Customizable Messages: You can input your own text or JSON commands for Entry, TP, and SL alerts directly in the settings menu.
3x Trigger Safety: Every alert fires 3 times continuously to ensure that external bots or webhooks receive the signal, minimizing the risk of missed trades due to network lag.
4. Visuals
TP/SL Lines: Draws active Stop Loss and Take Profit lines on the chart that update in real-time.
Dashboard Table: A panel in the top-right corner displays the precise price levels for the current TP and SL.
Fog & Colors: The background and candles change color based on the trend direction, giving you an immediate visual cue of market sentiment.
Notas de prensa
Update on pre-settings, and Triggered TP/SL once per bar instead of Per bar closed this help to prevent volitive price movement. Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que la republicación del código está sujeta a nuestras Normas internas.
Knowledge's Joe
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como asesoramiento o recomendaciones financieras, de inversión, de trading o de otro tipo proporcionadas o respaldadas por TradingView. Más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que la republicación del código está sujeta a nuestras Normas internas.
Knowledge's Joe
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como asesoramiento o recomendaciones financieras, de inversión, de trading o de otro tipo proporcionadas o respaldadas por TradingView. Más información en Condiciones de uso.