Advertisement
Maurizio-Ciullo

Bot Yesterday's Breakout

May 18th, 2023
1,140
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This source code is subject to the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
  2. // © TheSocialCryptoClub
  3.  
  4. //@version=5
  5.  
  6. strategy("Bot Yesterday's Breakout Yesterday's High", overlay=true, pyramiding = 1,
  7.          initial_capital=10000,
  8.          default_qty_type=strategy.percent_of_equity, default_qty_value=10,
  9.          slippage=1, backtest_fill_limits_assumption=1, use_bar_magnifier=true,
  10.          commission_type=strategy.commission.percent, commission_value=0.075
  11.          )
  12.  
  13. // -----------------------------------------------------------------------------
  14. // ROC Filter
  15. // -----------------------------------------------------------------------------
  16.  
  17. // f_security function by LucF for PineCoders available here: https://www.tradingview.com/script/cyPWY96u-How-to-avoid-repainting-when-using-security-PineCoders-FAQ/
  18. f_security(_sym, _res, _src, _rep) => request.security(_sym, _res, _src[not _rep and barstate.isrealtime ? 1 : 0])[_rep or barstate.isrealtime ? 0 : 1]
  19. high_daily = f_security(syminfo.tickerid, "D", high, false)
  20.  
  21. roc_enable = input.bool(false, "", group="ROC Filter from CloseD", inline="roc")
  22. roc_threshold = input.float(1, "Treshold", step=0.5, group="ROC Filter from CloseD", inline="roc")
  23.  
  24. closed = f_security(syminfo.tickerid,"1D",close, false)
  25. roc_filter= roc_enable ? (close-closed)/closed*100  > roc_threshold  : true
  26.  
  27.  
  28. // -----------------------------------------------------------------------------
  29. // Trigger Point
  30. // -----------------------------------------------------------------------------
  31.  
  32. open_session = ta.change(time('D'))
  33. price_session = ta.valuewhen(open_session, open, 0)
  34. tf_session = timeframe.multiplier <= 60
  35.  
  36. bgcolor(open_session and tf_session ?color.new(color.blue,80):na, title = "Session")
  37.  
  38. first_bar = 0
  39. if open_session
  40.     first_bar := bar_index
  41.  
  42. var max_today = 0.0
  43. var min_today = 0.0
  44. var high_daily1 = 0.0
  45. var low_daily1 = 0.0
  46. var today_open = 0.0
  47.  
  48. if first_bar
  49.     high_daily1 := max_today
  50.     low_daily1 := min_today
  51.     today_open := open
  52.     max_today := high
  53.     min_today := low
  54.  
  55.  
  56. if high >= max_today
  57.     max_today := high
  58.  
  59. if low < min_today
  60.     min_today := low
  61.  
  62.  
  63. same_day  = today_open == today_open[1]
  64.  
  65. plot( timeframe.multiplier <= 240 and same_day ? high_daily1 : na, color= color.yellow , style=plot.style_linebr, linewidth=1, title='High line')
  66. plot( timeframe.multiplier <= 240 and same_day ? low_daily1 : na, color= #E8000D , style=plot.style_linebr, linewidth=1, title='Low line')
  67.  
  68. // -----------------------------------------------------------------------------
  69. // Strategy settings
  70. // -----------------------------------------------------------------------------
  71.  
  72. Gap = input.float(1,"Gap%", step=0.5, tooltip="Gap di entrata su entry_price -n anticipa entrata, con +n posticipa entrata", group = "Entry")
  73. Gap2 = (high_daily1 * Gap)/100
  74.  
  75. sl  = input.float(3, "Stop-loss", step= 0.5,  group = "Entry")
  76. tp  = input.float(9, "Take-profit", step= 0.5, group = "Entry")
  77. stop_loss_price = strategy.position_avg_price * (1-sl/100)
  78. take_price = strategy.position_avg_price * (1+tp/100)
  79.  
  80. sl_trl = input.float(2, "Trailing-stop", step = 0.5, tooltip = "Attiva trailing stop dopo che ha raggiunto...",group = "Trailing Stop Settings")//group = "Trailing Stop Settings")
  81. Atrl= input.float(1, "Offset Trailing", step=0.5,tooltip = "Distanza dal prezzo", group = "Trailing Stop Settings")
  82. stop_trl_price_cond = sl_trl * high/syminfo.mintick/100
  83. stop_trl_price_offset_cond = Atrl * high/syminfo.mintick/100
  84.  
  85. stop_tick = sl * high/syminfo.mintick/100
  86. profit_tick = tp * high/syminfo.mintick/100
  87.  
  88. mess_buy = "buy"
  89. mess_sell = "sell"
  90.  
  91. // -----------------------------------------------------------------------------
  92. // Entry - Exit - Close
  93. // -----------------------------------------------------------------------------
  94.  
  95. if close < high_daily1 and roc_filter
  96.     strategy.entry("Entry", strategy.long, stop = high_daily1 + (Gap2), alert_message = mess_buy)
  97.  
  98. ts_n  = input.bool(true, "Trailing-stop", tooltip = "Attiva o disattiva trailing-stop", group = "Trailing Stop Settings")
  99. close_ema = input.bool(false, "Close EMA", tooltip = "Attiva o disattiva chiusura su EMA", group = "Trailing Stop Settings")
  100. len1 = input.int(10, "EMA length", step=1, group = "Trailing Stop Settings")
  101. ma1 = ta.ema(close, len1)
  102.  
  103. plot(ma1, title='EMA', color=color.new(color.yellow, 0))
  104.  
  105. if ts_n == true
  106.     strategy.exit("Trailing-Stop","Entry",loss= stop_tick, stop= stop_loss_price, limit= take_price, trail_points = stop_trl_price_cond, trail_offset = stop_trl_price_offset_cond, comment_loss="Stop-Loss!!",comment_profit ="CASH!!", comment_trailing = "TRL-Stop!!", alert_message = mess_sell)
  107. else
  108.     strategy.exit("TP-SL", "Entry",loss= stop_tick, stop=stop_loss_price, limit= take_price, comment_loss= "Stop-loss!!!", comment_profit = "CASH!!", alert_message = mess_sell)
  109.  
  110. if close_ema == true and ta.crossunder(close,ma1)
  111.     strategy.close("Entry",comment = "Close" , alert_message = mess_sell)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement