Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.98 KB | None | 0 0
  1. // STRATEGY SETTINGS
  2.  
  3. // Backtest Range
  4. FromYear  = input( defval = 2017, title = "Strategy from Year", type=integer, minval = 2011 )
  5. FromMonth = input( defval = 04,   title = "... Month",          type=integer, minval = 1 )
  6. FromDay   = input( defval = 01,   title = "... Day",            type=integer, minval = 1 )
  7. ToYear    = input( defval = 2018, title = "Strategy to Year",   type=integer, minval = 2011 )
  8. ToMonth   = input( defval = 03,   title = "... Month",          type=integer, minval = 1 )
  9. ToDay     = input( defval = 31,   title = "... Day",            type=integer, minval = 1 )
  10. isTimeRange = ( time > timestamp( FromYear, FromMonth, FromDay, 00, 00 ) ) and ( time < timestamp( ToYear, ToMonth, ToDay, 23, 59 ) )
  11.  
  12.  
  13.  
  14.  
  15. // -----------------------------------------------------------------------------
  16. // *****************************************************************************
  17. //                                      STRATEGY
  18.  
  19.  
  20. // ________________________
  21. // ______ CONDITIONS ______
  22.  
  23. // Definition of strategy conditions
  24. // NOTE: A "long trade" (i.e. buying to enter the market, then selling at a higher price to exit)
  25. //       is called "Bull Trade".
  26. //       Conversely, a "short trade" (i.e. selling to enter the market, then buying at a lower price to exit)
  27. //       is called "Bear Trade".
  28. //       The logic is always the same: "buy low, sell high" (whatever the order in time).
  29.  
  30.  
  31. // BUY CONDITIONS
  32. // Entry for a bull trade, exit for bear trade
  33.  
  34. // simple conditions for example, using long TF
  35.  
  36. // Look for a low above the lines (candle entirely out of the band)
  37. priceOverNegStDev1 = crossover(low, longDevLineBelow1)    // Negative Standard Deviation (i.e. below the mean)
  38. priceOverNegGolden = crossover(low, longDevLineBelow2)    // Negative Golden Deviation
  39.  
  40. // Trigger a bull signal when conditions are met
  41. bullSignal = priceOverNegStDev1 or priceOverNegGolden
  42.  
  43.  
  44. // SELL CONDITIONS
  45. // Exit for bull, entry for bear
  46.  
  47. // simple conditions for example, using long TF
  48.  
  49. // Look for a high below the bands
  50. priceOverPosStDev1 = crossunder(high, longDevLineAbove1)    // Positive Standard Deviation (i.e. above the mean)
  51. priceOverPosGolden = crossunder(high, longDevLineAbove2)    // Positive Golden Deviation
  52.  
  53. // Trigger a bear signal when conditions are met
  54. bearSignal = priceOverPosStDev1 or priceOverPosGolden
  55.  
  56.  
  57.  
  58. // ________________________
  59. // ______ EXECUTION ______
  60.  
  61. // BULL TRADE
  62. strategy.entry( "BULL", strategy.long, when=( bullSignal and isTimeRange ) )
  63. strategy.close( "BULL",                when=( bearSignal and isTimeRange ) )
  64.  
  65. // BEAR TRADE
  66. //strategy.entry( "BEAR", strategy.short, when=( bearSignal and isTimeRange ) )
  67. //strategy.close( "BEAR",                 when=( bullSignal and isTimeRange ) )
  68.  
  69.  
  70.  
  71. //                                  End of STRATEGY
  72. // *****************************************************************************
  73. // -----------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement