Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. // LOVE JOY PEACE PATIENCE KINDNESS GOODNESS FAITHFULNESS GENTLENESS SELF-CONTROL
  2. // Orig Auth: © twingall
  3. // Updated Murat's Strategy to Study w/ Alerts: @joshuamcgowan
  4. // Date: 2-27-2020
  5.  
  6. //@version=4
  7.  
  8. strategy(title = "% above SMA200- Murat idea strategy", overlay=false, currency=currency.USD, commission_value=0.075,commission_type=strategy.commission.percent, initial_capital=1000)
  9.  
  10. ///////////////////////////////////////////////
  11. //* Backtesting Period Selector | Component *//
  12. ///////////////////////////////////////////////
  13.  
  14. testStartYear = input(2019, "Backtest Start Year",minval=1980)
  15. testStartMonth = input(1, "Backtest Start Month",minval=1,maxval=12)
  16. testStartDay = input(1, "Backtest Start Day",minval=1,maxval=31)
  17. testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
  18.  
  19. testStopYear = input(2020, "Backtest Stop Year",minval=1980)
  20. testStopMonth = input(12, "Backtest Stop Month",minval=1,maxval=12)
  21. testStopDay = input(31, "Backtest Stop Day",minval=1,maxval=31)
  22. testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
  23.  
  24. testPeriod() => time >= testPeriodStart and time <= testPeriodStop ? true : false
  25.  
  26. ///////////////////////////////////////////////
  27. //* Inputs and Variables *//
  28. ///////////////////////////////////////////////
  29.  
  30. SMA = sma(close, 200)
  31. diff = ((close - SMA)/close)*100
  32.  
  33. ATR = atr(9)
  34.  
  35. plot(diff)
  36.  
  37. condition = diff>10
  38.  
  39. anticondition = diff<-10
  40.  
  41. ///////////////////////////////////////////////
  42. //* Strategy Entry & Exit Conditions *//
  43. ///////////////////////////////////////////////
  44.  
  45. if condition and testPeriod()
  46. stop_level = close + 2*ATR
  47. profit_level = close - 2*ATR
  48. strategy.entry(id="Short", long=false)
  49. strategy.exit("TP/SL", "Short", stop=stop_level, limit=profit_level)
  50.  
  51.  
  52. if anticondition and testPeriod()
  53. stop_level = close - 2*ATR
  54. profit_level = close + 2*ATR
  55. strategy.entry(id="Long", long=true)
  56. strategy.exit("TP/SL", "Long", stop=stop_level, limit=profit_level)
  57.  
  58. // END //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement