Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Reversal Finder – Tradingview to Amibroker AFL Code Conversion

2 min read

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 lows
malen for the length of the Simple Moving Average (SMA) of the candle rang
mult as a multiplier for the average range to identify significant range expansions
rangethreshold 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 last lookback period, and the close is within the upper portion of the range as determined by rangethreshold.
  • Short Signal (shortsig): Generated under the opposite conditions, with the high above the highest high of the last lookback 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.

Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Line Trading – OpenAlgo Automation Module for Amibroker Users

The line Trading Automation tool is designed for Manual traders who want to perform level-based trade execution faster and also bring some advanced trade...
Rajandran R
55 sec read

Mini Certification Course on Algorithmic Trading

Welcome to the Mini Certification on Algorithmic Trading using Amibroker and OpenAlgo! This comprehensive 4-part series is designed to equip you with the knowledge...
Rajandran R
1 min read

Pivot Reversal Strategy – Tradingview Pinescript to Amibroker AFL…

Pivot Reversal Strategy is a popular in-built strategy in Tradingview Platform. Here I had attempted to convert the pinescript v5 to Amibroker AFL Code....
Rajandran R
3 min read

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More