Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. //@version=4
  2. strategy(title = "Robot WhiteBox Channel", shorttitle = "Robot WhiteBox Channel", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0, commission_value = 0.1)
  3.  
  4. //Settings
  5. needlong = input(true, defval = true, title = "Long")
  6. needshort = input(true, defval = true, title = "Short")
  7. needstop = input(true, defval = true, title = "Stop-loss")
  8. //CandleClose = input(true, "Trade on candle close?")
  9. lotsize = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot, %")
  10. len = input(50, minval = 1, title = "Price Channel Length")
  11. showll = input(true, defval = true, title = "Show lines")
  12. showbg = input(false, defval = false, title = "Show Background")
  13. fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
  14. toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
  15. frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
  16. tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
  17. fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
  18. today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")
  19.  
  20. //Price Channel
  21. h = highest(high, len)
  22. l = lowest(low, len)
  23. center = (h + l) / 2
  24.  
  25. //Lines
  26. pccol = showll ? color.black : na
  27. slcol = showll ? color.red : na
  28. plot(h, offset = 1, color = pccol)
  29. plot(center, offset = 1, color = slcol)
  30. plot(l, offset = 1, color = pccol)
  31.  
  32. //Background
  33. size = strategy.position_size
  34. bgcol = showbg == false ? na : size > 0 ? color.lime : size < 0 ? color.red : na
  35. bgcolor(bgcol, transp = 70)
  36.  
  37. //Trading
  38. truetime = time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)
  39. lot = 0.0
  40. lot := size != size[1] ? strategy.equity / close * lotsize / 100 : lot[1]
  41. if h > 0
  42. strategy.entry("Long", strategy.long, lot, stop = h, when = strategy.position_size <= 0 and needlong and truetime)
  43. strategy.entry("Short", strategy.short, lot, stop = l, when = strategy.position_size >= 0 and needshort and truetime)
  44. if strategy.position_size > 0 and needstop
  45. strategy.exit("Stop Long", "Long", stop = center)
  46. if strategy.position_size > 0 and needstop == false and needshort == false
  47. strategy.exit("Stop Long", "Long", stop = l)
  48. if strategy.position_size < 0 and needstop
  49. strategy.exit("Stop Short", "Short", stop = center)
  50. if strategy.position_size < 0 and needstop == false and needlong == false
  51. strategy.exit("Stop Short", "Short", stop = h)
  52. if time > timestamp(toyear, tomonth, today, 23, 59)
  53. strategy.close_all()
  54. strategy.cancel("Long")
  55. strategy.cancel("Short")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement