OPEN-SOURCE SCRIPT
Aktualisiert 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.
Versionshinweise
Update on pre-settings, and Triggered TP/SL once per bar instead of Per bar closed this help to prevent volitive price movement. Versionshinweise
Fix Errors:- [*Custom Alert Messages: Previous version was not able to pick Symbol and Price this version is help to fix that.]
- [*Add mark TP and SL histories as the record so you can backtest and improve more on your settings]
We hope you like it and gain more profits from it.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Knowledge's Joe
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Knowledge's Joe
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.