OPEN-SOURCE SCRIPT
PG DMean & Price Sync ver 9.4 - Consolidated

PG DMean & Price Sync Strategy (SD Filter)
This strategy combines the momentum-oscillator properties of the Detrended Mean (DMean) with a Standard Deviation (SD) Price Filter for confirming trend direction, aiming to isolate high-conviction trades while actively managing risk.
🔑 Core Logic
DMean Momentum Signal: The strategy's primary engine is the DMean, which measures the percentage difference between the current closing price and a longer-term Moving Average (price_ma). It is then smoothed by a DMean Signal line (MA of the DMean).
Entry Signal: A trade is triggered when the DMean line crosses above (for Long) or below (for Short) its Signal Line, but it must clear a user-defined Dead Zone Threshold to confirm momentum commitment.
SD Filter Confirmation (Price Sync): A Standard Deviation Channel, based on a separate user-defined price source and period, is used to filter trades.
Long Filter: Allows Long entries only when the price is trading above the lower SD band, suggesting the current price action is stronger than the recent average volatility to the downside.
Short Filter: Allows Short entries only when the price is currently below the Filter Basis (SMA), confirming a bearish stance within the SD channel.
🛡️ Risk & Exit Management
Primary Exit: All trades are exited by reverse DMean Crossover/Crossunder, meaning the position is closed when the DMean momentum reverses against the open trade (e.g., DMean crosses under the Signal to exit a Long).
Hard Stop Loss (Short Trades): A mandatory percentage-based Hard Stop Loss is implemented only for short positions to protect against sudden upward price spikes, closing the trade if the loss exceeds the set percentage. (Note: This version does not include a Hard SL for Long trades).
📊 Performance Dashboard
A custom Performance Dashboard Table is displayed at the bottom right of the chart to provide real-time, at-a-glance comparison of the strategy's equity performance versus a simple Buy & Hold over the selected backtesting date range.
This strategy combines the momentum-oscillator properties of the Detrended Mean (DMean) with a Standard Deviation (SD) Price Filter for confirming trend direction, aiming to isolate high-conviction trades while actively managing risk.
🔑 Core Logic
DMean Momentum Signal: The strategy's primary engine is the DMean, which measures the percentage difference between the current closing price and a longer-term Moving Average (price_ma). It is then smoothed by a DMean Signal line (MA of the DMean).
Entry Signal: A trade is triggered when the DMean line crosses above (for Long) or below (for Short) its Signal Line, but it must clear a user-defined Dead Zone Threshold to confirm momentum commitment.
SD Filter Confirmation (Price Sync): A Standard Deviation Channel, based on a separate user-defined price source and period, is used to filter trades.
Long Filter: Allows Long entries only when the price is trading above the lower SD band, suggesting the current price action is stronger than the recent average volatility to the downside.
Short Filter: Allows Short entries only when the price is currently below the Filter Basis (SMA), confirming a bearish stance within the SD channel.
🛡️ Risk & Exit Management
Primary Exit: All trades are exited by reverse DMean Crossover/Crossunder, meaning the position is closed when the DMean momentum reverses against the open trade (e.g., DMean crosses under the Signal to exit a Long).
Hard Stop Loss (Short Trades): A mandatory percentage-based Hard Stop Loss is implemented only for short positions to protect against sudden upward price spikes, closing the trade if the loss exceeds the set percentage. (Note: This version does not include a Hard SL for Long trades).
📊 Performance Dashboard
A custom Performance Dashboard Table is displayed at the bottom right of the chart to provide real-time, at-a-glance comparison of the strategy's equity performance versus a simple Buy & Hold over the selected backtesting date range.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.