Reversal Finder is designed to identify potential reversal signals in a stock’s price action. It highlights specific bars that meet the criteria for a potential reversal based on the comparison of the current bar’s range (difference between the high and low) with a moving average of recent ranges, as well as the position of the bar’s closing price relative to its range.
This code is converted from the Reversal Finder Tradingview Pinescript Code
Inputs Parameters
It defines several user-input parameters such as
lookback
period for identifying highs and lowsmalen
for the length of the Simple Moving Average (SMA) of the candle rangmult
as a multiplier for the average range to identify significant range expansionsrangethreshold
to determine the placement of the closing price within the range of the bar for a valid signal.
Additional options include toggles for highlighting signal bars and tracking the highest high/lowest low.
Signal Generation Conditions
- Long Signal (
longsig
): Generated when the current bar’s range is at least as large as the average range multiplied by a user-defined factor (mult
), the low of the current bar is below the lowest low of the lastlookback
period, and the close is within the upper portion of the range as determined byrangethreshold
. - Short Signal (
shortsig
): Generated under the opposite conditions, with the high above the highest high of the lastlookback
period and the close within the lower portion of the range.
Range Finder – Amibroker AFL Code
//Code Generated by Rajandran R - www.marketcalls.in
_SECTION_BEGIN("Reversal Finder");
SetChartOptions(0,chartShowArrows|chartShowDates);
// Inputs
lookback = Param("Lookback period for highs and lows", 20, 1, 100, 1);
malen = Param("SMA length for candles range", 20, 1, 100, 1);
avrange = MA(H-L, malen);
mult = Param("Range multiple", 1.5, 0.1, 5, 0.1);
rangethreshold = Param("Range threshold (% of candle range)", 50, 1, 99, 1) / 100;
barcol = ParamToggle("Highlight signal bars?", "No|Yes", 0);
trackhilo = ParamToggle("Highlight highest high/lowest low?", "No|Yes", 0);
// Signal conditions
longsig = ((H-L)>=(avrange*mult)) AND (L<LLV(Ref(L,-1),lookback)) AND (C>=(H-((H-L)*rangethreshold)));
shortsig = ((H-L)>=(avrange*mult)) AND (H>HHV(Ref(H,-1), lookback)) AND (C<=(L+((H-L)*rangethreshold)));
// Plots for highest recent high/lowest recent low
if(trackhilo)
{
Plot(HHV(Ref(H,-1), lookback), "Highest high", colorGreen, styleThick);
Plot(LLV(Ref(L,-1), lookback), "Lowest low", colorRed, styleThick);
}
//Plot the trading signals
/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(longsig, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(longsig, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(longsig, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(shortsig, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(shortsig, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(shortsig, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
// Bar colours for use with 'highlight signals' option
if(barcol)
{
Color = IIf(longsig, colorGreen, IIf(shortsig, colorRed, colorGrey50));
Plot(C, "Close", Color, styleCandle);
}
else
{
Plot(C, "Close", colorDefault, styleCandle);
}
_SECTION_END();
This AFL script is looking for bars that represent a significant change in price action, suggesting a potential reversal. The criteria include a comparison of the bar’s range against a moving average of recent ranges and specific conditions regarding the closing price’s position within the bar’s range. This approach aims to identify moments when the price action shows a strong move that could indicate the beginning of a reversal trend.