-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathHourlyScan.pine
More file actions
50 lines (41 loc) · 2.39 KB
/
HourlyScan.pine
File metadata and controls
50 lines (41 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//@version=4
study(title="Hourly Scan", overlay=true)
// Idea from "Serious Backtester" - https://www.youtube.com/watch?v=2hX7qTamOAQ
// Defaults are optimized for 30 min candles
// This combines the idea of a trampoline with Bollinger Bands and RSI
// CONFIG
iBBThreshold = input(0.0010, minval=0.0, title="Bollinger Lower Threshold", tooltip="0.003 for daily, 0.0015 for 30 min candles", group="General Settings")
RSIThreshold = input(25, minval=1, title="RSI Lower Threshold", tooltip="Normally 25", group="General Settings")
RSIDown = input(72, minval=1, title="RSI Upper Threshold", tooltip="Normally 75", group="General Settings")
rsiLengthInput = input(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input(close, "Source", group="RSI Settings")
lengthBB = input(20, minval=1, group="Bollinger Bands")
srcBB = input(close, title="Source", group="Bollinger Bands")
multBB = input(2.0, minval=0.001, maxval=50, title="StdDev", group="Bollinger Bands")
offsetBB = input(0, "Offset", minval = -500, maxval = 500, group="Bollinger Bands")
isRed = close < open
isGreen = close > open
// BOLLINGER BANDS
basisBB = sma(srcBB, lengthBB)
devBB = multBB * stdev(srcBB, lengthBB)
upperBB = basisBB + devBB
lowerBB = basisBB - devBB
downBB = low < lowerBB or high < lowerBB
upBB = low > upperBB or high > upperBB
bbw = (upperBB - lowerBB) / basisBB
// RSI
up = rma(max(change(rsiSourceInput), 0), rsiLengthInput)
down = rma(-min(change(rsiSourceInput), 0), rsiLengthInput)
rsiM = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
back1 = isRed[1] and rsiM[1] <= RSIThreshold and close[1] < lowerBB[1] and bbw[1] > iBBThreshold
for1 = isGreen[1] and rsiM[1] >= RSIDown and close[1] > upperBB[1] and bbw[1] > iBBThreshold
weGoUp = isGreen and (back1 ) and (high > high[1])
upThrust = weGoUp and not weGoUp[1] and not weGoUp[2] and not weGoUp[3] and not weGoUp[4]
weGoDown = isRed and (for1 ) and (low < low[1])
downThrust = weGoDown and not weGoDown[1] and not weGoDown[2] and not weGoDown[3] and not weGoDown[4]
atrUp = high + atr(14) * 1.2
atrDown = low - atr(14) * 1.6
if (upThrust)
alert("Trampoline Buy on " + syminfo.ticker + " at " + str.tostring(close, "#.##") + ", TP: " + str.tostring(atrUp, "#.##"), alert.freq_once_per_bar)
if (downThrust)
alert("Trampoline Sell on " + syminfo.ticker + " at " + str.tostring(close, "#.##") + ", TP: " + str.tostring(atrDown, "#.##"), alert.freq_once_per_bar)