Advertisement
warriorofbtc

Untitled

Dec 1st, 2023
54
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. //@version=5
  2. strategy(title="Indicator Test Strategy", shorttitle="ITS", format=format.price, precision=4)
  3.  
  4. useDateFilter = input.bool(true, title="Filter Date Range of Backtest",
  5. group="Backtest Time Period")
  6. backtestStartDate = input.time(timestamp("1 Jan 2018"),
  7. title="Start Date", group="Backtest Time Period",
  8. tooltip="This start date is in the time zone of the exchange " +
  9. "where the chart's instrument trades. It doesn't use the time " +
  10. "zone of the chart or of your computer.")
  11. backtestEndDate = input.time(timestamp("1 Jan 2092"),
  12. title="End Date", group="Backtest Time Period",
  13. tooltip="This end date is in the time zone of the exchange " +
  14. "where the chart's instrument trades. It doesn't use the time " +
  15. "zone of the chart or of your computer.")
  16.  
  17. //Range Conditions
  18. inDateRange = not useDateFilter or (time >= backtestStartDate and
  19. time < backtestEndDate)
  20.  
  21. //_________________________________________________________________________________________________________________
  22. //_________________________________________________________________________________________________________________
  23. //_________________________________________________________________________________________________________________
  24. //_________________________________________________________________________________________________________________
  25. timeframej = input.string("3D", "Days", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "Indicator timeframe")
  26.  
  27. // Inputs
  28. length = input.int(14, title="Length")
  29. volatilityPeriod = input.int(14, title="Volatility Period")
  30. adaptive = input.bool(true, title="Adaptive")
  31.  
  32. // Initialize variables
  33. var float gma = na
  34. var float sumOfWeights = na
  35.  
  36. // Get the standard deviation or use the input value
  37. sigma = adaptive ? ta.stdev(close, volatilityPeriod) : input.float(1.0, title="Fixed StdDev")
  38.  
  39. // Pre-calculate the highest and lowest values
  40. var float[] highestValues = array.new_float(length, na)
  41. var float[] lowestValues = array.new_float(length, na)
  42.  
  43. for i = 0 to length - 1
  44. array.set(highestValues, i, ta.highest(close, i + 1))
  45. array.set(lowestValues, i, ta.lowest(close, i + 1))
  46.  
  47. // Calculate GMA
  48. gma := 0.0
  49. sumOfWeights := 0.0
  50. for i = 0 to length - 1
  51. weight = math.exp(-math.pow((i - (length - 1)) / (2 * sigma), 2) / 2)
  52. value = array.get(highestValues, i) + array.get(lowestValues, i)
  53. gma := gma + (value * weight)
  54. sumOfWeights := sumOfWeights + weight
  55. gma := (gma / sumOfWeights) / 2
  56.  
  57. // Define long and short conditions
  58. Long = close > gma
  59. Short = close < gma
  60.  
  61.  
  62.  
  63. long1 = request.security(syminfo.tickerid,timeframej,Long)
  64. short1 = request.security(syminfo.tickerid,timeframej,Short)
  65.  
  66. var color barColor = na
  67.  
  68. // Determine the bar color based on the conditions
  69. if long1
  70. barColor := color.green
  71. else if short1
  72. barColor := color.red
  73.  
  74. // Apply the bar color
  75. barcolor(barColor)
  76.  
  77. // Strategy Execution
  78. if (long1) and inDateRange
  79. strategy.entry("Long", strategy.long)
  80.  
  81. if (short1) and inDateRange
  82. strategy.entry("Short", strategy.short)
  83.  
  84.  
Advertisement
Comments
  • # text 0.12 KB | 0 0
    1. download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement