Indicator example

Ulcer Index

Readonly source from tests/EasyLanguage/David_EasyLanguage, generated Pine Script v6, and an expiry-free example EX5.

Original EasyLanguage

  1. { Search Tag: WA-Ulcer Index }
  2. inputs:
  3. Price( Close ) [DisplayName = "Price", ToolTip =
  4. "Enter an EasyLanguage expression to use in the calculation of the Ulcer Index."],
  5. Length( 14 ) [DisplayName = "Length", ToolTip =
  6. "Enter the number of bars to be used in the calculation of the Ulcer Index."],
  7. SafeLevel( 5 ) [DisplayName = "SafeLevel", ToolTip =
  8. "Enter a value below which downward volatility is considered to be low."] ;
  9. variables:
  10. UlcerX( 0 ) ;
  11. UlcerX = UlcerIndex( Price, Length ) ;
  12. Plot1( UlcerX, !( "UlcerX" ) ) ;
  13. Plot2( SafeLevel, !( "SafeLevel" ) ) ;
  14. if AlertEnabled and UlcerX crosses over SafeLevel then
  15. Alert( !( "Indicator crossing over Safe Level" ) ) ;
  16. { ** Copyright © TradeStation Technologies, Inc. All Rights Reserved **
  17. ** TradeStation reserves the right to modify or overwrite this analysis technique
  18. with each release. ** }

Generated Pine Script v6

  1. //@version=6
  2. indicator("UlcerIndexIndicator", overlay=true)
  3. // dependencies:
  4. __el_ulcer_index(float source, int length) =>
  5. float peak = ta.highest(source, length)
  6. float drawdownPercent = peak == 0 ? 0 : 100 * (source - peak) / peak
  7. math.sqrt(ta.sma(drawdownPercent * drawdownPercent, length))
  8. price = input.source(close, "price")
  9. length = input.float(14.0, "length")
  10. safelevel = input.float(5.0, "safelevel")
  11. var float ulcerx = 0
  12. float __el_plot1 = na
  13. color __el_plot1_color = color.blue
  14. float __el_plot2 = na
  15. color __el_plot2_color = color.blue
  16. __el_call1 = __el_ulcer_index(price, int(length))
  17. if bar_index >= 13
  18. ulcerx := __el_call1
  19. __el_plot1 := ulcerx
  20. __el_plot2 := safelevel
  21. if true and ta.crossover(ulcerx, safelevel)
  22. alert("Indicator crossing over Safe Level", alert.freq_once_per_bar)
  23. plot(__el_plot1, title="UlcerX", color=__el_plot1_color)
  24. plot(__el_plot2, title="SafeLevel", color=__el_plot2_color)

Compiled MetaTrader 5 example

The EX5 uses the original script filename stem and has no PineAnywhere expiration guard.

Download UlcerIndexIndicator.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.