Advertisement
Maurizio-Ciullo

Bot 1H FIRSTBAR V.2.01

Jun 23rd, 2023
1,130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // ©tumiza999
  3.  
  4.  
  5. // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //
  6.  
  7. // Startegia di Tumiza999 Gruppo PineCoders Telegram //
  8.  
  9. //Strategy che prende in considerazione il canale creato dalla candela della prima ora inizio sessione giornaliera, quindi High Open  e Low.
  10. //Strategy Entry sono 3 High - Open - Low
  11.  
  12. //Strategy Mode sono 3
  13. //Classica: SL - TP
  14. //CrossEMA: SL su ema TP da impostzione
  15. //Trailing-Stop: no comment
  16.  
  17. //Tips:
  18. //Gap se vuoi anticipare o posticipare entry
  19.  
  20. // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //
  21.  
  22.  
  23. //@version=5
  24. strategy("Bot 1H FIRSTBAR V.2.01", overlay=true, pyramiding = 1, slippage = 1,
  25.          initial_capital=10000,
  26.          default_qty_type=strategy.percent_of_equity, default_qty_value=10,
  27.          commission_type=strategy.commission.percent, commission_value=0.0750, use_bar_magnifier = false)
  28.  
  29. // -----------------------------------------------------------------------------
  30. // Trigger Point
  31. // -----------------------------------------------------------------------------
  32.  
  33. open_1H = request.security(syminfo.tickerid, "60", open)
  34. high_1H = request.security(syminfo.tickerid, "60", high)
  35. low_1H= request.security(syminfo.tickerid, "60", low)
  36.  
  37. SessionHigh(sessionTime, sessionTimeZone=syminfo.timezone) =>
  38.     insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
  39.     var float sessionHighPrice = na
  40.  
  41.     if insideSession and not insideSession[1]
  42.         sessionHighPrice := high
  43.     else if insideSession
  44.         sessionHighPrice := high_1H
  45.    
  46.     sessionHighPrice
  47.  
  48. SessionLow(sessionTime, sessionTimeZone=syminfo.timezone) =>
  49.     insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
  50.     var float sessionLowPrice = na
  51.  
  52.     if insideSession and not insideSession[1]
  53.         sessionLowPrice := low
  54.     else if insideSession
  55.         sessionLowPrice := low_1H
  56.    
  57.     sessionLowPrice
  58.  
  59. SessionOpen(sessionTime, sessionTimeZone=syminfo.timezone) =>
  60.     insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
  61.     var float sessionOpenPrice = na
  62.  
  63.     if insideSession and not insideSession[1]
  64.         sessionOpenPrice := open
  65.     else if insideSession
  66.         sessionOpenPrice := open_1H
  67.    
  68.     sessionOpenPrice
  69.  
  70. InSession(sessionTimes, sessionTimeZone=syminfo.timezone) =>
  71.     not na(time(timeframe.period, sessionTimes, sessionTimeZone))
  72.  
  73. session  = input.session("0000-0100", title="Data Session")
  74. timeZone = input.string("GMT", title="Time Zone")
  75.  
  76. sessHigh = SessionHigh(session, timeZone)
  77. sessLow= SessionLow(session, timeZone)
  78. sessOpen= SessionOpen(session, timeZone)
  79.  
  80. plot(sessHigh, color=color.rgb(92, 217, 255), title="Session High")
  81. plot(sessOpen, color=color.rgb(255, 244, 92), title="Session Open")
  82. plot(sessLow, color=color.rgb(255, 117, 244), title="Session Low")
  83. bgcolor(InSession(session, timeZone) ? color.new(#00ffdd, 95) : na)
  84.  
  85. if ta.crossover(close,sessHigh)
  86.     alert(message = "High First Hour Crossover", freq = alert.freq_once_per_bar)
  87.    
  88.  
  89. if ta.crossunder(close, sessOpen)
  90.     alert(message = "Open First Hour Crossunder", freq = alert.freq_once_per_bar)
  91.  
  92. if ta.crossunder(close,sessLow)
  93.     alert(message = "Low First Hour Crossunder", freq = alert.freq_once_per_bar)
  94.  
  95. if ta.crossover(close, sessLow)
  96.     alert(message = "Low First Hour Crossover", freq = alert.freq_once_per_bar)
  97.  
  98. plotshape(ta.crossover(close, sessHigh), "CrossOvHIGH", shape.triangleup, location = location.belowbar, color=color.yellow)
  99. plotshape(ta.crossover(close, sessOpen), "CrossOvOPEN",shape.triangleup, location = location.belowbar, color= color.red)
  100. plotshape(ta.crossover(close, sessLow), "CrossoOvLOW",shape.triangleup, location = location.belowbar, color = color.green)
  101. //plotshape(ta.crossunder(close, sessHigh), "CrossovHigh",shape.triangleup, location = location.belowbar)
  102. //plotshape(ta.crossunder(close, sessHigh), "CrossovHigh",shape.triangleup, location = location.belowbar)
  103. //plotshape(ta.crossunder(close, sessHigh), "CrossovHigh",shape.triangleup, location = location.belowbar)
  104.  
  105. //---Entry Exit Close
  106. //Entry = input.float(str.tostring(sessHigh), "Engage Price", options = [sessLow, sessOpen, sessHigh])
  107.  
  108. //---INPUT DATA STOP-LOSS TAKE PROFIT
  109. strategy_on = input.bool(false, "Strategy On")
  110. strategy_engage = input.string("sessHigh", "Strategy Type", options = ["sessHigh","sessOpen", "sessLow"])
  111. Gap = input.float(1,"Gap%", step=0.5, tooltip="Gap di entrata su entry_price -n anticipa entrata, con +n posticipa entrata", group = "Entry")
  112. //Gap2 = (Entry * Gap)/100
  113. sl  = input.float(3, "Stop-loss", step= 0.5,  group = "Entry")
  114. tp  = input.float(9, "Take-profit", step= 0.5, group = "Entry")
  115. //entry_source = input.string(sessHigh, "Entry Engage", options = [sessHigh, sessLow,sessOpen])
  116. stop_loss_price = strategy.position_avg_price * (1-sl/100)
  117. take_price = strategy.position_avg_price * (1+tp/100)
  118.  
  119. //---INPUT DATA TRAILING STOP
  120. 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")
  121. Atrl= input.float(1, "Offset Trailing", step=0.5,tooltip = "Distanza dal prezzo", group = "Trailing Stop Settings")
  122. stop_trl_price_cond = sl_trl * high/syminfo.mintick/100
  123. stop_trl_price_offset_cond = Atrl * high/syminfo.mintick/100
  124.  
  125. stop_tick = sl * high/syminfo.mintick/100
  126. profit_tick = tp * high/syminfo.mintick/100
  127.  
  128. //var Pair_BotD= syminfo.currency + syminfo.basecurrency
  129. //mess_buy_discord = !buy + rre
  130. //mess_sell = !sell +
  131. //3comma-3commass alert
  132. //var Pair_3c = syminfo.currency + "_" + syminfo.basecurrency
  133. //mess_buy_3c = '{  "message_type": "bot",  "bot_id": 10913385,  "email_token": "b0792bf7-9ddc-4a83-85f5-b71478070846",  "delay_seconds": 0,  "pair": "'+ Pair_3c +'"}'
  134. //mess_sell_3c = '{  "action": "close_at_market_price", "message_type": "bot",   "bot_id": 10913385, "email_token": "b0792bf7-9ddc-4a83-85f5-b71478070846","delay_seconds": 6,"pair": "'+ Pair_3c +'"}'
  135. var Pair_BotD= syminfo.basecurrency+syminfo.currency
  136. //mess_buy ="!market_p "+str.tostring(tp)+" "+str.tostring(sl)+" "+syminfo.basecurrency+syminfo.currency
  137. mess_buy_h= "!stop_limit_p "+str.tostring(sessHigh)+" "+str.tostring(tp)+" "+str.tostring(sl)+" "+Pair_BotD
  138. mess_buy_o= "!stop_limit_p "+str.tostring(sessOpen)+" "+str.tostring(tp)+" "+str.tostring(sl)+" "+Pair_BotD
  139. mess_buy_l= "!stop_limit_p "+str.tostring(sessLow)+" "+str.tostring(tp)+" "+str.tostring(sl)+" "+Pair_BotD
  140. //mess_sell = !sell + syminfo.basecurrency+syminfo.currency
  141.  
  142. // -----------------------------------------------------------------------------
  143. // ENTRY - EXIT - CLOSE - CONDITION
  144. // -----------------------------------------------------------------------------
  145. //Filter and condition
  146. //INPUT FILTER
  147. Filter_Atr_bool = input.bool(false, "Volatility Filter", group = "Filter Settings")
  148. Filter_atr_low = input.int(2, "Atr Low Lenght", minval = 1, step = 1, group = "Filter Settings")
  149. Filter_atr_high = input.int(14, "Atr High Lenght", minval = 1, step = 1, group = "Filter Settings")
  150. //Filter_emaD = input.bool(false, "Ema Daily Filter", group = "Filter Settings")
  151. //Filter_Btc = input.bool(false, "BTC Trend Filter", group = "Filter Settings")
  152. //Filter_Fomocandle= input.bool(false, "Fomo Daily Filter", group = "Filter Settings")
  153.  
  154.  
  155. //----CONDITION ENGAGE
  156. Filter_Atr = ta.atr(Filter_atr_low) <= ta.atr(Filter_atr_high)
  157. //cond_long=  ta.crossover(close, ta.ema(close, 60)) // and ta.crossover(close, ta.ema(close, 223))
  158. //cond_long2= ta.crossover((request.security("BINANCE:BTCUSDT", "60", close)), ta.ema(request.security("BINANCE:BTCUSDT","60",close), 10))
  159. //cond_long = request.security(syminfo.tickerid,"D",high[1]-low[1]) >= request.security(syminfo.tickerid,"D",high[2]-low[2])
  160. //When_entry = hour > 01
  161. //cond_BTC = ta.crossover(request.security('BINANCE:BTCUSDT', "60", close), ta.ema(request.security('BINANCE:BTCUSDT', "60", close), 60))
  162. cond_long = request.security(syminfo.tickerid,"D",high[1]-low[1]) <= request.security(syminfo.tickerid,"D",high[2]-low[2])
  163. //cond_long = close >= ta.ema(request.security(syminfo.tickerid, "60", close), 10)
  164. //cond_long = true
  165. price =request.security(syminfo.tickerid, "10", close)
  166.  
  167.  
  168. //------IF STRATEGY ENTRY CLOSE TRAILING
  169. //activation strategy settings
  170. ts_n  = input.bool(true, "Trailing-stop", tooltip = "Attiva o disattiva trailing-stop", group = "Trailing Stop Settings")
  171. close_ema = input.bool(false, "Close EMA", tooltip = "Attiva o disattiva chiusura su EMA", group = "Trailing Stop Settings")
  172. len1 = input.int(10, "EMA length", step=1, group = "Trailing Stop Settings")
  173. ma1 = ta.ema(request.security(syminfo.tickerid, "60", close), len1)
  174. plot(ma1, title='EMA', color=color.new(color.yellow, 0))
  175.  
  176. //---Entry engage
  177. entry_h = sessHigh + (sessHigh * Gap)/100
  178. entry_o = sessOpen + (sessOpen * Gap)/100
  179. entry_l = sessLow + (sessLow * Gap)/100
  180.  
  181. //--------Strategy On
  182. if strategy_on == true and strategy_engage == "sessHigh"
  183.  
  184.     if ta.crossover(price, sessLow) and cond_long and Filter_Atr or ta.crossover(price, sessOpen) and cond_long and Filter_Atr
  185.         strategy.entry("Entry", strategy.long, stop = entry_h) // alert_message = mess_buy_h)
  186.  
  187.  
  188.     //fomo candle
  189.     if ts_n == true and close_ema == false
  190.         //alert(mess_sell_3c, alert.freq_once_per_bar)
  191.         strategy.exit("Entry", loss= stop_tick, stop= stop_loss_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_profit= mess_sell_3c, alert_loss = mess_sell_3c, alert_trailing = mess_sell_3c)
  192.    
  193.     else if ts_n == false and close_ema == false
  194.         //alert(mess_sell_3c, alert.freq_once_per_bar)
  195.         strategy.exit("Entry", loss= stop_tick, stop=stop_loss_price, limit= take_price, comment_loss= "Stop-loss!!!", comment_profit = "CASH!!") //alert_profit= mess_sell_3c, alert_loss = mess_sell_3c, alert_trailing = mess_sell_3c)
  196.  
  197.     if close_ema == true and ta.crossunder(open,ma1) and ts_n == false
  198.         //alert(mess_sell_3c, alert.freq_once_per_bar)
  199.         strategy.close("Entry", comment = "Close EMA ") //alert_message = mess_sell_3c)
  200.  
  201.  
  202. if strategy_on == true and strategy_engage == "sessOpen"
  203.  
  204.     if ta.crossover(price, sessLow) and cond_long and Filter_Atr or ta.crossover(price, sessOpen) and cond_long and Filter_Atr
  205.         strategy.entry("Entry Open", strategy.long, stop = entry_o) // alert_message = mess_buy_3c)
  206.  
  207.  
  208.     //fomo candle
  209.     if ts_n == true and close_ema == false
  210.         //alert(mess_sell_3c, alert.freq_once_per_bar)
  211.         strategy.exit("Entry Open", loss= stop_tick, stop= stop_loss_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_profit= mess_sell_3c, alert_loss = mess_sell_3c, alert_trailing = mess_sell_3c)
  212.    
  213.     else if ts_n == false and close_ema == false
  214.         //alert(mess_sell_3c, alert.freq_once_per_bar)
  215.         strategy.exit("Entry Open", loss= stop_tick, stop=stop_loss_price, limit= take_price, comment_loss= "Stop-loss!!!", comment_profit = "CASH!!") //alert_profit= mess_sell_3c, alert_loss = mess_sell_3c, alert_trailing = mess_sell_3c)
  216.  
  217.     if close_ema == true and ta.crossunder(open,ma1) and ts_n == false
  218.         //alert(mess_sell_3c, alert.freq_once_per_bar)
  219.         strategy.close("Entry Open", comment = "Close EMA ") //alert_message = mess_sell_3c)
  220.  
  221.  
  222. if strategy_on == true and strategy_engage == "sessLow"
  223.  
  224.     if ta.crossover(price, sessLow) and cond_long and Filter_Atr or ta.crossover(price, sessOpen) and cond_long and Filter_Atr
  225.         strategy.entry("Entry Low", strategy.long, stop = entry_l)
  226.  
  227.  
  228.     //fomo candle
  229.     if ts_n == true and close_ema == false
  230.         //alert(mess_sell_3c, alert.freq_once_per_bar)
  231.         strategy.exit("Entry Low", loss= stop_tick, stop= stop_loss_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_profit= mess_sell_3c, alert_loss = mess_sell_3c, alert_trailing = mess_sell_3c)
  232.    
  233.     else if ts_n == false and close_ema == false
  234.         //alert(mess_sell_3c, alert.freq_once_per_bar)
  235.         strategy.exit("Entry Low", loss= stop_tick, stop=stop_loss_price, limit= take_price, comment_loss= "Stop-loss!!!", comment_profit = "CASH!!")
  236.  
  237.     if close_ema == true and ta.crossunder(open,ma1) and ts_n == false
  238.         //alert(mess_sell_3c, alert.freq_once_per_bar)
  239.         strategy.close("Entry Low", comment = "Close EMA ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement