INVITE-ONLY SCRIPT
Güncellendi

Heikin Ashi Buy Sell by JPTrades

5 419
Description
I use this script a lot to know the trend of a stock, cryptocurrency, forex.

This script is based on an EMA study. Which tells us the trend of a stock.

How to use
You can see the trend of a stock if it goes up it says buy and if it goes down it says sell. It is recommended that you put it with the heinki ashi table. It can help you much more.

How to access the script
Send me a message to the private

Observations
This advice is NOT financial advice.
We do not provide personal investment advice and we are not a licensed and qualified investment advisor.
All information found here, including ideas, opinions, views, predictions, forecasts, comments, suggestions, or action selections, expressed or implied in this document, are for informational, entertainment, or educational purposes only and should not be be construed as personal investment advice.
We will not and will not be responsible for any action you take as a result of what you read here.
We only provide this information to help you make a better decision.
While the information provided is believed to be accurate, it may include errors or inaccuracies.
Sürüm Notları
🚀 Improvements Made to the Trading Script 🚀
1. Trend Filter with Long EMA 📈
What was done: A longer-period EMA (emaTrend) was added to confirm the trend direction.
Why it's useful: This filter avoids false signals in sideways markets. Buy signals are only generated if the price is above the trend EMA, and sell signals if it's below.
Example: If the fast EMA crosses above the slow EMA, but the price is below the trend EMA, no buy signal is generated. 🛑
2. Volume Confirmation 📊
What was done: A volume condition (volumeSpike) was added to confirm signals.
Why it's useful: A significant volume increase validates the strength of the signal, reducing false positives.
Example: If there's a bullish EMA crossover and the RSI is in oversold, but no volume spike, no buy signal is triggered. ❌
3. Dynamic Stop-Loss and Take-Profit 🔒💰
What was done: The Average True Range (ATR) was used to calculate dynamic stop-loss and take-profit levels.
Why it's useful: The ATR adapts to market volatility, making stop-loss and take-profit levels more accurate and suited to current conditions.
Example: If ATR is 10 and the risk-reward ratio is 2, the stop-loss will be 15 (1.5 * ATR) and the take-profit will be 30 (stop-loss * 2). 📉📈
4. Stop-Loss and Take-Profit Labels on the Chart 📊
What was done: Visual labels for stop-loss and take-profit levels were added to the chart.
Why it's useful: It allows you to see risk and reward levels directly on the chart, making position management easier. ✔️
Example: When a buy signal is generated, "SL" (stop-loss) labels will appear below the price and "TP" (take-profit) labels above the price. 🔽⬆️
5. Simplified Alerts 🔔
What was done: Alert messages were simplified to avoid concatenation errors with dynamic values.
Why it's useful: Although dynamic values like stop-loss and take-profit cannot be included in the alerts, they now indicate that a signal has been detected and suggest checking the chart for specific levels.
Example: "🚨 Buy signal detected! Check the chart for stop-loss and take-profit levels." 🔍
6. Visual Improvements 👀
What was done: Color fills were added between the fast and slow EMAs to highlight the trend direction.
Why it's useful: The green fill indicates an uptrend, and the red fill indicates a downtrend. This makes trend identification easier visually.
Example: If the fast EMA is above the slow EMA, the area between them will be filled with green to show an uptrend. 🌱
7. Improved Buy and Sell Conditions 📉📈
What was done: Multiple conditions (EMA crossovers, RSI, volume, and trend) were combined to generate more reliable signals.
Why it's useful: By combining several indicators, false signals are reduced, and signal accuracy is improved.
Example: A buy signal is generated only if:
✅ The fast EMA crosses above the slow EMA.
✅ The RSI is in oversold territory.
✅ There’s a volume spike.
✅ The price is above the trend EMA. 🔝
8. Bug Fixes 🔧
What was done: The syntax error related to dynamic value concatenation in alerts was fixed.
Why it's useful: The script now runs correctly without errors, improving the user experience on TradingView.
Example: Instead of showing incorrect dynamic value concatenation, alerts now show a generic, clear message like "Buy signal detected! Check the chart for details." 🛠️
Summary of the Improvements 📋
Feature Description
Trend Filter Added a longer EMA to confirm the trend direction.
Volume Confirmation Signals are only generated if there is a significant volume spike.
Dynamic Stop-Loss and Take-Profit Levels based on the ATR, adapting to market volatility.
Chart Labels SL and TP labels are shown visually on the chart.
Simplified Alerts Clear alert messages suggesting to check the chart for stop-loss and take-profit levels.
Visual Improvements Fill between the EMAs to highlight the trend.
Improved Conditions Combining multiple indicators for more reliable signals.
Bug Fixes Fixed concatenation error in alerts.
Example of Usage 💡
Buy Signal: When:

The fast EMA crosses above the slow EMA 📈
The RSI is in oversold territory 🔻
There is a volume spike 📊
The price is above the trend EMA 🟢
Sell Signal: When:

The fast EMA crosses below the slow EMA 📉
The RSI is in overbought territory 🔺
There is a volume spike 📊
The price is below the trend EMA 🔴
Sürüm Notları
1. New Features Added
These are entirely new functionalities not present in the original code:

ADX (Average Directional Index) for Trend Strength:
-Added ADX calculation using ta.dmi(adxLength, adxLength) to measure trend strength.
-Introduced input: adxLength = input.int(14, title="ADX Length", minval=1).
-Introduced input: adxThreshold = input.int(25, title="ADX Trend Strength Threshold", minval=10).
-Added condition strongTrend = adx > adxThreshold to filter signals during strong trends.
-Plotted ADX in a separate pane: plot(adx, color=color.purple, title="ADX", display=display.pane).

