Indicator example

Triangle Moving Average

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

Original EasyLanguage

  1. { Search Tag: WA-Mov Avg Triangular }
  2. inputs:
  3. Price( Close ) [
  4. DisplayName = "Price",
  5. ToolTip = "Enter an EasyLanguage expression to use in the triangular moving average calculation."],
  6. Length( 9 ) [
  7. DisplayName = "Length",
  8. ToolTip = "Enter the number of bars used in the calculation of the triangular moving average."],
  9. Displace( 0 ) [
  10. DisplayName = "Displace",
  11. ToolTip = "Displacement. Enter the number of bars by which plots will be displaced. Displacement may be positive (left) or negative (right)."];
  12. variables:
  13. AvgTriangular( 0 );
  14. AvgTriangular = TriAverage( Price, Length );
  15. if Displace >= 0 or CurrentBar > AbsValue( Displace ) then
  16. begin
  17. Plot1[Displace]( AvgTriangular, !( "AvgTri" ) );
  18. { alert criteria }
  19. if AlertEnabled and Displace <= 0 then
  20. begin
  21. if Price > AvgTriangular and AvgTriangular > AvgTriangular[1]
  22. and AvgTriangular[1] <= AvgTriangular[2] then
  23. begin
  24. Alert( !( "Indicator turning up" ) ) ;
  25. end
  26. else if Price < AvgTriangular
  27. and AvgTriangular < AvgTriangular[1]
  28. and AvgTriangular[1] >= AvgTriangular[2] then
  29. begin
  30. Alert( !( "Indicator turning down" ) );
  31. end;
  32. end;
  33. end;
  34. { ** Copyright © TradeStation Technologies, Inc. All Rights Reserved **
  35. ** TradeStation reserves the right to modify or overwrite this analysis technique
  36. with each release. ** }

Generated Pine Script v6

  1. //@version=6
  2. indicator("MovAvgTriangleIndicator", overlay=true)
  3. // dependencies:
  4. __el_triangular_average(float source, int length) =>
  5. int firstLength = int(math.ceil((length + 1) / 2.0))
  6. int secondLength = int(math.floor((length + 1) / 2.0))
  7. ta.sma(ta.sma(source, firstLength), secondLength)
  8. price = input.source(close, "price")
  9. length = input.float(9.0, "length")
  10. displace = input.float(0.0, "displace")
  11. var float avgtriangular = 0
  12. float __el_plot1 = na
  13. color __el_plot1_color = color.blue
  14. __el_call1 = __el_triangular_average(price, int(length))
  15. if bar_index >= 8
  16. avgtriangular := __el_call1
  17. if displace >= 0 or bar_index + 1 > math.abs(displace)
  18. __el_plot1 := avgtriangular
  19. if true and displace <= 0
  20. if price > avgtriangular and avgtriangular > avgtriangular[1] and avgtriangular[1] <= avgtriangular[2]
  21. alert("Indicator turning up", alert.freq_once_per_bar)
  22. else
  23. if price < avgtriangular and avgtriangular < avgtriangular[1] and avgtriangular[1] >= avgtriangular[2]
  24. alert("Indicator turning down", alert.freq_once_per_bar)
  25. plot(__el_plot1, title="AvgTri", color=__el_plot1_color, offset=int(displace))

Compiled MetaTrader 5 example

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

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