{"id":147,"date":"2025-09-13T18:42:18","date_gmt":"2025-09-13T10:42:18","guid":{"rendered":"https:\/\/yinyang.taichi.us.kg\/?p=147"},"modified":"2025-09-18T14:41:40","modified_gmt":"2025-09-18T06:41:40","slug":"like-to-delve-deeper-into-any-of-these-specific-indicators-emas-rsi-or-bollinger-bands-or-discuss-the-role-of-the-atr-in-this-script-for-stop-loss-calculation","status":"publish","type":"post","link":"https:\/\/yinyang.taichi.us.kg\/?k=124c20374f177bab","title":{"rendered":"like to delve deeper into any of these specific indicators (EMAs, RSI, or Bollinger Bands) or discuss the role of the ATR in this script for stop-loss calculation"},"content":{"rendered":"\n<h2 class=\"wp-block-heading has-accent-3-color has-text-color has-link-color wp-elements-9f19ab65ab7bb61396d61149ba52e44d\">Multi-Indicator Trading Strategy: EMA, RSI, Bollinger Bands&#8221; script, including the role of ATR for stop-loss calculation.<\/h2>\n\n\n\n<p class=\"is-style-default has-contrast-color has-base-background-color has-text-color has-background has-link-color wp-elements-77159b35ce3a95f08fc237f37a150136\"><strong>1. Exponential Moving Averages (EMAs)<\/strong><\/p>\n\n\n\n<p><strong>What they are:<\/strong> EMAs are used to smooth price data, similar to Simple Moving Averages (SMAs), but they give more weight to recent prices. This makes them more responsive to current price changes [Source: Previous conversation].<\/p>\n\n\n\n<p><strong>How they are used in the script:<\/strong><\/p>\n\n\n\n<p>\u2022 <strong>Inputs:<\/strong> The script allows you to customize the lengths for three EMAs: <code>len_fast<\/code> (default 5), <code>len_mid<\/code> (default 10), and <code>len_slow<\/code> (default 20). The source for these calculations is typically the <code>close<\/code> price.<\/p>\n\n\n\n<p>\u2022 <strong>Calculations:<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <code>ema_fast = ta.ema(src, len_fast)<\/code><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <code>ema_mid = ta.ema(src, len_mid)<\/code><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <code>ema_slow = ta.ema(src, len_slow)<\/code><\/p>\n\n\n\n<p>\u2022 <strong>Role in Signals:<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <strong>Trend Confirmation:<\/strong> The EMAs are used together to establish a &#8220;strong uptrend&#8221; or &#8220;strong downtrend.&#8221;<\/p>\n\n\n\n<p class=\"has-accent-3-color has-text-color has-link-color wp-elements-d80e3a69d9977819ae905fde19fe36f6\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u25aa A <code>is_strong_uptrend<\/code> condition is met when <code>ema_fast<\/code> is above <code>ema_mid<\/code>, AND <code>ema_mid<\/code> is above <code>ema_slow<\/code>. This hierarchical order indicates a strong bullish trend.<\/p>\n\n\n\n<p class=\"has-accent-3-color has-text-color has-link-color wp-elements-975845b7bafcd4bf2f5fd79cf0915462\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u25aa A <code>is_strong_downtrend<\/code> condition is met when <code>ema_fast<\/code> is below <code>ema_mid<\/code>, AND <code>ema_mid<\/code> is below <code>ema_slow<\/code>. This indicates a strong bearish trend.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <strong>Crossover Triggers:<\/strong> The <code>ema_fast<\/code> crossing over or under the <code>ema_mid<\/code> acts as a primary trigger for signals:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u25aa For a <code>buy_signal<\/code>, <code>ta.crossover(ema_fast, ema_mid)<\/code> is required.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u25aa For a <code>sell_signal<\/code>, <code>ta.crossunder(ema_fast, ema_mid)<\/code> is required.<\/p>\n\n\n\n<p>\u2022 <strong>Visuals:<\/strong> The <code>ema_fast<\/code>, <code>ema_mid<\/code>, and <code>ema_slow<\/code> are all plotted on the chart in aqua, yellow, and orange, respectively, to visually represent the trend.<\/p>\n\n\n\n<p><strong>2. Relative Strength Index (RSI)<\/strong><\/p>\n\n\n\n<p><strong>What it is:<\/strong> The RSI is a momentum oscillator that measures the speed and change of price movements. It oscillates between 0 and 100, typically used to identify overbought or oversold conditions.<\/p>\n\n\n\n<p><strong>How it is used in the script:<\/strong><\/p>\n\n\n\n<p>\u2022 <strong>Inputs:<\/strong> You can set the <code>len_rsi<\/code> (RSI Length, default 14), <code>rsi_overbought<\/code> level (default 70), and <code>rsi_oversold<\/code> level (default 30).<\/p>\n\n\n\n<p>\u2022 <strong>Calculations:<\/strong> The RSI is calculated using Pine Script&#8217;s built-in <code>ta.rsi<\/code> function: <code>rsi = ta.rsi(src, len_rsi)<\/code>.<\/p>\n\n\n\n<p>\u2022 <strong>Role in Signals:<\/strong> The RSI acts as a <strong>filter<\/strong> for both buy and sell signals, aiming to prevent trades from being entered at extreme price points:<\/p>\n\n\n\n<p class=\"has-accent-3-color has-text-color has-link-color wp-elements-325540b8d5d229d2869e829c10415eb8\">&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 For a <code>buy_signal<\/code>, the <code>rsi<\/code> must be <strong>below<\/strong> the <code>rsi_overbought<\/code> level (<code>rsi &lt; rsi_overbought<\/code>). This means the market should not already be considered &#8220;too high&#8221;.<\/p>\n\n\n\n<p class=\"has-accent-3-color has-text-color has-link-color wp-elements-c02d0c2fbbd901fc3956d90cfb80fe17\">&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 For a <code>sell_signal<\/code>, the <code>rsi<\/code> must be <strong>above<\/strong> the <code>rsi_oversold<\/code> level (<code>rsi &gt; rsi_oversold<\/code>). This means the market should not already be considered &#8220;too low&#8221;.<\/p>\n\n\n\n<p>3. Bollinger Bands (BB)<\/p>\n\n\n\n<p><strong>What they are:<\/strong> Bollinger Bands are a volatility indicator. They consist of a middle band (a Simple Moving Average) and two outer bands (upper and lower) that are typically two standard deviations away from the middle band. The bands widen or narrow based on market volatility.<\/p>\n\n\n\n<p><strong>How they are used in the script:<\/strong><\/p>\n\n\n\n<p>\u2022 <strong>Inputs:<\/strong> The script allows you to configure <code>len_bb<\/code> (BB Length, default 20) and <code>mult_bb<\/code> (BB Standard Deviation Multiplier, default 2.0).<\/p>\n\n\n\n<p>\u2022 <strong>Calculations:<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <code>bb_basis = ta.sma(src, len_bb)<\/code>: This is the middle band, a Simple Moving Average of the source price.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <code>bb_dev = ta.stdev(src, len_bb) * mult_bb<\/code>: This calculates the standard deviation of the price over <code>len_bb<\/code> periods and multiplies it by the <code>mult_bb<\/code> to determine the distance of the outer bands from the basis.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <code>bb_upper = bb_basis + bb_dev<\/code>: The upper band.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <code>bb_lower = bb_basis - bb_dev<\/code>: The lower band.<\/p>\n\n\n\n<p>\u2022 <strong>Role in Signals:<\/strong> Bollinger Bands are used to confirm <strong>volatility and price position<\/strong> relative to the average:<\/p>\n\n\n\n<p class=\"has-accent-3-color has-text-color has-link-color wp-elements-ec780795ca41b1bfdf05395af89f7193\">&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 For a <code>buy_signal<\/code>, the <code>close<\/code> price must be <strong>above<\/strong> the <code>bb_basis<\/code> line (<code>close &gt; bb_basis<\/code>). This confirms bullish sentiment within the volatility envelope.<\/p>\n\n\n\n<p class=\"has-accent-3-color has-text-color has-link-color wp-elements-a0907796fb39c3c8b64616dda6a3cc60\">&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 For a <code>sell_signal<\/code>, the <code>close<\/code> price must be <strong>below<\/strong> the <code>bb_basis<\/code> line (<code>close &lt; bb_basis<\/code>). This confirms bearish sentiment.<\/p>\n\n\n\n<p>\u2022 <strong>Visuals:<\/strong> The <code>bb_basis<\/code>, <code>bb_upper<\/code>, and <code>bb_lower<\/code> are all plotted on the chart, with the area between the upper and lower bands filled for visual clarity.<\/p>\n\n\n\n<p class=\"has-base-color has-accent-3-background-color has-text-color has-background has-link-color wp-elements-b632fac0cd69654677675aab24bcd49e\">4. Average True Range (ATR) for Stop Loss<\/p>\n\n\n\n<p><strong>What it is:<\/strong> ATR is a measure of market volatility. It indicates how much an asset moves, on average, during a given timeframe. It&#8217;s often used in risk management to set stop-loss levels based on an asset&#8217;s typical price fluctuations.<\/p>\n\n\n\n<p><strong>How it is used in the script:<\/strong><\/p>\n\n\n\n<p>\u2022 <strong>Inputs:<\/strong> You can customize the <code>len_atr<\/code> (ATR Length, default 14) and <code>atr_multiplier<\/code> (ATR Stop Loss Multiplier, default 2.0).<\/p>\n\n\n\n<p>\u2022 <strong>Calculations:<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <code>atr = ta.atr(len_atr)<\/code>: The ATR value is calculated using Pine Script&#8217;s built-in <code>ta.atr<\/code> function.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <code>stop_loss_level_long = low - atr * atr_multiplier<\/code>: For a long position (buy), the suggested stop loss is set a certain multiple of ATR below the current bar&#8217;s <code>low<\/code>.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 <code>stop_loss_level_short = high + atr * atr_multiplier<\/code>: For a short position (sell), the suggested stop loss is set a certain multiple of ATR above the current bar&#8217;s <code>high<\/code>.<\/p>\n\n\n\n<p>\u2022 <strong>Role in Risk Management:<\/strong> The ATR is <em>not<\/em> directly involved in generating the buy\/sell signals themselves. Instead, it&#8217;s used for <strong>risk management<\/strong> by dynamically suggesting a stop-loss level once a signal is generated:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 The <code>sl_price<\/code> variable tracks the suggested stop-loss level.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 If a <code>buy_signal<\/code> occurs, <code>sl_price<\/code> is set to <code>stop_loss_level_long<\/code>.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u25e6 If a <code>sell_signal<\/code> occurs, <code>sl_price<\/code> is set to <code>stop_loss_level_short<\/code>.<\/p>\n\n\n\n<p>\u2022 <strong>Visuals:<\/strong> The <code>sl_price<\/code> is plotted on the chart as a red line, but only when a new signal is generated, making it a dynamic visual aid for managing risk.<\/p>\n\n\n\n<p>This comprehensive strategy combines these indicators to create robust trading signals by considering trend, momentum, and volatility, along with built-in risk management using ATR.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u00a9 Gemini\n\/\/@version=5\nindicator(\"Enhanced Trend, Momentum &amp; Volatility Strategy\", shorttitle=\"TMV Enhanced\", overlay=true)\n\n\/\/ --- SECTION: INDICATOR INPUTS ---\n\/\/ This section allows you to customize the settings for each indicator in the strategy.\n\n\/\/ Exponential Moving Averages (EMAs) for trend direction\nema_group = \"Trend Indicators (EMAs)\"\nlen_fast = input.int(5, title=\"Fast EMA Length\", group=ema_group, inline=\"ema_lens\")\nlen_mid = input.int(10, title=\"Mid EMA Length\", group=ema_group, inline=\"ema_lens\")\nlen_slow = input.int(20, title=\"Slow EMA Length\", group=ema_group, inline=\"ema_lens\")\nsrc = input(close, \"Source\", group=ema_group)\n\n\/\/ Relative Strength Index (RSI) for momentum\nrsi_group = \"Momentum Indicator (RSI)\"\nlen_rsi = input.int(14, title=\"RSI Length\", group=rsi_group)\n\n\/\/ Bollinger Bands for Volatility\nbb_group = \"Volatility Indicator (Bollinger Bands)\"\nlen_bb = input.int(20, title=\"BB Length\", group=bb_group)\nmult_bb = input.float(2.0, title=\"BB StdDev Multiplier\", group=bb_group, step=0.1)\n\n\/\/ Average True Range (ATR) for Stop Loss\natr_group = \"Risk Management (ATR)\"\nlen_atr = input.int(14, \"ATR Length\", group=atr_group)\natr_multiplier = input.float(2.0, \"ATR Stop Loss Multiplier\", group=atr_group, step=0.5)\n\n\/\/ --- SECTION: ENHANCED CONFLUENCE FILTERS ---\n\/\/ These optional filters can be enabled to make the buy\/sell signals more accurate.\nfilter_group = \"Confluence Filters (for Accuracy)\"\nuse_strict_trend_filter = input.bool(true, title=\"Use Stricter Trend Filter (Price &gt; Slow EMA)?\", group=filter_group)\nuse_rsi_filter = input.bool(true, title=\"Use RSI Momentum Filter (RSI &gt; 50 for Buy)?\", group=filter_group)\nuse_vol_filter = input.bool(true, title=\"Use Volume Filter (Volume &gt; Avg Volume)?\", group=filter_group)\nlen_vol = input.int(20, title=\"Volume SMA Length\", group=filter_group)\n\n\n\/\/ --- SECTION: CALCULATIONS ---\n\/\/ Calculate the values for our indicators.\n\n\/\/ EMAs\nema_fast = ta.ema(src, len_fast)\nema_mid = ta.ema(src, len_mid)\nema_slow = ta.ema(src, len_slow)\n\n\/\/ RSI\nrsi = ta.rsi(src, len_rsi)\n\n\/\/ Bollinger Bands\nbb_basis = ta.sma(src, len_bb)\nbb_dev = ta.stdev(src, len_bb) * mult_bb\nbb_upper = bb_basis + bb_dev\nbb_lower = bb_basis - bb_dev\n\n\/\/ ATR\natr = ta.atr(len_atr)\n\n\/\/ Average Volume for the filter\navg_vol = ta.sma(volume, len_vol)\n\n\n\/\/ --- SECTION: ENHANCED STRATEGY LOGIC ---\n\/\/ Define the conditions with stricter confluence for more accurate signals.\n\n\/\/ --- Bullish Conditions ---\n\/\/ 1. Core Trend: EMAs are stacked bullishly (fast &gt; mid &gt; slow).\n\/\/ 2. Core Trigger: The fast EMA crosses above the mid EMA.\n\/\/ 3. Filter 1 (Optional): Price is above the slow EMA for stricter trend confirmation.\n\/\/ 4. Filter 2 (Optional): RSI is above 50, confirming bullish momentum is in control.\n\/\/ 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.\n\nis_strong_uptrend = ema_fast &gt; ema_mid and ema_mid &gt; ema_slow\nstrict_trend_buy_filter = not use_strict_trend_filter or close &gt; ema_slow\nrsi_momentum_buy_filter = not use_rsi_filter or rsi &gt; 50\nvolume_conviction_filter = not use_vol_filter or volume &gt; avg_vol\n\nbuy_signal = ta.crossover(ema_fast, ema_mid) and is_strong_uptrend and strict_trend_buy_filter and rsi_momentum_buy_filter and volume_conviction_filter\n\n\/\/ --- Bearish Conditions ---\n\/\/ 1. Core Trend: EMAs are stacked bearishly (fast &lt; mid &lt; slow).\n\/\/ 2. Core Trigger: The fast EMA crosses below the mid EMA.\n\/\/ 3. Filter 1 (Optional): Price is below the slow EMA for stricter trend confirmation.\n\/\/ 4. Filter 2 (Optional): RSI is below 50, confirming bearish momentum is in control.\n\/\/ 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.\n\nis_strong_downtrend = ema_fast &lt; ema_mid and ema_mid &lt; ema_slow\nstrict_trend_sell_filter = not use_strict_trend_filter or close &lt; ema_slow\nrsi_momentum_sell_filter = not use_rsi_filter or rsi &lt; 50\n\/\/ Note: High volume confirms conviction for both bullish and bearish moves.\n\nsell_signal = ta.crossunder(ema_fast, ema_mid) and is_strong_downtrend and strict_trend_sell_filter and rsi_momentum_sell_filter and volume_conviction_filter\n\n\n\/\/ --- SECTION: PLOTTING &amp; VISUALS ---\n\/\/ Plot the indicators and the buy\/sell signals on the chart.\n\n\/\/ Plot Bollinger Bands\nplot(bb_basis, \"BB Basis\", color=color.new(color.gray, 50))\np_upper = plot(bb_upper, \"BB Upper\", color=color.new(color.gray, 80))\np_lower = plot(bb_lower, \"BB Lower\", color=color.new(color.gray, 80))\nfill(p_upper, p_lower, color=color.new(color.gray, 95), title=\"BB Fill\")\n\n\/\/ Plot EMAs\nplot(ema_fast, \"Fast EMA\", color=color.new(color.aqua, 0), linewidth=2)\nplot(ema_mid, \"Mid EMA\", color=color.new(color.yellow, 0), linewidth=2)\nplot(ema_slow, \"Slow EMA\", color=color.new(color.orange, 0), linewidth=2)\n\n\/\/ Plot Buy Signals on the chart\nplotshape(buy_signal, \"Buy Signal\", style=shape.labelup, location=location.belowbar, color=color.new(color.green, 20), text=\"BUY\", textcolor=color.white, size=size.small)\n\n\/\/ Plot Sell Signals on the chart\nplotshape(sell_signal, \"Sell Signal\", style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 20), text=\"SELL\", textcolor=color.white, size=size.small)\n\n\/\/ Calculate and plot the suggested Stop Loss level\nstop_loss_level_long = low - atr * atr_multiplier\nstop_loss_level_short = high + atr * atr_multiplier\n\nvar float sl_price = na\nif (buy_signal)\n    sl_price := stop_loss_level_long\nif (sell_signal)\n    sl_price := stop_loss_level_short\n    \nplot(sl_price, \"Suggested Stop Loss\", color=color.new(color.red, 0), style=plot.style_linebr, linewidth=2)\n\n\/\/ Alert Conditions\nalertcondition(buy_signal, title=\"TMV Buy Signal\", message=\"Potential Buy Signal on {{ticker}}\")\nalertcondition(sell_signal, title=\"TMV Sell Signal\", message=\"Potential Sell Signal on {{ticker}}\")\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u00a9 Gemini add volume version\n\/\/@version=5\nindicator(\"Enhanced Trend, Momentum &amp; Volatility Strategy\", shorttitle=\"TMV Enhanced\", overlay=true)\n\n\/\/ --- SECTION: INDICATOR INPUTS ---\n\/\/ This section allows you to customize the settings for each indicator in the strategy.\n\n\/\/ Exponential Moving Averages (EMAs) for trend direction\nema_group = \"Trend Indicators (EMAs)\"\nlen_fast = input.int(5, title=\"Fast EMA Length\", group=ema_group, inline=\"ema_lens\")\nlen_mid = input.int(10, title=\"Mid EMA Length\", group=ema_group, inline=\"ema_lens\")\nlen_slow = input.int(20, title=\"Slow EMA Length\", group=ema_group, inline=\"ema_lens\")\nsrc = input(close, \"Source\", group=ema_group)\n\n\/\/ Relative Strength Index (RSI) for momentum\nrsi_group = \"Momentum Indicator (RSI)\"\nlen_rsi = input.int(14, title=\"RSI Length\", group=rsi_group)\n\n\/\/ Bollinger Bands for Volatility\nbb_group = \"Volatility Indicator (Bollinger Bands)\"\nlen_bb = input.int(20, title=\"BB Length\", group=bb_group)\nmult_bb = input.float(2.0, title=\"BB StdDev Multiplier\", group=bb_group, step=0.1)\n\n\/\/ Average True Range (ATR) for Stop Loss\natr_group = \"Risk Management (ATR)\"\nlen_atr = input.int(14, \"ATR Length\", group=atr_group)\natr_multiplier = input.float(2.0, \"ATR Stop Loss Multiplier\", group=atr_group, step=0.5)\n\n\/\/ --- SECTION: ENHANCED CONFLUENCE FILTERS ---\n\/\/ These optional filters can be enabled to make the buy\/sell signals more accurate.\nfilter_group = \"Confluence Filters (for Accuracy)\"\nuse_strict_trend_filter = input.bool(true, title=\"Use Stricter Trend Filter (Price &gt; Slow EMA)?\", group=filter_group)\nuse_rsi_filter = input.bool(true, title=\"Use RSI Momentum Filter (RSI &gt; 50 for Buy)?\", group=filter_group)\nuse_vol_filter = input.bool(true, title=\"Use Basic Volume Filter (Volume &gt; Avg Volume)?\", group=filter_group)\nlen_vol = input.int(20, title=\"Volume SMA Length\", group=filter_group)\n\n\/\/ --- SECTION: ADVANCED VOLUME FILTERS ---\nadv_vol_group = \"Advanced Volume Filters\"\nuse_obv_filter = input.bool(true, \"Use On-Balance Volume (OBV) Filter?\", group=adv_vol_group)\nlen_obv_ma = input.int(20, \"OBV Smoothing MA Length\", group=adv_vol_group)\nuse_vwma_filter = input.bool(true, \"Use Volume-Weighted MA (VWMA) Filter?\", group=adv_vol_group)\nlen_vwma = input.int(20, \"VWMA Length\", group=adv_vol_group)\n\n\n\/\/ --- SECTION: CALCULATIONS ---\n\/\/ Calculate the values for our indicators.\n\n\/\/ EMAs\nema_fast = ta.ema(src, len_fast)\nema_mid = ta.ema(src, len_mid)\nema_slow = ta.ema(src, len_slow)\n\n\/\/ RSI\nrsi = ta.rsi(src, len_rsi)\n\n\/\/ Bollinger Bands\nbb_basis = ta.sma(src, len_bb)\nbb_dev = ta.stdev(src, len_bb) * mult_bb\nbb_upper = bb_basis + bb_dev\nbb_lower = bb_basis - bb_dev\n\n\/\/ ATR\natr = ta.atr(len_atr)\n\n\/\/ Average Volume for the filter\navg_vol = ta.sma(volume, len_vol)\n\n\/\/ Advanced Volume Calculations\nobv = ta.obv\nobv_ma = ta.sma(obv, len_obv_ma)\nvwma = ta.vwma(src, len_vwma)\n\n\n\/\/ --- SECTION: ENHANCED STRATEGY LOGIC ---\n\/\/ Define the conditions with stricter confluence for more accurate signals.\n\n\/\/ --- Bullish Conditions ---\n\/\/ 1. Core Trend: EMAs are stacked bullishly (fast &gt; mid &gt; slow).\n\/\/ 2. Core Trigger: The fast EMA crosses above the mid EMA.\n\/\/ 3. Filter 1 (Optional): Price is above the slow EMA for stricter trend confirmation.\n\/\/ 4. Filter 2 (Optional): RSI is above 50, confirming bullish momentum is in control.\n\/\/ 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.\n\/\/ 6. Filter 4 (Optional): OBV is trending up, showing accumulation.\n\/\/ 7. Filter 5 (Optional): Price is above the VWMA, showing strength against the volume-weighted price.\n\nis_strong_uptrend = ema_fast &gt; ema_mid and ema_mid &gt; ema_slow\nstrict_trend_buy_filter = not use_strict_trend_filter or close &gt; ema_slow\nrsi_momentum_buy_filter = not use_rsi_filter or rsi &gt; 50\nvolume_conviction_filter = not use_vol_filter or volume &gt; avg_vol\nobv_buy_filter = not use_obv_filter or obv &gt; obv_ma\nvwma_buy_filter = not use_vwma_filter or close &gt; vwma\n\nbuy_signal = ta.crossover(ema_fast, ema_mid) and is_strong_uptrend and strict_trend_buy_filter and rsi_momentum_buy_filter and volume_conviction_filter and obv_buy_filter and vwma_buy_filter\n\n\/\/ --- Bearish Conditions ---\n\/\/ 1. Core Trend: EMAs are stacked bearishly (fast &lt; mid &lt; slow).\n\/\/ 2. Core Trigger: The fast EMA crosses below the mid EMA.\n\/\/ 3. Filter 1 (Optional): Price is below the slow EMA for stricter trend confirmation.\n\/\/ 4. Filter 2 (Optional): RSI is below 50, confirming bearish momentum is in control.\n\/\/ 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.\n\/\/ 6. Filter 4 (Optional): OBV is trending down, showing distribution.\n\/\/ 7. Filter 5 (Optional): Price is below the VWMA, showing weakness against the volume-weighted price.\n\nis_strong_downtrend = ema_fast &lt; ema_mid and ema_mid &lt; ema_slow\nstrict_trend_sell_filter = not use_strict_trend_filter or close &lt; ema_slow\nrsi_momentum_sell_filter = not use_rsi_filter or rsi &lt; 50\n\/\/ Note: High volume confirms conviction for both bullish and bearish moves.\nobv_sell_filter = not use_obv_filter or obv &lt; obv_ma\nvwma_sell_filter = not use_vwma_filter or close &lt; vwma\n\nsell_signal = ta.crossunder(ema_fast, ema_mid) and is_strong_downtrend and strict_trend_sell_filter and rsi_momentum_sell_filter and volume_conviction_filter and obv_sell_filter and vwma_sell_filter\n\n\n\/\/ --- SECTION: PLOTTING &amp; VISUALS ---\n\/\/ Plot the indicators and the buy\/sell signals on the chart.\n\n\/\/ Plot Bollinger Bands\nplot(bb_basis, \"BB Basis\", color=color.new(color.gray, 50))\np_upper = plot(bb_upper, \"BB Upper\", color=color.new(color.gray, 80))\np_lower = plot(bb_lower, \"BB Lower\", color=color.new(color.gray, 80))\nfill(p_upper, p_lower, color=color.new(color.gray, 95), title=\"BB Fill\")\n\n\/\/ Plot EMAs\nplot(ema_fast, \"Fast EMA\", color=color.new(color.aqua, 0), linewidth=2)\nplot(ema_mid, \"Mid EMA\", color=color.new(color.yellow, 0), linewidth=2)\nplot(ema_slow, \"Slow EMA\", color=color.new(color.orange, 0), linewidth=2)\nplot(vwma, \"VWMA\", color=color.new(color.purple, 0), linewidth=2)\n\n\/\/ Plot Buy Signals on the chart\nplotshape(buy_signal, \"Buy Signal\", style=shape.labelup, location=location.belowbar, color=color.new(color.green, 20), text=\"BUY\", textcolor=color.white, size=size.small)\n\n\/\/ Plot Sell Signals on the chart\nplotshape(sell_signal, \"Sell Signal\", style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 20), text=\"SELL\", textcolor=color.white, size=size.small)\n\n\/\/ Calculate and plot the suggested Stop Loss level\nstop_loss_level_long = low - atr * atr_multiplier\nstop_loss_level_short = high + atr * atr_multiplier\n\nvar float sl_price = na\nif (buy_signal)\n    sl_price := stop_loss_level_long\nif (sell_signal)\n    sl_price := stop_loss_level_short\n    \nplot(sl_price, \"Suggested Stop Loss\", color=color.new(color.red, 0), style=plot.style_linebr, linewidth=2)\n\n\/\/ Alert Conditions\nalertcondition(buy_signal, title=\"TMV Buy Signal\", message=\"Potential Buy Signal on {{ticker}}\")\nalertcondition(sell_signal, title=\"TMV Sell Signal\", message=\"Potential Sell Signal on {{ticker}}\")\n\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u00a9 Gemini final version with price showing\n\/\/@version=5\nindicator(\"Enhanced Trend, Momentum &amp; Volatility Strategy\", shorttitle=\"TMV Enhanced\", overlay=true)\n\n\/\/ --- SECTION: INDICATOR INPUTS ---\n\/\/ This section allows you to customize the settings for each indicator in the strategy.\n\n\/\/ Exponential Moving Averages (EMAs) for trend direction\nema_group = \"Trend Indicators (EMAs)\"\nlen_fast = input.int(5, title=\"Fast EMA Length\", group=ema_group, inline=\"ema_lens\")\nlen_mid = input.int(10, title=\"Mid EMA Length\", group=ema_group, inline=\"ema_lens\")\nlen_slow = input.int(20, title=\"Slow EMA Length\", group=ema_group, inline=\"ema_lens\")\nsrc = input(close, \"Source\", group=ema_group)\n\n\/\/ Relative Strength Index (RSI) for momentum\nrsi_group = \"Momentum Indicator (RSI)\"\nlen_rsi = input.int(14, title=\"RSI Length\", group=rsi_group)\n\n\/\/ Bollinger Bands for Volatility\nbb_group = \"Volatility Indicator (Bollinger Bands)\"\nlen_bb = input.int(20, title=\"BB Length\", group=bb_group)\nmult_bb = input.float(2.0, title=\"BB StdDev Multiplier\", group=bb_group, step=0.1)\n\n\/\/ Average True Range (ATR) for Stop Loss\natr_group = \"Risk Management (ATR)\"\nlen_atr = input.int(14, \"ATR Length\", group=atr_group)\natr_multiplier = input.float(2.0, title=\"ATR Stop Loss Multiplier\", group=atr_group, step=0.5)\n\n\/\/ --- SECTION: ENHANCED CONFLUENCE FILTERS ---\n\/\/ These optional filters can be enabled to make the buy\/sell signals more accurate.\nfilter_group = \"Confluence Filters (for Accuracy)\"\nuse_strict_trend_filter = input.bool(true, title=\"Use Stricter Trend Filter (Price &gt; Slow EMA)?\", group=filter_group)\nuse_rsi_filter = input.bool(true, title=\"Use RSI Momentum Filter (RSI &gt; 50 for Buy)?\", group=filter_group)\nuse_vol_filter = input.bool(true, title=\"Use Basic Volume Filter (Volume &gt; Avg Volume)?\", group=filter_group)\nlen_vol = input.int(20, title=\"Volume SMA Length\", group=filter_group)\n\n\/\/ --- SECTION: ADVANCED VOLUME FILTERS ---\nadv_vol_group = \"Advanced Volume Filters\"\nuse_obv_filter = input.bool(true, \"Use On-Balance Volume (OBV) Filter?\", group=adv_vol_group)\nlen_obv_ma = input.int(20, \"OBV Smoothing MA Length\", group=adv_vol_group)\nuse_vwma_filter = input.bool(true, \"Use Volume-Weighted MA (VWMA) Filter?\", group=adv_vol_group)\nlen_vwma = input.int(20, \"VWMA Length\", group=adv_vol_group)\n\n\n\/\/ --- SECTION: CALCULATIONS ---\n\/\/ Calculate the values for our indicators.\n\n\/\/ EMAs\nema_fast = ta.ema(src, len_fast)\nema_mid = ta.ema(src, len_mid)\nema_slow = ta.ema(src, len_slow)\n\n\/\/ RSI\nrsi = ta.rsi(src, len_rsi)\n\n\/\/ Bollinger Bands\nbb_basis = ta.sma(src, len_bb)\nbb_dev = ta.stdev(src, len_bb) * mult_bb\nbb_upper = bb_basis + bb_dev\nbb_lower = bb_basis - bb_dev\n\n\/\/ ATR\natr = ta.atr(len_atr)\n\n\/\/ Average Volume for the filter\navg_vol = ta.sma(volume, len_vol)\n\n\/\/ Advanced Volume Calculations\nobv = ta.obv\nobv_ma = ta.sma(obv, len_obv_ma)\nvwma = ta.vwma(src, len_vwma)\n\n\n\/\/ --- SECTION: ENHANCED STRATEGY LOGIC ---\n\/\/ Define the conditions with stricter confluence for more accurate signals.\n\n\/\/ --- Bullish Conditions ---\n\/\/ 1. Core Trend: EMAs are stacked bullishly (fast &gt; mid &gt; slow).\n\/\/ 2. Core Trigger: The fast EMA crosses above the mid EMA.\n\/\/ 3. Filter 1 (Optional): Price is above the slow EMA for stricter trend confirmation.\n\/\/ 4. Filter 2 (Optional): RSI is above 50, confirming bullish momentum is in control.\n\/\/ 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.\n\/\/ 6. Filter 4 (Optional): OBV is trending up, showing accumulation.\n\/\/ 7. Filter 5 (Optional): Price is above the VWMA, showing strength against the volume-weighted price.\n\nis_strong_uptrend = ema_fast &gt; ema_mid and ema_mid &gt; ema_slow\nstrict_trend_buy_filter = not use_strict_trend_filter or close &gt; ema_slow\nrsi_momentum_buy_filter = not use_rsi_filter or rsi &gt; 50\nvolume_conviction_filter = not use_vol_filter or volume &gt; avg_vol\nobv_buy_filter = not use_obv_filter or obv &gt; obv_ma\nvwma_buy_filter = not use_vwma_filter or close &gt; vwma\n\nbuy_signal = ta.crossover(ema_fast, ema_mid) and is_strong_uptrend and strict_trend_buy_filter and rsi_momentum_buy_filter and volume_conviction_filter and obv_buy_filter and vwma_buy_filter\n\n\/\/ --- Bearish Conditions ---\n\/\/ 1. Core Trend: EMAs are stacked bearishly (fast &lt; mid &lt; slow).\n\/\/ 2. Core Trigger: The fast EMA crosses below the mid EMA.\n\/\/ 3. Filter 1 (Optional): Price is below the slow EMA for stricter trend confirmation.\n\/\/ 4. Filter 2 (Optional): RSI is below 50, confirming bearish momentum is in control.\n\/\/ 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.\n\/\/ 6. Filter 4 (Optional): OBV is trending down, showing distribution.\n\/\/ 7. Filter 5 (Optional): Price is below the VWMA, showing weakness against the volume-weighted price.\n\nis_strong_downtrend = ema_fast &lt; ema_mid and ema_mid &lt; ema_slow\nstrict_trend_sell_filter = not use_strict_trend_filter or close &lt; ema_slow\nrsi_momentum_sell_filter = not use_rsi_filter or rsi &lt; 50\n\/\/ Note: High volume confirms conviction for both bullish and bearish moves.\nobv_sell_filter = not use_obv_filter or obv &lt; obv_ma\nvwma_sell_filter = not use_vwma_filter or close &lt; vwma\n\nsell_signal = ta.crossunder(ema_fast, ema_mid) and is_strong_downtrend and strict_trend_sell_filter and rsi_momentum_sell_filter and volume_conviction_filter and obv_sell_filter and vwma_sell_filter\n\n\n\/\/ --- SECTION: PLOTTING &amp; VISUALS ---\n\/\/ Plot the indicators and the buy\/sell signals on the chart.\n\n\/\/ Plot Bollinger Bands\nplot(bb_basis, \"BB Basis\", color=color.new(color.gray, 50))\np_upper = plot(bb_upper, \"BB Upper\", color=color.new(color.gray, 80))\np_lower = plot(bb_lower, \"BB Lower\", color=color.new(color.gray, 80))\nfill(p_upper, p_lower, color=color.new(color.gray, 95), title=\"BB Fill\")\n\n\/\/ Plot EMAs\nplot(ema_fast, \"Fast EMA\", color=color.new(color.aqua, 0), linewidth=2)\nplot(ema_mid, \"Mid EMA\", color=color.new(color.yellow, 0), linewidth=2)\nplot(ema_slow, \"Slow EMA\", color=color.new(color.orange, 0), linewidth=2)\nplot(vwma, \"VWMA\", color=color.new(color.purple, 0), linewidth=2)\n\n\/\/ Plot Buy Signals on the chart\nif buy_signal\n    buy_label_text = \"BUY\\n\" + str.tostring(close, format.mintick)\n    label.new(bar_index, low, text=buy_label_text, color=color.new(color.green, 20), textcolor=color.white, style=label.style_label_up, yloc=yloc.belowbar, size=size.small)\n\n\/\/ Plot Sell Signals on the chart\nif sell_signal\n    sell_label_text = \"SELL\\n\" + str.tostring(close, format.mintick)\n    label.new(bar_index, high, text=sell_label_text, color=color.new(color.red, 20), textcolor=color.white, style=label.style_label_down, yloc=yloc.abovebar, size=size.small)\n\n\/\/ Calculate and plot the suggested Stop Loss level\nstop_loss_level_long = low - atr * atr_multiplier\nstop_loss_level_short = high + atr * atr_multiplier\n\nvar float sl_price = na\nif (buy_signal)\n    sl_price := stop_loss_level_long\nif (sell_signal)\n    sl_price := stop_loss_level_short\n    \nplot(sl_price, \"Suggested Stop Loss\", color=color.new(color.red, 0), style=plot.style_linebr, linewidth=2)\n\n\/\/ Alert Conditions\nalertcondition(buy_signal, title=\"TMV Buy Signal\", message=\"Potential Buy Signal on {{ticker}} at {{close}}\")\nalertcondition(sell_signal, title=\"TMV Sell Signal\", message=\"Potential Sell Signal on {{ticker}} at {{close}}\")\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Multi-Indicator Trading Strategy: EMA, RSI, Bollinger Bands&#8221; script, including the role of ATR for stop-loss calculation.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-3"],"_links":{"self":[{"href":"https:\/\/yinyang.taichi.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yinyang.taichi.us.kg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yinyang.taichi.us.kg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yinyang.taichi.us.kg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yinyang.taichi.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=147"}],"version-history":[{"count":6,"href":"https:\/\/yinyang.taichi.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":362,"href":"https:\/\/yinyang.taichi.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions\/362"}],"wp:attachment":[{"href":"https:\/\/yinyang.taichi.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yinyang.taichi.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yinyang.taichi.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}