Advertisement
Guest User

Untitled

a guest
Aug 1st, 2019
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. //@version=4
  2. // this is based on https://www.tradingview.com/v/PbQW4mRn/
  3. //strategy(title = "ONLY LONG V4 v1", overlay = true, initial_capital = 1000, pyramiding = 1000,
  4. //calc_on_order_fills = false, calc_on_every_tick = false, default_qty_type = strategy.percent_of_equity, default_qty_value = 50, commission_value = 0.075)
  5.  
  6. study(title = "ONLY LONG V4 v1", overlay = true)
  7.  
  8. //Fast RSI
  9. src = close
  10. fastup = rma(max(change(src), 0), 3)
  11. fastdown = rma(-min(change(src), 0), 3)
  12. fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))
  13.  
  14. //Body Filter
  15. body = abs(close - open)
  16. abody = sma(body, 20)
  17.  
  18. mac = sma(close, 20)
  19. len = abs(close - mac)
  20. sma = sma(len, 100)
  21. max = max(open, close)
  22. min = min(open, close)
  23. up = close < open and len > sma * 2 and min < min[1] and fastrsi < 10 and body > abody * 2.5
  24.  
  25. // Strategy
  26. // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  27.  
  28. var bool longCondition = na
  29.  
  30. longCondition := up == 1 ? 1 : na
  31.  
  32. // Get the price of the last opened long
  33.  
  34. var float last_open_longCondition = na
  35.  
  36. last_open_longCondition := longCondition ? close : nz(last_open_longCondition[1])
  37.  
  38. // Get the bar time of the last opened long
  39.  
  40. var int last_longCondition = 0
  41.  
  42. last_longCondition := longCondition ? time : nz(last_longCondition[1])
  43.  
  44. // Take profit
  45. // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  46.  
  47. tp = input(20, "TAKE PROFIT %", type = input.float, minval = 0, step = 0.5)
  48.  
  49. long_tp = crossover(high, (1+(tp/100))*last_open_longCondition) and not longCondition
  50.  
  51. // Get the time of the last tp close
  52.  
  53. var int last_long_tp = na
  54.  
  55. last_long_tp := long_tp ? time : nz(last_long_tp[1])
  56.  
  57. Final_Long_tp = long_tp and last_longCondition > nz(last_long_tp[1])
  58.  
  59. // Count your long conditions
  60.  
  61. var int sectionLongs = 0
  62.  
  63. sectionLongs := nz(sectionLongs[1])
  64.  
  65. var int sectionTPs = 0
  66.  
  67. sectionTPs := nz(sectionTPs[1])
  68.  
  69. // Longs Counter
  70.  
  71. if longCondition
  72. sectionLongs := sectionLongs + 1
  73. sectionTPs := 0
  74.  
  75. if Final_Long_tp
  76. sectionLongs := 0
  77. sectionTPs := sectionTPs + 1
  78.  
  79. // Signals
  80. // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  81.  
  82. // Long
  83.  
  84. label.new(
  85. x = longCondition[1] ? time : na,
  86. y = na,
  87. text = 'LONG'+tostring(sectionLongs),
  88. color=color.lime,
  89. textcolor=color.black,
  90. style = label.style_labelup,
  91. xloc = xloc.bar_time,
  92. yloc = yloc.belowbar,
  93. size = size.tiny)
  94.  
  95. // Tp
  96.  
  97. label.new(
  98. x = Final_Long_tp ? time : na,
  99. y = na,
  100. text = 'PROFIT '+tostring(tp)+'%',
  101. color=color.orange,
  102. textcolor=color.black,
  103. style = label.style_labeldown,
  104. xloc = xloc.bar_time,
  105. yloc = yloc.abovebar,
  106. size = size.tiny)
  107.  
  108. ltp = iff(Final_Long_tp, (last_open_longCondition*(1+(tp/100))), na), plot(ltp, style=plot.style_cross, linewidth=3, color = color.white, editable = false)
  109.  
  110. // Backtesting
  111. // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  112.  
  113. //testStartYear = input(2019, "BACKTEST START YEAR", minval = 1, maxval = 2222)
  114. //testStartMonth = input(01, "BACKTEST START MONTH", minval = 1, maxval = 12)
  115. //testStartDay = input(01, "BACKTEST START DAY", minval = 1, maxval = 31)
  116. //testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
  117.  
  118. //strategy.entry("long", strategy.long, when = longCondition and (time >= testPeriodStart))
  119. //strategy.exit("TP", "long", limit = (last_open_longCondition*(1+(tp/100))))
  120.  
  121. // Alerts
  122. // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  123.  
  124. alertcondition(longCondition[1], title="Long Alert", message = "LONG")
  125. alertcondition(Final_Long_tp, title="Long TP Alert", message = "LONG TP")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement