Indicator example
Average Directional Movement Rating
Readonly source from tests/EasyLanguage/David_EasyLanguage, generated Pine Script v6, and an expiry-free example EX5.
Original EasyLanguage
{ Search Tag: WA-ADXR }inputs:Length( 14 ) [DisplayName = "Length",ToolTip = "Enter the number of bars to be used in the calculation of the indicator."];variables:ReturnValue( 0 ),oDMIPlus( 0 ),oDMIMinus( 0 ),oDMI( 0 ),oADX( 0 ),oADXR( 0 ),oVolty( 0 );ReturnValue = DirMovement( H, L, C, Length, oDMIPlus, oDMIMinus, oDMI, oADX, oADXR,oVolty );Plot1( oADX, !( "ADX" ) );Plot2( oADXR, !( "ADXR" ) );{ alert criteria }if AlertEnabled thenbeginif oADXR > oADXR[1] and oADXR[1] <= oADXR[2] thenAlert( !( "ADXR turning up" ) )else if oADXR < oADXR[1] and oADXR[1] >= oADXR[2] thenAlert( !( "ADXR turning down" ) );end;{ ** Copyright © TradeStation Technologies, Inc. All Rights Reserved **** TradeStation reserves the right to modify or overwrite this analysis techniquewith each release. ** }
Generated Pine Script v6
//@version=6indicator("ADXR", overlay=true)// dependencies:__el_dir_movement(float priceHigh, float priceLow, float priceClose, int length) =>float upMove = ta.change(priceHigh)float downMove = -ta.change(priceLow)float plusDM = upMove > downMove and upMove > 0 ? upMove : 0float minusDM = downMove > upMove and downMove > 0 ? downMove : 0float previousClose = nz(priceClose[1], priceClose)float trueRange = math.max(priceHigh - priceLow, math.max(math.abs(priceHigh - previousClose), math.abs(priceLow - previousClose)))float smoothedTR = ta.rma(trueRange, length)float plus = smoothedTR == 0 ? 0 : 100 * ta.rma(plusDM, length) / smoothedTRfloat minus = smoothedTR == 0 ? 0 : 100 * ta.rma(minusDM, length) / smoothedTRfloat directionalDifference = plus - minusfloat sum = plus + minusfloat dmi = sum == 0 ? 0 : 100 * math.abs(directionalDifference) / sumfloat adx = ta.rma(dmi, length)float adxr = (adx + nz(adx[length], adx)) / 2[1, plus, minus, dmi, adx, adxr, smoothedTR]length = input.float(14.0, "length")var float returnvalue = 0var float odmiplus = 0var float odmiminus = 0var float odmi = 0var float oadx = 0var float oadxr = 0var float ovolty = 0float __el_plot1 = nacolor __el_plot1_color = color.bluefloat __el_plot2 = nacolor __el_plot2_color = color.blue[__el_out1_0, __el_out1_1, __el_out1_2, __el_out1_3, __el_out1_4, __el_out1_5, __el_out1_6] = __el_dir_movement(high, low, close, int(length))if bar_index >= 13returnvalue := __el_out1_0odmiplus := __el_out1_1odmiminus := __el_out1_2odmi := __el_out1_3oadx := __el_out1_4oadxr := __el_out1_5ovolty := __el_out1_6__el_plot1 := oadx__el_plot2 := oadxrif trueif oadxr > oadxr[1] and oadxr[1] <= oadxr[2]alert("ADXR turning up", alert.freq_once_per_bar)elseif oadxr < oadxr[1] and oadxr[1] >= oadxr[2]alert("ADXR turning down", alert.freq_once_per_bar)plot(__el_plot1, title="ADX", color=__el_plot1_color)plot(__el_plot2, title="ADXR", color=__el_plot2_color)
Compiled MetaTrader 5 example
The EX5 uses the original script filename stem and has no PineAnywhere expiration guard.