Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- strategy("DMT Cloud Strategy", shorttitle="DMT Cloud Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital = 1000)
- //Inputs
- mult1 = input(title="Multiplier 1", type=input.float, step=0.1, defval=10)
- period1 = input(title="Period 1", type=input.integer, defval=6)
- mult2 = input(title="Multiplier 2", type=input.float, step=0.1, defval=6)
- period2 = input(title="Period 2", type=input.integer, defval=10)
- // sl_inp = input(4, title='Stop Loss %', type=input.float)/100
- // tp_inp = input(2, title='Take Profit %', type=input.float)/100
- stopLoss = input(100, title = "Stop loss percentage(For eg: 100 means 10%)")
- takeProfit = input(2, title = "Take profit percentage(2 means 0.2%)")
- ////////////////////////////////////////////////////////////////////////////////
- // BACKTESTING RANGE
- // From Date Inputs
- fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
- fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
- fromYear = input(defval = 2018, title = "From Year", minval = 1970)
- // To Date Inputs
- toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
- toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
- toYear = input(defval = 2020, title = "To Year", minval = 1970)
- // Calculate start/end date and time condition
- startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
- finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
- time_cond = time >= startDate and time <= finishDate
- ////////////////////////////////////////////////////////////////////////////////
- //Calculations
- up_lev1 = hl2 - (mult1 * atr(period1))
- dn_lev1 = hl2 + (mult2 * atr(period2))
- up_lev2 = hl2 - (mult1 * atr(period1))
- dn_lev2 = hl2 + (mult2 * atr(period2))
- up_trend1 = 0.0
- up_trend1 := close[1] > up_trend1[1] ? max(up_lev1, up_trend1[1]) : up_lev1
- up_trend2 = 0.0
- up_trend2 := close[1] > up_trend2[1] ? max(up_lev2, up_trend2[1]) : up_lev2
- down_trend1 = 0.0
- down_trend1 := close[1] < down_trend1[1] ? min(dn_lev1, down_trend1[1]) : dn_lev1
- down_trend2 = 0.0
- down_trend2 := close[1] < down_trend2[1] ? min(dn_lev2, down_trend2[1]) : dn_lev2
- trend1 = 0
- trend1 := close > down_trend1[1] ? 1: close < up_trend1[1] ? -1 : nz(trend1[1], 1)
- trend2 = 0
- trend2 := close > down_trend2[1] ? 1: close < up_trend2[1] ? -1 : nz(trend2[1], 1)
- st_line1 = trend1 == 1 ? up_trend1 : down_trend1
- st_line2 = trend2 == 1 ? up_trend2 : down_trend2
- // Plotting
- plot1 = plot(st_line1, color = trend1 == 1 ? color.green : color.red , style = plot.style_line, linewidth = 1, title = "T 1")
- plot2 = plot(st_line2, color = trend2 == 1 ? color.green : color.red , style = plot.style_line, linewidth = 1, title = "T 2")
- fill(plot1, plot2, color = color.aqua, title = "MTSCloud")
- //buy = crossover(close, st_line1) and close > st_line2 or crossover(close, st_line2) and close > st_line1
- //plotshape(buy, title = "Buy", text = "Buy", style = shape.labelup, location = location.belowbar, color = color.green, size=size.small, textcolor=color.white, transp=0)
- //sell = crossunder(close, st_line1) and close < st_line2 or crossunder(close, st_line2) and close < st_line1
- //plotshape(sell, title = "Sell", text = "Sell", style = shape.labeldown, location = location.abovebar, color = color.red, size=size.small, textcolor=color.white, transp=0)
- //alertcondition(buy, title="Buy", message="MTS Buy!")
- //alertcondition(sell, title="Sell", message="MTS Sell!")
- long = crossover(close, st_line1) and close > st_line2 or crossover(close, st_line2) and close > st_line1
- short = crossunder(close, st_line1) and close < st_line2 or crossunder(close, st_line2) and close < st_line1
- NoTrade = crossover(close, st_line1) and close < st_line2 or crossunder(close, st_line1) and close > st_line2
- // stop_level = strategy.position_avg_price * (1 - sl_inp)
- // take_level = strategy.position_avg_price * (1 + tp_inp)
- // stop_level2 = strategy.position_avg_price * (1 + sl_inp)
- // take_level2 = strategy.position_avg_price * (1 - tp_inp)
- // // strategy.order("Stop Loss", false, stop=stop_level,"long")
- // // strategy.order("Take Profit", false, limit=take_level, "long")
- // loss=sl_inp, profit=tp_inp
- if(long and time_cond)
- strategy.entry("long", long = true , comment="long")
- // strategy.exit("Stop Loss/TP","long", loss=stop_level, profit=take_level)
- strategy.exit("Exit", "long", loss = close * stopLoss / 1000 / syminfo.mintick, profit = close * takeProfit / 1000 / syminfo.mintick)
- if(NoTrade and time_cond)
- strategy.close("long")
- strategy.close("short")
- if(short and time_cond)
- strategy.entry("short", long = false , comment="short")
- strategy.exit("Exit", "short", loss = close * stopLoss / 1000 / syminfo.mintick, profit = close * takeProfit / 1000 / syminfo.mintick)
- // strategy.exit("Stop Loss/TP","short", loss=stop_level, profit=take_level)
- if (not time_cond)
- strategy.close_all()
- // plot(stop_level, color=color.red, linewidth=5)
- // plot(take_level, color=color.green, linewidth=5)
- // plot(stop_level2, color=color.blue, linewidth=5)
- // plot(take_level2, color=color.white, linewidth=5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement