Advertisement
Maurizio-Ciullo

17 Creare Filtri Giorn Mens Orari

Dec 27th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -----------------------------------*(Lezione 35 Personale Creare Dei Filtri Giornalieri E Mensili E Orari)*----------------------------------------
  2.  
  3. 1) Creare input buleani true e false per i giorni della settimana e per i mesi dell'anno. Group crea una categoria nelle impostazioni.
  4. 2) Creo 2 variabili 1 long e 1 short e dentro: (trade_long_on_dow_1 and dayofweek == 1) or (trade_long_on_dow_2 and dayofweek == 2)....etc... .
  5.   gli dico che se trade_long_on_dow_1 è true e lo è ... e anche dayofweek == 1 è true sono true tutti e 2 e quindi validi quando li seleziono.
  6. 3) Posso aggiungere dei filtri di sicurezza per chiudere le posizioni aperte se si trovano aperte nel mese che ho scartato.
  7.   Le posizione aperte senza questo filtro if rimarranno aperte finchè il codice non le chiude come prestabilito, quindi potremmo trovare
  8.   delle posizioni aperte a Maggio e chiuse A Giungo anche se Giungo lo abbiamo escluso se non usiamo il filtro if che chiude tutte le posizioni.
  9. 4) Inserisco la variabili con and iniziale dentro le condizioni di entrata sia long che short se previsto.
  10.  
  11. //1)
  12.  
  13. // Include or Exclude Days of the Week
  14. // Trade_long_on_dow_1 is Sunday/Domenica
  15. // Trade_long_on_dow_2 is Monday/Lunedì Etc...
  16. // If a position is opened it will be closed as srategy without excluding the month
  17.  
  18. trade_long_on_dow_1 = input(true, group="Include/Esclude Giorni Long")
  19. trade_long_on_dow_2 = input(true, group="Include/Esclude Giorni Long")
  20. trade_long_on_dow_3 = input(true, group="Include/Esclude Giorni Long")
  21. trade_long_on_dow_4 = input(true, group="Include/Esclude Giorni Long")
  22. trade_long_on_dow_5 = input(true, group="Include/Esclude Giorni Long")
  23. trade_long_on_dow_6 = input(true, group="Include/Esclude Giorni Long")
  24. trade_long_on_dow_7 = input(true, group="Include/Esclude Giorni Long")
  25.  
  26. trade_short_on_dow_1 = input(true, group="Include/Esclude Giorni Short")
  27. trade_short_on_dow_2 = input(true, group="Include/Esclude Giorni Short")
  28. trade_short_on_dow_3 = input(true, group="Include/Esclude Giorni Short")
  29. trade_short_on_dow_4 = input(true, group="Include/Esclude Giorni Short")
  30. trade_short_on_dow_5 = input(true, group="Include/Esclude Giorni Short")
  31. trade_short_on_dow_6 = input(true, group="Include/Esclude Giorni Short")
  32. trade_short_on_dow_7 = input(true, group="Include/Esclude Giorni Short")
  33.  
  34. //2)
  35.  
  36. trade_long_today = (trade_long_on_dow_1 and dayofweek == 1) or (trade_long_on_dow_2 and dayofweek == 2) or (trade_long_on_dow_3 and dayofweek == 3) or (trade_long_on_dow_4 and dayofweek == 4) or (trade_long_on_dow_5 and dayofweek == 5) or (trade_long_on_dow_6 and dayofweek == 6) or (trade_long_on_dow_7 and dayofweek == 7)
  37. trade_short_today = (trade_short_on_dow_1 and dayofweek == 1) or (trade_short_on_dow_2 and dayofweek == 2) or (trade_short_on_dow_3 and dayofweek == 3) or (trade_short_on_dow_4 and dayofweek == 4) or (trade_short_on_dow_5 and dayofweek == 5) or (trade_short_on_dow_6 and dayofweek == 6) or (trade_short_on_dow_7 and dayofweek == 7)
  38.  
  39. //3)
  40.  
  41. // Exit open market position when date range ends
  42.  
  43. //if (not trade_long_today)
  44. //    strategy.close_all()
  45.  
  46. //if (not trade_short_today)
  47. //    strategy.close_all()
  48.  
  49.  
  50. // Include or Exclude Moths of the Year
  51. // Trade_long_on_dow_1 is Sunday/Domenica
  52. // Trade_long_on_dow_2 is Monday/Lunedì Etc...
  53. // If a position is opened it will be closed as srategy without excluding the month
  54.  
  55. trade_long_on_dow_month_1 = input(true, group="Include/Esclude Mesi Long")
  56. trade_long_on_dow_month_2 = input(true, group="Include/Esclude Mesi Long")
  57. trade_long_on_dow_month_3 = input(true, group="Include/Esclude Mesi Long")
  58. trade_long_on_dow_month_4 = input(true, group="Include/Esclude Mesi Long")
  59. trade_long_on_dow_month_5 = input(true, group="Include/Esclude Mesi Long")
  60. trade_long_on_dow_month_6 = input(true, group="Include/Esclude Mesi Long")
  61. trade_long_on_dow_month_7 = input(true, group="Include/Esclude Mesi Long")
  62. trade_long_on_dow_month_8 = input(true, group="Include/Esclude Mesi Long")
  63. trade_long_on_dow_month_9 = input(true, group="Include/Esclude Mesi Long")
  64. trade_long_on_dow_month_10 = input(true, group="Include/Esclude Mesi Long")
  65. trade_long_on_dow_month_11 = input(true, group="Include/Esclude Mesi Long")
  66. trade_long_on_dow_month_12 = input(true, group="Include/Esclude Mesi Long")
  67.  
  68. trade_short_on_dow_month_1 = input(true, group="Include/Esclude Mesi Short")
  69. trade_short_on_dow_month_2 = input(true, group="Include/Esclude Mesi Short")
  70. trade_short_on_dow_month_3 = input(true, group="Include/Esclude Mesi Short")
  71. trade_short_on_dow_month_4 = input(true, group="Include/Esclude Mesi Short")
  72. trade_short_on_dow_month_5 = input(true, group="Include/Esclude Mesi Short")
  73. trade_short_on_dow_month_6 = input(true, group="Include/Esclude Mesi Short")
  74. trade_short_on_dow_month_7 = input(true, group="Include/Esclude Mesi Short")
  75. trade_short_on_dow_month_8 = input(true, group="Include/Esclude Mesi Short")
  76. trade_short_on_dow_month_9 = input(true, group="Include/Esclude Mesi Short")
  77. trade_short_on_dow_month_10 = input(true, group="Include/Esclude Mesi Short")
  78. trade_short_on_dow_month_11 = input(true, group="Include/Esclude Mesi Short")
  79. trade_short_on_dow_month_12 = input(true, group="Include/Esclude Mesi Short")
  80.  
  81.  
  82. trade_long_this_month = (trade_long_on_dow_month_1 and month == 1) or (trade_long_on_dow_month_2 and month == 2) or (trade_long_on_dow_month_3 and month == 3) or (trade_long_on_dow_month_4 and month == 4) or (trade_long_on_dow_month_5 and month == 5) or (trade_long_on_dow_month_5 and month == 5) or (trade_long_on_dow_month_6 and month == 6) or (trade_long_on_dow_month_7 and month == 7) or (trade_long_on_dow_month_8 and month == 8) or (trade_long_on_dow_month_9 and month == 9) or (trade_long_on_dow_month_10 and month == 10) or (trade_long_on_dow_month_11 and month == 11) or (trade_long_on_dow_month_12 and month == 12)
  83. trade_short_this_month = (trade_short_on_dow_month_1 and month == 1) or (trade_short_on_dow_month_2 and month == 2) or (trade_short_on_dow_month_3 and month == 3) or (trade_short_on_dow_month_4 and month == 4) or (trade_short_on_dow_month_5 and month == 5) or (trade_short_on_dow_month_5 and month == 5) or (trade_short_on_dow_month_6 and month == 6) or (trade_short_on_dow_month_7 and month == 7) or (trade_short_on_dow_month_8 and month == 8) or (trade_short_on_dow_month_9 and month == 9) or (trade_short_on_dow_month_10 and month == 10) or (trade_short_on_dow_month_11 and month == 11) or (trade_short_on_dow_month_12 and month == 12)
  84.  
  85. // Exit open market position when date range ends
  86. //if (trade_long_this_month)
  87. //    strategy.close_all()
  88.  
  89. //if (trade_short_this_month)
  90. //    strategy.close_all()
  91.  
  92. //4)
  93.  
  94. condEntryLong = close > maSlowLong and (maFastLong - maSlowLong) > etc..... and trade_long_today and trade_long_this_month
  95. -------------------------------------------------------------------------------------------------------------------------------------
  96.                                                  // Include or Exclude Hours of the Day
  97.  
  98.  
  99. // Include or Exclude Hours of the Day
  100. // Trade_long_on_dow_0 is 02:00 AM Confrontare Sempre Con Exchange
  101. // Trade_long_on_dow_1 is 03:00 AM Confrontare Sempre Con Exchange
  102. // If a position is opened it will be closed as srategy without excluding the hour
  103.  
  104. trade_long_on_dow_0 = input(true, group="Include/Esclude Ore Long", tooltip=" Trade_long_on_dow_0 is 02:00 AM Confrontare Sempre Con Exchange")
  105. trade_long_on_dow_1 = input(true, group="Include/Esclude Ore Long")
  106. trade_long_on_dow_2 = input(true, group="Include/Esclude Ore Long")
  107. trade_long_on_dow_3 = input(true, group="Include/Esclude Ore Long")
  108. trade_long_on_dow_4 = input(true, group="Include/Esclude Ore Long")
  109. trade_long_on_dow_5 = input(true, group="Include/Esclude Ore Long")
  110. trade_long_on_dow_6 = input(true, group="Include/Esclude Ore Long")
  111. trade_long_on_dow_7 = input(true, group="Include/Esclude Ore Long")
  112. trade_long_on_dow_8 = input(true, group="Include/Esclude Ore Long")
  113. trade_long_on_dow_9 = input(true, group="Include/Esclude Ore Long")
  114. trade_long_on_dow_10 = input(true, group="Include/Esclude Ore Long")
  115. trade_long_on_dow_11 = input(true, group="Include/Esclude Ore Long")
  116. trade_long_on_dow_12 = input(true, group="Include/Esclude Ore Long")
  117. trade_long_on_dow_13 = input(true, group="Include/Esclude Ore Long")
  118. trade_long_on_dow_14 = input(true, group="Include/Esclude Ore Long")
  119. trade_long_on_dow_15 = input(true, group="Include/Esclude Ore Long")
  120. trade_long_on_dow_16 = input(true, group="Include/Esclude Ore Long")
  121. trade_long_on_dow_17 = input(true, group="Include/Esclude Ore Long")
  122. trade_long_on_dow_18 = input(true, group="Include/Esclude Ore Long")
  123. trade_long_on_dow_19 = input(true, group="Include/Esclude Ore Long")
  124. trade_long_on_dow_20 = input(true, group="Include/Esclude Ore Long")
  125. trade_long_on_dow_21 = input(true, group="Include/Esclude Ore Long")
  126. trade_long_on_dow_22 = input(true, group="Include/Esclude Ore Long")
  127. trade_long_on_dow_23 = input(true, group="Include/Esclude Ore Long")
  128. trade_long_on_dow_24 = input(true, group="Include/Esclude Ore Long")
  129.  
  130. trade_short_on_dow_0 = input(true, group="Include/Esclude Ore Short", tooltip=" Trade_short_on_dow_0 is 02:00 AM Confrontare Sempre Con Exchange")
  131. trade_short_on_dow_1 = input(true, group="Include/Esclude Ore Short")
  132. trade_short_on_dow_2 = input(true, group="Include/Esclude Ore Short")
  133. trade_short_on_dow_3 = input(true, group="Include/Esclude Ore Short")
  134. trade_short_on_dow_4 = input(true, group="Include/Esclude Ore Short")
  135. trade_short_on_dow_5 = input(true, group="Include/Esclude Ore Short")
  136. trade_short_on_dow_6 = input(true, group="Include/Esclude Ore Short")
  137. trade_short_on_dow_7 = input(true, group="Include/Esclude Ore Short")
  138. trade_short_on_dow_8 = input(true, group="Include/Esclude Ore Short")
  139. trade_short_on_dow_9 = input(true, group="Include/Esclude Ore Short")
  140. trade_short_on_dow_10 = input(true, group="Include/Esclude Ore Short")
  141. trade_short_on_dow_11 = input(true, group="Include/Esclude Ore Short")
  142. trade_short_on_dow_12 = input(true, group="Include/Esclude Ore Short")
  143. trade_short_on_dow_13 = input(true, group="Include/Esclude Ore Short")
  144. trade_short_on_dow_14 = input(true, group="Include/Esclude Ore Short")
  145. trade_short_on_dow_15 = input(true, group="Include/Esclude Ore Short")
  146. trade_short_on_dow_16 = input(true, group="Include/Esclude Ore Short")
  147. trade_short_on_dow_17 = input(true, group="Include/Esclude Ore Short")
  148. trade_short_on_dow_18 = input(true, group="Include/Esclude Ore Short")
  149. trade_short_on_dow_19 = input(true, group="Include/Esclude Ore Short")
  150. trade_short_on_dow_20 = input(true, group="Include/Esclude Ore Short")
  151. trade_short_on_dow_21 = input(true, group="Include/Esclude Ore Short")
  152. trade_short_on_dow_22 = input(true, group="Include/Esclude Ore Short")
  153. trade_short_on_dow_23 = input(true, group="Include/Esclude Ore Short")
  154. trade_short_on_dow_24 = input(true, group="Include/Esclude Ore Short")
  155.  
  156. trade_long_hour_today = (trade_long_on_dow_0 and hour == 0) or (trade_long_on_dow_1 and hour == 1) or (trade_long_on_dow_2 and hour == 2) or (trade_long_on_dow_3 and hour == 3) or (trade_long_on_dow_4 and hour == 4) or (trade_long_on_dow_5 and hour == 5) or (trade_long_on_dow_6 and hour == 6) or (trade_long_on_dow_7 and hour == 7) or (trade_long_on_dow_8 and hour == 8) or (trade_long_on_dow_9 and hour == 9) or (trade_long_on_dow_10 and hour == 10) or (trade_long_on_dow_11 and hour == 11) or (trade_long_on_dow_12 and hour == 12) or (trade_long_on_dow_13 and hour == 13) or (trade_long_on_dow_14 and hour == 14) or (trade_long_on_dow_15 and hour == 15) or (trade_long_on_dow_16 and hour == 16) or (trade_long_on_dow_17 and hour == 17) or (trade_long_on_dow_18 and hour == 18) or (trade_long_on_dow_19 and hour == 19) or (trade_long_on_dow_20 and hour == 20) or (trade_long_on_dow_21 and hour == 21) or (trade_long_on_dow_22 and hour == 22) or (trade_long_on_dow_23 and hour == 23) or (trade_long_on_dow_24 and hour == 24)
  157. trade_short_hour_today = (trade_short_on_dow_0 and hour == 0) or (trade_short_on_dow_1 and hour == 1) or (trade_short_on_dow_2 and hour == 2) or (trade_short_on_dow_3 and hour == 3) or (trade_short_on_dow_4 and hour == 4) or (trade_short_on_dow_5 and hour == 5) or (trade_short_on_dow_6 and hour == 6) or (trade_short_on_dow_7 and hour == 7) or (trade_short_on_dow_8 and hour == 8) or (trade_short_on_dow_9 and hour == 9) or (trade_short_on_dow_10 and hour == 10) or (trade_short_on_dow_11 and hour == 11) or (trade_short_on_dow_12 and hour == 12) or (trade_short_on_dow_13 and hour == 13) or (trade_short_on_dow_14 and hour == 14) or (trade_short_on_dow_15 and hour == 15) or (trade_short_on_dow_16 and hour == 16) or (trade_short_on_dow_17 and hour == 17) or (trade_short_on_dow_18 and hour == 18) or (trade_short_on_dow_19 and hour == 19) or (trade_short_on_dow_20 and hour == 20) or (trade_short_on_dow_21 and hour == 21) or (trade_short_on_dow_22 and hour == 22) or (trade_short_on_dow_23 and hour == 23) or (trade_short_on_dow_24 and hour == 24)
  158.  
  159.  
  160. // Exit open market position when date range ends
  161.  
  162. //if (not trade_long_hour_today)
  163. //    strategy.close_all()
  164.  
  165. //if (not trade_short_hour_today)
  166. //    strategy.close_all()
  167.  
  168. cond_long = blà, blà, blà and trade_long_hour_today
  169. cond_short = blà, blà, blà and trade_short_hour_today
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement