Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. //@version=4
  2. strategy("DMT Cloud Strategy", shorttitle="DMT Cloud Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital = 1000)
  3.  
  4. //Inputs
  5. mult1 = input(title="Multiplier 1", type=input.float, step=0.1, defval=10)
  6. period1 = input(title="Period 1", type=input.integer, defval=6)
  7. mult2 = input(title="Multiplier 2", type=input.float, step=0.1, defval=6)
  8. period2 = input(title="Period 2", type=input.integer, defval=10)
  9.  
  10. // sl_inp = input(4, title='Stop Loss %', type=input.float)/100
  11. // tp_inp = input(2, title='Take Profit %', type=input.float)/100
  12.  
  13. stopLoss = input(100, title = "Stop loss percentage(For eg: 100 means 10%)")
  14. takeProfit = input(2, title = "Take profit percentage(2 means 0.2%)")
  15. ////////////////////////////////////////////////////////////////////////////////
  16. // BACKTESTING RANGE
  17.  
  18. // From Date Inputs
  19. fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
  20. fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
  21. fromYear = input(defval = 2018, title = "From Year", minval = 1970)
  22.  
  23. // To Date Inputs
  24. toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
  25. toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
  26. toYear = input(defval = 2020, title = "To Year", minval = 1970)
  27.  
  28. // Calculate start/end date and time condition
  29. startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
  30. finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
  31. time_cond = time >= startDate and time <= finishDate
  32.  
  33. ////////////////////////////////////////////////////////////////////////////////
  34. //Calculations
  35. up_lev1 = hl2 - (mult1 * atr(period1))
  36. dn_lev1 = hl2 + (mult2 * atr(period2))
  37. up_lev2 = hl2 - (mult1 * atr(period1))
  38. dn_lev2 = hl2 + (mult2 * atr(period2))
  39.  
  40. up_trend1 = 0.0
  41. up_trend1 := close[1] > up_trend1[1] ? max(up_lev1, up_trend1[1]) : up_lev1
  42. up_trend2 = 0.0
  43. up_trend2 := close[1] > up_trend2[1] ? max(up_lev2, up_trend2[1]) : up_lev2
  44.  
  45. down_trend1 = 0.0
  46. down_trend1 := close[1] < down_trend1[1] ? min(dn_lev1, down_trend1[1]) : dn_lev1
  47. down_trend2 = 0.0
  48. down_trend2 := close[1] < down_trend2[1] ? min(dn_lev2, down_trend2[1]) : dn_lev2
  49.  
  50. trend1 = 0
  51. trend1 := close > down_trend1[1] ? 1: close < up_trend1[1] ? -1 : nz(trend1[1], 1)
  52. trend2 = 0
  53. trend2 := close > down_trend2[1] ? 1: close < up_trend2[1] ? -1 : nz(trend2[1], 1)
  54.  
  55. st_line1 = trend1 == 1 ? up_trend1 : down_trend1
  56. st_line2 = trend2 == 1 ? up_trend2 : down_trend2
  57.  
  58. // Plotting
  59. plot1 = plot(st_line1, color = trend1 == 1 ? color.green : color.red , style = plot.style_line, linewidth = 1, title = "T 1")
  60. plot2 = plot(st_line2, color = trend2 == 1 ? color.green : color.red , style = plot.style_line, linewidth = 1, title = "T 2")
  61. fill(plot1, plot2, color = color.aqua, title = "MTSCloud")
  62.  
  63. //buy = crossover(close, st_line1) and close > st_line2 or crossover(close, st_line2) and close > st_line1
  64. //plotshape(buy, title = "Buy", text = "Buy", style = shape.labelup, location = location.belowbar, color = color.green, size=size.small, textcolor=color.white, transp=0)
  65. //sell = crossunder(close, st_line1) and close < st_line2 or crossunder(close, st_line2) and close < st_line1
  66. //plotshape(sell, title = "Sell", text = "Sell", style = shape.labeldown, location = location.abovebar, color = color.red, size=size.small, textcolor=color.white, transp=0)
  67.  
  68. //alertcondition(buy, title="Buy", message="MTS Buy!")
  69. //alertcondition(sell, title="Sell", message="MTS Sell!")
  70.  
  71. long = crossover(close, st_line1) and close > st_line2 or crossover(close, st_line2) and close > st_line1
  72. short = crossunder(close, st_line1) and close < st_line2 or crossunder(close, st_line2) and close < st_line1
  73. NoTrade = crossover(close, st_line1) and close < st_line2 or crossunder(close, st_line1) and close > st_line2
  74.  
  75.  
  76. // stop_level = strategy.position_avg_price * (1 - sl_inp)
  77. // take_level = strategy.position_avg_price * (1 + tp_inp)
  78.  
  79. // stop_level2 = strategy.position_avg_price * (1 + sl_inp)
  80. // take_level2 = strategy.position_avg_price * (1 - tp_inp)
  81. // // strategy.order("Stop Loss", false, stop=stop_level,"long")
  82. // // strategy.order("Take Profit", false, limit=take_level, "long")
  83.  
  84. // loss=sl_inp, profit=tp_inp
  85. if(long and time_cond)
  86. strategy.entry("long", long = true , comment="long")
  87. // strategy.exit("Stop Loss/TP","long", loss=stop_level, profit=take_level)
  88. strategy.exit("Exit", "long", loss = close * stopLoss / 1000 / syminfo.mintick, profit = close * takeProfit / 1000 / syminfo.mintick)
  89.  
  90. if(NoTrade and time_cond)
  91. strategy.close("long")
  92. strategy.close("short")
  93.  
  94. if(short and time_cond)
  95. strategy.entry("short", long = false , comment="short")
  96. strategy.exit("Exit", "short", loss = close * stopLoss / 1000 / syminfo.mintick, profit = close * takeProfit / 1000 / syminfo.mintick)
  97.  
  98. // strategy.exit("Stop Loss/TP","short", loss=stop_level, profit=take_level)
  99.  
  100. if (not time_cond)
  101. strategy.close_all()
  102.  
  103. // plot(stop_level, color=color.red, linewidth=5)
  104. // plot(take_level, color=color.green, linewidth=5)
  105.  
  106. // plot(stop_level2, color=color.blue, linewidth=5)
  107. // plot(take_level2, color=color.white, linewidth=5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement