Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- // this is based on https://www.tradingview.com/v/PbQW4mRn/
- //strategy(title = "ONLY LONG V4 v1", overlay = true, initial_capital = 1000, pyramiding = 1000,
- //calc_on_order_fills = false, calc_on_every_tick = false, default_qty_type = strategy.percent_of_equity, default_qty_value = 50, commission_value = 0.075)
- study(title = "ONLY LONG V4 v1", overlay = true)
- //Fast RSI
- src = close
- fastup = rma(max(change(src), 0), 3)
- fastdown = rma(-min(change(src), 0), 3)
- fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))
- //Body Filter
- body = abs(close - open)
- abody = sma(body, 20)
- mac = sma(close, 20)
- len = abs(close - mac)
- sma = sma(len, 100)
- max = max(open, close)
- min = min(open, close)
- up = close < open and len > sma * 2 and min < min[1] and fastrsi < 10 and body > abody * 2.5
- // Strategy
- // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- var bool longCondition = na
- longCondition := up == 1 ? 1 : na
- // Get the price of the last opened long
- var float last_open_longCondition = na
- last_open_longCondition := longCondition ? close : nz(last_open_longCondition[1])
- // Get the bar time of the last opened long
- var int last_longCondition = 0
- last_longCondition := longCondition ? time : nz(last_longCondition[1])
- // Take profit
- // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- tp = input(20, "TAKE PROFIT %", type = input.float, minval = 0, step = 0.5)
- long_tp = crossover(high, (1+(tp/100))*last_open_longCondition) and not longCondition
- // Get the time of the last tp close
- var int last_long_tp = na
- last_long_tp := long_tp ? time : nz(last_long_tp[1])
- Final_Long_tp = long_tp and last_longCondition > nz(last_long_tp[1])
- // Count your long conditions
- var int sectionLongs = 0
- sectionLongs := nz(sectionLongs[1])
- var int sectionTPs = 0
- sectionTPs := nz(sectionTPs[1])
- // Longs Counter
- if longCondition
- sectionLongs := sectionLongs + 1
- sectionTPs := 0
- if Final_Long_tp
- sectionLongs := 0
- sectionTPs := sectionTPs + 1
- // Signals
- // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- // Long
- label.new(
- x = longCondition[1] ? time : na,
- y = na,
- text = 'LONG'+tostring(sectionLongs),
- color=color.lime,
- textcolor=color.black,
- style = label.style_labelup,
- xloc = xloc.bar_time,
- yloc = yloc.belowbar,
- size = size.tiny)
- // Tp
- label.new(
- x = Final_Long_tp ? time : na,
- y = na,
- text = 'PROFIT '+tostring(tp)+'%',
- color=color.orange,
- textcolor=color.black,
- style = label.style_labeldown,
- xloc = xloc.bar_time,
- yloc = yloc.abovebar,
- size = size.tiny)
- ltp = iff(Final_Long_tp, (last_open_longCondition*(1+(tp/100))), na), plot(ltp, style=plot.style_cross, linewidth=3, color = color.white, editable = false)
- // Backtesting
- // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- //testStartYear = input(2019, "BACKTEST START YEAR", minval = 1, maxval = 2222)
- //testStartMonth = input(01, "BACKTEST START MONTH", minval = 1, maxval = 12)
- //testStartDay = input(01, "BACKTEST START DAY", minval = 1, maxval = 31)
- //testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
- //strategy.entry("long", strategy.long, when = longCondition and (time >= testPeriodStart))
- //strategy.exit("TP", "long", limit = (last_open_longCondition*(1+(tp/100))))
- // Alerts
- // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- alertcondition(longCondition[1], title="Long Alert", message = "LONG")
- alertcondition(Final_Long_tp, title="Long TP Alert", message = "LONG TP")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement