Advertisement
Maurizio-Ciullo

11 Come creare intervalli di tempo personalizzati

Oct 31st, 2021
139
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. //@version=4
  5.  
  6. //Strategia di prova nĀ°1
  7. //11 Come creare intervalli di tempo personalizzati
  8. //Strategia Daily Chiliz/USDT Incrocio Sma8 con Sma12
  9. //Scheletro
  10.  
  11. strategy(title="Strategia_Maurizio_Ciullo1",
  12.      shorttitle="S_M_C_1",
  13.      overlay=true,
  14.      pyramiding=0,
  15.      default_qty_type=strategy.percent_of_equity,
  16.      default_qty_value=5,
  17.      initial_capital=1000,
  18.      //currency=currency.USD,
  19.      commission_type=strategy.commission.cash_per_order,
  20.      commission_value=0.1,
  21.      slippage=2
  22.      )
  23.  
  24. // STEP 1 DATARANGE:
  25. // Make input options that configure backtest date range
  26.  
  27. startDate = input(title="Start Date", type=input.integer,
  28.      defval=16, minval=1, maxval=31)
  29. startMonth = input(title="Start Month", type=input.integer,
  30.      defval=7, minval=1, maxval=12)
  31. startYear = input(title="Start Year", type=input.integer,
  32.      defval=2017, minval=1800, maxval=2100)
  33.  
  34. endDate = input(title="End Date", type=input.integer,
  35.      defval=16, minval=1, maxval=31)
  36. endMonth = input(title="End Month", type=input.integer,
  37.      defval=12, minval=1, maxval=12)
  38. endYear = input(title="End Year", type=input.integer,
  39.      defval=2018, minval=1800, maxval=2100)
  40.      
  41. // STEP 2 DATARANGE:
  42. // Look if the close time of the current bar
  43. // falls inside the date range
  44.  
  45. inDateRange = (time >= timestamp(syminfo.timezone, startYear,
  46.          startMonth, startDate, 0, 0)) and
  47.      (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
  48.  
  49. //Parametri Indicatori Ed Oscillatori
  50.  
  51. Media_Mobile_Esponenziale_Veloce=ema(close, 8)
  52.  
  53. Media_Mobile_Esponenziale_Lenta=ema(close,12)
  54.  
  55. //Le faccio visualizzare sul grafico alla chiusura che ho definito con i clori che ho definito
  56.  
  57. plot(Media_Mobile_Esponenziale_Veloce, color=color.orange)
  58. plot(Media_Mobile_Esponenziale_Lenta, color=color.blue)
  59.  
  60. //Condizioni parametri di entrata
  61.  
  62. Cond_Entry_Long=crossover(Media_Mobile_Esponenziale_Veloce, Media_Mobile_Esponenziale_Lenta)
  63.  
  64. //Condizioni parametri di uscita
  65.  
  66. Cond_Exit_Long=crossunder(Media_Mobile_Esponenziale_Veloce, Media_Mobile_Esponenziale_Lenta)
  67.  
  68. // STEP 3 DATARANGE E ENTRY EXIT:
  69. // Submit entry orders, but only when bar is inside date range
  70.  
  71. if (inDateRange and Cond_Entry_Long)
  72.     strategy.entry("ID 1 Ingresso Long", true, when=Cond_Entry_Long)
  73. if (inDateRange and Cond_Exit_Long)
  74.     strategy.close("ID 1 Ingresso Long", when=Cond_Exit_Long)
  75.    
  76. // STEP 4 DATARANGE:
  77. // Exit open market position when date range ends
  78.  
  79. if (not inDateRange)
  80.     strategy.close_all()
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement