0% found this document useful (0 votes)
225 views3 pages

DRFX Reversal Algorithm Overview

Uploaded by

vashugautam97
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
225 views3 pages

DRFX Reversal Algorithm Overview

Uploaded by

vashugautam97
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
  • Indicator Parameters
  • Algorithm Functions and Logic

//@version=5

indicator("Reversal Algo", overlay=true)

// Input parameters
alertLong = [Link](true, title="Long Alert", group="Alerts")
alertShort = [Link](true, title="Short Alert", group="Alerts")

signalFilter = [Link](false, title="Show Buy/Sell Dots When Close >


DonchianUpper", group="Dots", inline="21")
showDots = [Link](true, title="Show Buy/Sell Dots When Not Filtered",
group="Dots", inline="21")

macd_fast = [Link](20, title="Fast Length", group="MACD Settings", inline="1")


macd_slow = [Link](50, title="Slow Length", group="MACD Settings", inline="1")
macd_src = [Link](close, title="Source", group="MACD Settings")
macd_signal_ema = [Link](12, title="Signal Smoothing", group="MACD Settings")

// Calculate MACD
[macd, signal, hist] = [Link](macd_src, macd_fast, macd_slow, macd_signal_ema)
cross_UP = [Link](macd, signal)
cross_DN = [Link](macd, signal)

// RSI
rsiPeriod = [Link](14, "RSI Length", group="RSI Settings")
rsisrc = [Link](close, "RSI Source", group="RSI Settings")
rsi = [Link](rsisrc, rsiPeriod)
rsisignal = rsi - 50

// Volatility for support and resistance zones


volatilityPeriod = [Link](10, title="Volatility Period", minval=1,
group="Support/Resistance Cloud")
multiplier = [Link](5.0, title="Multiplier", minval=1, step=0.5,
group="Support/Resistance Cloud")

// Color Settings
gradientRange = [Link](2000, title="Gradient Range", minval=500, step=500,
group="Colors")

// Calculate volatility
atr = [Link](volatilityPeriod)
upperBand = (high + low) / 2 + atr * multiplier
lowerBand = (high + low) / 2 - atr * multiplier

// Determine support and resistance zones with more precise levels


supportLevel = [Link](low, 20)
resistanceLevel = [Link](high, 20)
preciseSupportZoneStart = [Link](supportLevel, [Link](lowerBand, 20))
preciseSupportZoneEnd = [Link](supportLevel, [Link](lowerBand, 20))
preciseResistanceZoneStart = [Link](resistanceLevel, [Link](upperBand, 20))
preciseResistanceZoneEnd = [Link](resistanceLevel, [Link](upperBand, 20))

// Kalman filter function


kalmanFilter(input, kf_q, kf_r) =>
var kf_x = 0.0
var kf_p = 1.0
kf_k = kf_p / (kf_p + kf_r)
kf_x := kf_k * input + (1 - kf_k) * nz(kf_x[1])
kf_p := (1 - kf_k) * kf_p + kf_q
kf_x
// Smooth the support and resistance zone levels using Kalman filter
kf_q = 0.01
kf_r = 0.1
smoothedSupportZoneStart = kalmanFilter(preciseSupportZoneStart, kf_q, kf_r)
smoothedSupportZoneEnd = kalmanFilter(preciseSupportZoneEnd, kf_q, kf_r)
smoothedResistanceZoneStart = kalmanFilter(preciseResistanceZoneStart, kf_q, kf_r)
smoothedResistanceZoneEnd = kalmanFilter(preciseResistanceZoneEnd, kf_q, kf_r)

// Determine trend based on MACD histogram and RSI signal


histPower = [Link](hist)
rsiPower = [Link](rsisignal)
bullishTrend = hist > 0 and hist > hist[1] and rsisignal > 0
bearishTrend = hist < 0 and hist < hist[1] and rsisignal < 0
consolidatingTrend = not bullishTrend and not bearishTrend

// Change bar color based on MACD histogram power and RSI signal
barcolor(na(histPower) ? [Link] :
bullishTrend ? color.from_gradient(histPower, 0, gradientRange,
[Link](0, 255, 0), [Link](0, 150, 0)) :
bearishTrend ? color.from_gradient(histPower, 0, gradientRange,
[Link](255, 0, 0), [Link](150, 0, 0)) :
color.from_gradient(histPower, 0, gradientRange, [Link](150, 0 , 0),
[Link](0, 150, 0)))

// Display histPower value and rsiPower value for debug


//[Link](bar_index, high, [Link](histPower, [Link]),
style=label.style_none, yloc=[Link], color=[Link])
//[Link](bar_index, high, [Link](rsiPower, [Link]),
style=label.style_none, yloc=[Link], color=[Link])

// Plot Buy and Sell Signals


plotshape(showDots and cross_UP and rsisignal > 0 and (not signalFilter or close >
smoothedSupportZoneEnd), title="Strong Buy", color=[Link](0, 255, 0),
style=[Link], location=[Link], size=[Link], text="Strong",
textcolor=[Link])
plotshape(showDots and cross_DN and rsisignal < 0 and (not signalFilter or close <
smoothedResistanceZoneStart), title="Strong Sell", color=[Link](255, 0, 0),
style=[Link], location=[Link], size=[Link],
text="Strong", textcolor=[Link])

plotshape(showDots and cross_UP and rsisignal <= 0 and (not signalFilter or close >
smoothedSupportZoneEnd), title="Buy", color=[Link](0, 255, 0),
style=[Link], location=[Link], size=[Link], text="Buy",
textcolor=[Link])
plotshape(showDots and cross_DN and rsisignal >= 0 and (not signalFilter or close <
smoothedResistanceZoneStart), title="Sell", color=[Link](255, 0, 0),
style=[Link], location=[Link], size=[Link], text="Sell",
textcolor=[Link])

// Plot the dynamic support and resistance zones


supportZone = smoothedSupportZoneStart
resistanceZone = smoothedResistanceZoneEnd
fill(plot(supportZone, title="Support Zone", style=plot.style_linebr, linewidth=1,
color=[Link]([Link], 70)), plot(smoothedSupportZoneEnd,
style=plot.style_linebr, linewidth=1, color=[Link]([Link], 70)),
color=[Link]([Link], 80))
fill(plot(smoothedResistanceZoneStart, title="Resistance Zone",
style=plot.style_linebr, linewidth=1, color=[Link]([Link], 70)),
plot(smoothedResistanceZoneEnd, style=plot.style_linebr, linewidth=1,
color=[Link]([Link], 70)), color=[Link]([Link], 80))

// Function to generate alert message


alertMessage(msg) =>
"Symbol = " + [Link] + " | TimeFrame = " + [Link] + " |
Price = " + [Link](close) + " | Reversal Algo " + msg

// Alerts
if alertLong and cross_UP and (not signalFilter or close > smoothedSupportZoneEnd)
alert(alertMessage("Buy"), alert.freq_once_per_bar_close)

if alertShort and cross_DN and (not signalFilter or close <


smoothedResistanceZoneStart)
alert(alertMessage("Sell"), alert.freq_once_per_bar_close)

Common questions

Powered by AI

Within the "Reversal Algo" strategy, dynamic support and resistance zones serve the purpose of determining critical price levels where reversals are likely to occur. They are dynamically calculated using the Average True Range (ATR) for volatility adjustment and are adjusted by a multiplier. These zones are further smoothed using the Kalman filter to refine their predictive accuracy. The function of these zones is to provide traders with key levels where the market might reverse direction or consolidate. They guide traders in making informed decisions on entry and exit points based on the proximity of the current price to these zones, incorporating both price action and volatility dynamics .

In the "Reversal Algo" strategy, buy and sell alerts are issued based on specific trigger conditions involving MACD and RSI signals, as well as the price in relation to the smoothed support and resistance zones. A buy alert is triggered when the MACD crosses above the signal line (cross_UP) while the RSI signal is greater than 0, and either the signalFilter is off or the closing price is above the smoothed support zone. Conversely, a sell alert is triggered under opposite conditions: when MACD crosses below the signal line (cross_DN) and the RSI signal is less than 0, with either the signalFilter off or the close price below the smoothed resistance zone. Alerts are then generated using the 'alertMessage' function, which formats and outputs the alert for execution .

The gradient color system in the "Reversal Algo" trading indicator is utilized to visually represent the strength and direction of trends based on the MACD histogram power and RSI signals. The bar color changes based on the calculated MACD histogram power: if the trend is bullish, the bars transition from green to darker green as histogram power increases; for bearish trends, bars transition from red to darker red. In the case of consolidating trends, the bars transition from less intense to more intense shades of red and green. This gradient system helps traders quickly interpret the strength and momentum of trends at a glance .

The Kalman filter is employed in the "Reversal Algo" strategy to smooth the levels of the support and resistance zones. It processes the raw support and resistance levels calculated from the ATR and Donchian channels by applying a recursive predictive and updating mechanism. Specifically, it smooths the 'precise support zone start and end' and 'precise resistance zone start and end' by reducing noise, which results in more stable and potentially more accurate support and resistance zones for trading decisions .

The MACD configuration in the "Reversal Algo" strategy deviates from traditional settings primarily in its selection of the fast (20) and slow (50) lengths, as opposed to the more common settings of 12 and 26 respectively. Such a deviation emphasizes longer-term trends by smoothing out shorter-term fluctuations, which may be deemed more suitable for identifying more pronounced trend reversals rather than short-term shifts. By focusing on these longitudinal trends, the strategy might reduce the frequency of false signals typically associated with short-term noise, potentially resulting in fewer but more robust signal generation .

The "Reversal Algo" strategy uses the MACD and RSI indicators for trend identification by analyzing the relationship between their signals. The MACD is calculated using a fast length of 20, a slow length of 50, and signal smoothing period of 12. A bullish trend is identified when the MACD histogram is positive, indicating that the MACD line is above the signal line, and when it is increasing compared to the previous bar. Simultaneously, the RSI signal, which is derived from an RSI period of 14, must be greater than 0, indicating upward momentum. Conversely, a bearish trend is indicated when the MACD histogram is negative, decreasing compared to the previous bar, and when the RSI signal is less than 0. If neither bullish nor bearish conditions are met, the strategy identifies a consolidating trend .

The 'signalFilter' parameter in the "Reversal Algo" strategy is crucial for refining the conditions under which buy and sell signals are validated, impacting the sensitivity and frequency of generated alerts. When the signalFilter is enabled, additional filtering based on the price relative to the smoothed support and resistance zones is applied. This means buy signals require the current close to be above the resistance end, while sell signals necessitate the close to be below the support start. Thus, the signalFilter acts as an extra validation layer, potentially reducing false signals and enhancing the strategy's robustness by ensuring trend signals are confirmed with price action beyond these critical zones. Its proper adjustment is vital for balancing between signal reliability and timely market entry .

The "Reversal Algo" strategy employs a series of visual techniques to ensure that the plotted support and resistance zones are distinguishable on the chart. The zones are represented as bands using the 'fill' function, which draws semi-transparent colored fills between the smoothed support and resistance levels. The support zone is displayed with semi-transparent blue shades, while the resistance zone uses red shades, with different transparency levels (adjusted using alpha blending). This color differentiation and transparency help traders easily identify these zones against the backdrop of price action, ensuring clear visual distinction .

Volatility is integrated into the "Reversal Algo" strategy by using the Average True Range (ATR) to adjust the support and resistance zones dynamically. Specifically, the strategy calculates the ATR over a specified period (default is 10) and uses a multiplier (default value of 5) to determine the width of the bands. The calculated upper and lower bands define the zones, representing potential support and resistance where price reversals might occur. This approach helps traders adapt to changing market volatility by re-calibrating the zones according to current market conditions .

In the "Reversal Algo" strategy, the RSI signal complements the MACD findings by providing momentum confirmation to filter MACD crossovers. The RSI signal, calculated as the difference from 50, offers a gauge on bullish or bearish momentum: RSI > 0 confirms bullish momentum when MACD crosses above its signal line, supporting buy signals; RSI < 0 indicates bearish momentum confirming sell signals when MACD crosses below its signal line. This combination enables the strategy to not only identify potential trend directions based on price and volume via MACD but also to assess the strength of these trends using RSI, enhancing the robustness and reliability of trade signals .

//@version=5
indicator("Reversal Algo", overlay=true)
// Input parameters
alertLong = input.bool(true, title="Long Alert", gr
// Smooth the support and resistance zone levels using Kalman filter
kf_q = 0.01
kf_r = 0.1
smoothedSupportZoneStart = kalman
plot(smoothedResistanceZoneEnd, style=plot.style_linebr, linewidth=1, 
color=color.new(color.red, 70)), color=color.new(color

You might also like