MACD Confirmation:
-Added MACD calculation using ta.macd(close, macdFast, macdSlow, macdSignal).
-Introduced inputs:
macdFast = input.int(12, title="MACD Fast Length", minval=1)
macdSlow = input.int(26, title="MACD Slow Length", minval=1)
macdSignal = input.int(9, title="MACD Signal Length", minval=1)
-Added conditions macdBullish = macdLine > signalLine and macdBearish = macdLine < signalLine to confirm buy/sell signals.

Dynamic ATR Multiplier:
-Added volatility-based ATR adjustment:
Calculated volatility = ta.stdev(close, 14) and avgVolatility = ta.sma(volatility, 14).
Computed dynamicATR = dynamicATRMult * (volatility / avgVolatility).
-Introduced input: dynamicATRMult = input.float(1.5, title="Dynamic ATR Multiplier Base", minval=0.5).
-Updated stop-loss calculation: stopLoss = atr * dynamicATR (replacing static atr * 1.5).

Volatility-Based Position Sizing:
-Added position size calculation: positionSize = positionSizing ? math.floor(1 / (volatility / close)) : 1.
-Introduced input: positionSizing = input.bool(true, title="Use Volatility-Based Position Sizing").
-Created display label: positionLabel = positionSizing ? str.tostring(positionSize, "#") + " units" : "N/A".
-Displayed position size on chart when signals occur: label.new(..., text="Size: " + positionLabel, ...).

Show/Hide Labels Toggle:
-Added input: showLabels = input.bool(true, title="Show Signal Labels").
-Used to control visibility of buy/sell signals (plotshape) and stop-loss/take-profit/position size labels (label.new).
2. Enhancements to Existing Features
These are improvements or modifications to features already present in the original code:

Strengthened Buy/Sell Conditions:
-Original buy condition: ta.crossover(emaFast, emaSlow) and rsi < rsiOversold and volumeSpike and close > emaTrend.
-Updated buy condition: Added and strongTrend and macdBullish for ADX and MACD confirmation.
-Original sell condition: ta.crossunder(emaFast, emaSlow) and rsi > rsiOverbought and volumeSpike and close < emaTrend.
-Updated sell condition: Added and strongTrend and macdBearish.
-Result: Signals are more robust, reducing false positives by requiring trend strength and momentum alignment.

Stop-Loss and Take-Profit:
-Original: Used static multiplier stopLoss = atr * 1.5.
-Updated: Uses dynamic multiplier stopLoss = atr * dynamicATR based on volatility.
-Take-profit remains takeProfit = stopLoss * riskRewardRatio, but benefits from dynamic stop-loss.

Signal Display Control:
-Original: Buy/sell signals always displayed via plotshape.
-Updated: Signals are conditional on showLabels using plotshape(showLabels ? buyCondition : false, ...) and plotshape(showLabels ? sellCondition : false, ...).

Label Enhancements:
-Original: Displayed stop-loss (SL) and take-profit (TP) labels only.
-Updated: Added position size label (Size: X units) when showLabels is true.
-Labels are now conditional on both signal occurrence and showLabels.

3. Error Fixes
These address syntax and scope issues that arose during updates:

Fixed plotshape Local Scope Error:
-Original: plotshape calls were in global scope but later versions attempted to place them in if blocks, causing errors.
-Fix: Moved plotshape calls to global scope with conditional logic: showLabels ? buyCondition : false and showLabels ? sellCondition : false.
-Ensures compliance with Pine Script v6 rules prohibiting plotshape in local scopes.

Fixed alertcondition Syntax Error:
-Original: Alerts were correct: alertcondition(buyCondition, title="Buy Signal", message="BUY signal detected! ...").
-Problematic version: Introduced invalid syntax with {{positionLabel}}, {{stopLoss}}, {{takeProfit}} and stray {{takeProfit}}").
-Fix: Reverted to simple, valid messages: message="BUY signal detected!" and message="SELL signal detected!".
-Note: Removed dynamic values from alerts because Pine Script v6 doesn’t support direct variable interpolation in alertcondition. Values are instead shown via chart labels.

4. Code Structure and Clarity
Minor changes to improve readability and maintainability:

Organized Input Section:
-Grouped new inputs (ADX, MACD, dynamic ATR, etc.) logically with existing ones.
-Kept consistent formatting for clarity.

Consistent Variable Naming:
-Used descriptive names like macdBullish, macdBearish, strongTrend, and dynamicATR to make the code self-explanatory.
Preserved Original Visuals:
Kept EMA plots (fastPlot, slowPlot, trendPlot) and fill (fill(fastPlot, slowPlot, ...)) unchanged.
Added ADX plot as a non-intrusive addition in a separate pane.
5. Removed or Adjusted Features
No features from the original code were removed, but some were adjusted:

Alert Messages:
Original: Included detailed messages with stop-loss and take-profit.
Updated: Simplified to avoid syntax errors, with details moved to chart labels.
Stop-Loss Multiplier:
Original: Fixed at 1.5.
Updated: Dynamic based on volatility (dynamicATR).
Summary of Changes
Added: ADX trend strength, MACD confirmation, dynamic ATR multiplier, volatility-based position sizing, show/hide labels toggle.
Enhanced: Buy/sell conditions (added ADX and MACD filters), stop-loss calculation (dynamic), signal/label display (conditional on showLabels), position size display.
Fixed: plotshape scope errors (moved to global scope), alertcondition syntax errors (removed invalid {{}} syntax).
Preserved: Core EMA, RSI, volume, and ATR logic; all visual elements (EMA plots, fill); alert functionality (simplified).
Improved: Code robustness, signal accuracy, and user control over display.

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.