Advertisement
Maurizio-Ciullo

Indicatore Strategia Grezza Break Out

Feb 13th, 2023
751
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. // © Maurizio-Ciullo
  3.  
  4. // breakMaxMinIntraD = (High0/Low0 Maggiore/Minore HighD0/LowD0 Session)                                    
  5. // breakMaxMinClose = (Close Maggiore/Minore HighD1/LowD1)
  6.      
  7.  
  8. //@version=5
  9. strategy("Indicatore Strategia Grezza Break Out", overlay=true,
  10.      pyramiding=0,
  11.      initial_capital=100,
  12.      commission_type=strategy.commission.cash_per_contract,
  13.      commission_value=0.0,
  14.      slippage=0,
  15.      default_qty_type=strategy.fixed,
  16.      default_qty_value=100)
  17.  
  18.  
  19. //inputs
  20. on_off_breakMaxMinIntraD = input.bool(title='Break Max Min IntraD Activate', defval=true, inline='1', group='Test Selection', tooltip="Testa Break Max Min Intra-Day")
  21. in_solo_long_breakMaxMinIntraD = input.bool(title='Solo Long Break Max Min IntraD', defval=false, inline='1', group='Direzione Break Max Min IntraD')
  22. in_solo_short_breakMaxMinIntraD = input.bool(title='Solo Short Break Max Min IntraD', defval=false, inline='1', group='Direzione Break Max Min IntraD')
  23.  
  24.  
  25. on_off_breakMaxMinClose = input.bool(title='Break Max Min Close Activate', defval=false, inline='1', group='Test Selection', tooltip="Testa Break Max Min Close")
  26. in_solo_long_breakMaxMinClose = input.bool(title='Solo Long Break Max Min Close', defval=false, inline='1', group='Direzione Break Max Min Close')
  27. in_solo_short_breakMaxMinClose = input.bool(title='Solo Short Break Max Min Close', defval=false, inline='1', group='Direzione Break Max Min Close')
  28.  
  29.  
  30. // Calcolo del range del backtest
  31. startDate = input.int(title="Start Date",
  32.      defval=17, minval=1, maxval=31, group="Periodo")
  33. startMonth = input.int(title="Start Month",
  34.      defval=08, minval=1, maxval=12, group="Periodo")
  35. startYear = input.int(title="Start Year",
  36.      defval=2000, minval=1800, maxval=2100, group="Periodo")
  37.  
  38. endDate = input.int(title="End Date",
  39.      defval=01, minval=1, maxval=31, group="Periodo")
  40. endMonth = input.int(title="End Month",
  41.      defval=01, minval=1, maxval=12, group="Periodo")
  42. endYear = input.int(title="End Year",
  43.      defval=2121, minval=1800, maxval=2150, group="Periodo")
  44.  
  45.  
  46. inDateRange = (time >= timestamp(syminfo.timezone, startYear,
  47.          startMonth, startDate, 0, 0)) and
  48.      (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
  49.      
  50.      
  51. // Start Hour Range Trading Non Attivo /////////////////////
  52. //hourTrading = input(title='sessione valida di trading', defval='0600-2300:23456')
  53. //hourRangeTrading = time(timeframe.period, hourTrading)    
  54.      
  55.      
  56. ///////////////////  Start Detecting High0 Session  ///////////////////
  57.  
  58. // Configure session with inputs
  59. session_high  = input.session("0000-0100", title="Trading Session")
  60. timeZone_high = input.string("GMT+2", title="Time Zone")
  61.  
  62. // SessionHigh() returns the highest price during the specified
  63. // session, optionally corrected for the given time zone.
  64. // Returns 'na' when the session hasn't started or isn't on the chart.
  65. SessionHigh(sessionTime, sessionTimeZone=syminfo.timezone) =>
  66.     insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
  67.     var float sessionHighPrice = na
  68.  
  69.     if insideSession and not insideSession[1]
  70.         sessionHighPrice := high
  71.     else if not insideSession and high > sessionHighPrice // Inserito personalmente perchè se fuori sessione e massimo più alto non aggiornava
  72.         sessionHighPrice := high // // Inserito personalmente perchè se fuori sessione e massimo più alto non aggiornava
  73.     else if insideSession
  74.         sessionHighPrice := math.max(sessionHighPrice, high)
  75.    
  76.     sessionHighPrice
  77.  
  78. // InSession() returns 'true' when the current bar happens inside
  79. // the specified session, corrected for the given time zone (optional).
  80. // Returns 'false' when the bar doesn't happen in that time period,
  81. // or when the chart's time frame is 1 day or higher.
  82. InSessionHigh(sessionTimes, sessionTimeZone=syminfo.timezone) =>
  83.     not na(time(timeframe.period, sessionTimes, sessionTimeZone))
  84.  
  85. // Get the session high
  86. highd0 = SessionHigh(session_high, timeZone_high)
  87.  
  88. // Show the session high on the chart
  89. //plot(highd0, color=color.green, title="Highd0")
  90.  
  91. // For visual verification, highlight the background of session bars
  92. bgcolor(InSessionHigh(session_high, timeZone_high) ? color.new(color.orange, 90) : na)
  93.  
  94. // ///////////////////  End Detecting High0 Session  ///////////////////
  95.  
  96.  
  97. // ///////////////////  Start Detecting Low0 Session  ///////////////////
  98.  
  99. // Configure session with inputs
  100. session_low  = input.session("0000-0100", title="Trading Session")                                  
  101. timeZone_low = input.string("GMT+2", title="Time Zone")
  102.  
  103. // SessionLow() returns the lowest price during the specified
  104. // session, optionally corrected for the given time zone.
  105. // Returns 'na' when the session hasn't started or isn't on the chart.
  106. SessionLow(sessionTime, sessionTimeZone=syminfo.timezone) =>                                      
  107.     insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
  108.     var float sessionLowPrice = na
  109.  
  110.     if insideSession and not insideSession[1]
  111.         sessionLowPrice := low
  112.     else if not insideSession and low < sessionLowPrice // Inserito personalmente perchè se fuori sessione e minimo più basso non aggiornava
  113.         sessionLowPrice := low // // Inserito personalmente perchè se fuori sessione e minimo più basso non aggiornava
  114.     else if insideSession
  115.         sessionLowPrice := math.min(sessionLowPrice, low)
  116.    
  117.     sessionLowPrice
  118.  
  119. // InSession() returns 'true' when the current bar happens inside
  120. // the specified session, corrected for the given time zone (optional).
  121. // Returns 'false' when the bar doesn't happen in that time period,
  122. // or when the chart's time frame is 1 day or higher.
  123. InSessionLow(sessionTimes, sessionTimeZone=syminfo.timezone) =>
  124.     not na(time(timeframe.period, sessionTimes, sessionTimeZone))
  125.  
  126. // Get the session low
  127. lowd0 = SessionLow(session_low, timeZone_low)
  128.  
  129. // Show the session low on the chart
  130. //plot(lowd0, color=color.red, title="Lowd0")
  131.  
  132. // For visual verification, lowest the background of session bars
  133. //bgcolor(InSessionLow(session_low, timeZone_low) ? color.new(color.orange, 90) : na)
  134.  
  135. // ///////////////////  End Detecting Low0 Session  ///////////////////
  136.  
  137.  
  138. ///////////////////  Start Detecting HighD1 Session  ///////////////////
  139.  
  140. highd1 = request.security(syminfo.tickerid, "D", high[1], lookahead = barmerge.lookahead_on)
  141. plot(highd1, title="highd1")
  142.  
  143. // ///////////////////  End Detecting HighD1 Session  ///////////////////
  144.  
  145.  
  146. ///////////////////  Start Detecting LowD1 Session  ///////////////////
  147.      
  148. lowd1 = request.security(syminfo.tickerid, "D", low[1], lookahead = barmerge.lookahead_on)
  149. plot(lowd1, title="lowd1")    
  150.      
  151.  ///////////////////  End Detecting LowD1 Session  ///////////////////  
  152.  
  153.                                            
  154. //-----------------------------------------------------------------------------------------------------------------------------------------------------//
  155.                                                // Inizio Test Break Max Min Intra Day //
  156. //-----------------------------------------------------------------------------------------------------------------------------------------------------//                                              
  157.  
  158. // Long e Short Break Max Min Intra Day
  159. if in_solo_long_breakMaxMinIntraD == false and  in_solo_short_breakMaxMinIntraD == false and on_off_breakMaxMinIntraD and inDateRange
  160.     strategy.entry('operazioneLong', strategy.long, stop=highd0, alert_message = "Open Long Position")
  161.     strategy.entry('operazioneShort', strategy.short, stop=lowd0, alert_message = "Open Long Position")
  162.  
  163.  
  164. // Solo Long Break Max Min Intra Day
  165. if in_solo_long_breakMaxMinIntraD == true and in_solo_short_breakMaxMinIntraD == false and on_off_breakMaxMinIntraD and inDateRange
  166.     strategy.entry('operazioneLong', strategy.long, stop=highd0, alert_message = "Open Long Position")
  167.     strategy.exit('SL e TP', from_entry='operazioneLong', stop=lowd0, alert_message = "Your Long SL-TP Has Been Triggered.")
  168.  
  169.  
  170. // Solo Short Break Max Min Intra Day
  171. if in_solo_short_breakMaxMinIntraD == true and in_solo_long_breakMaxMinIntraD == false and on_off_breakMaxMinIntraD and inDateRange
  172.     strategy.entry('operazioneShort', strategy.short, stop=lowd0, alert_message = "Open Short Position")
  173.     strategy.exit('SL e TP', from_entry='operazioneShort', stop=highd0, alert_message = "Your Short SL-TP Has Been Triggered.")  
  174.  
  175.  
  176. //-----------------------------------------------------------------------------------------------------------------------------------------------------//                                    
  177.                                               // Inizio Test Break Max Min Close //
  178. //-----------------------------------------------------------------------------------------------------------------------------------------------------//
  179.  
  180. // Long E Short Insieme Break Max Min Close                              
  181. if in_solo_long_breakMaxMinClose == false and in_solo_short_breakMaxMinClose == false and on_off_breakMaxMinClose and inDateRange
  182.     if close > highd1
  183.         strategy.entry('operazioneLong', strategy.long, alert_message = "Open Long Position")
  184.     if close < lowd1
  185.         strategy.entry('operazioneShort', strategy.short, alert_message = "Open Short Position")    
  186.  
  187.  
  188. // Solo Long Break Max Min Close
  189. if in_solo_long_breakMaxMinClose == true and in_solo_short_breakMaxMinClose == false and on_off_breakMaxMinClose and inDateRange
  190.     if close > highd1
  191.         strategy.entry('operazioneLong', strategy.long, alert_message = "Open Long Position")
  192.     if close < lowd1
  193.         strategy.close('operazioneLong', alert_message = "Your Long SL-TP Has Been Triggered.")
  194.  
  195.  
  196. // Solo Short Break Max Min Close
  197. if in_solo_short_breakMaxMinClose == true and in_solo_long_breakMaxMinClose == false and on_off_breakMaxMinClose and inDateRange
  198.     if close < lowd1
  199.         strategy.entry('operazioneShort', strategy.short, alert_message = "Open Short Position")
  200.     if close > highd1
  201.         strategy.close('operazioneShort', alert_message = "Your Long SL-TP Has Been Triggered.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement