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

  1. { Search Tag: WA-ADXR }
  2. inputs:
  3. Length( 14 ) [
  4. DisplayName = "Length",
  5. ToolTip = "Enter the number of bars to be used in the calculation of the indicator."];
  6. variables:
  7. ReturnValue( 0 ),
  8. oDMIPlus( 0 ),
  9. oDMIMinus( 0 ),
  10. oDMI( 0 ),
  11. oADX( 0 ),
  12. oADXR( 0 ),
  13. oVolty( 0 );
  14. ReturnValue = DirMovement( H, L, C, Length, oDMIPlus, oDMIMinus, oDMI, oADX, oADXR,
  15. oVolty );
  16. Plot1( oADX, !( "ADX" ) );
  17. Plot2( oADXR, !( "ADXR" ) );
  18. { alert criteria }
  19. if AlertEnabled then
  20. begin
  21. if oADXR > oADXR[1] and oADXR[1] <= oADXR[2] then
  22. Alert( !( "ADXR turning up" ) )
  23. else if oADXR < oADXR[1] and oADXR[1] >= oADXR[2] then
  24. Alert( !( "ADXR turning down" ) );
  25. end;
  26. { ** Copyright © TradeStation Technologies, Inc. All Rights Reserved **
  27. ** TradeStation reserves the right to modify or overwrite this analysis technique
  28. with each release. ** }

Generated Pine Script v6

  1. //@version=6
  2. indicator("ADXR", overlay=true)
  3. // dependencies:
  4. __el_dir_movement(float priceHigh, float priceLow, float priceClose, int length) =>
  5. float upMove = ta.change(priceHigh)
  6. float downMove = -ta.change(priceLow)
  7. float plusDM = upMove > downMove and upMove > 0 ? upMove : 0
  8. float minusDM = downMove > upMove and downMove > 0 ? downMove : 0
  9. float previousClose = nz(priceClose[1], priceClose)
  10. float trueRange = math.max(priceHigh - priceLow, math.max(math.abs(priceHigh - previousClose), math.abs(priceLow - previousClose)))
  11. float smoothedTR = ta.rma(trueRange, length)
  12. float plus = smoothedTR == 0 ? 0 : 100 * ta.rma(plusDM, length) / smoothedTR
  13. float minus = smoothedTR == 0 ? 0 : 100 * ta.rma(minusDM, length) / smoothedTR
  14. float directionalDifference = plus - minus
  15. float sum = plus + minus
  16. float dmi = sum == 0 ? 0 : 100 * math.abs(directionalDifference) / sum
  17. float adx = ta.rma(dmi, length)
  18. float adxr = (adx + nz(adx[length], adx)) / 2
  19. [1, plus, minus, dmi, adx, adxr, smoothedTR]
  20. length = input.float(14.0, "length")
  21. var float returnvalue = 0
  22. var float odmiplus = 0
  23. var float odmiminus = 0
  24. var float odmi = 0
  25. var float oadx = 0
  26. var float oadxr = 0
  27. var float ovolty = 0
  28. float __el_plot1 = na
  29. color __el_plot1_color = color.blue
  30. float __el_plot2 = na
  31. color __el_plot2_color = color.blue
  32. [__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))
  33. if bar_index >= 13
  34. returnvalue := __el_out1_0
  35. odmiplus := __el_out1_1
  36. odmiminus := __el_out1_2
  37. odmi := __el_out1_3
  38. oadx := __el_out1_4
  39. oadxr := __el_out1_5
  40. ovolty := __el_out1_6
  41. __el_plot1 := oadx
  42. __el_plot2 := oadxr
  43. if true
  44. if oadxr > oadxr[1] and oadxr[1] <= oadxr[2]
  45. alert("ADXR turning up", alert.freq_once_per_bar)
  46. else
  47. if oadxr < oadxr[1] and oadxr[1] >= oadxr[2]
  48. alert("ADXR turning down", alert.freq_once_per_bar)
  49. plot(__el_plot1, title="ADX", color=__el_plot1_color)
  50. 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.

Download ADXR.ex5
An unexpected error occurred. Reload×

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.