This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
NDAQ_Scalper_CCI_alerts.pine
44 lines (36 loc) · 2.22 KB
/
NDAQ_Scalper_CCI_alerts.pine
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
//@version=3
study(title="CCI Scalper Alerts", shorttitle="CCI Scalper Alerts")
FastMA = input(10, minval=1)
SlowMA = input(20, minval=1)
upperBoundLine = input(137, "CCI Upper line", type=integer)
lowerBoundLine = input(-142, "CCI Lower line", type=integer)
useSMA = input(false, "Use SMA with CCI", type=bool)
cciPeriod = input(20, "CCI Period (number of bars)", type=integer)
// === INPUT BACKTEST RANGE ===
FromDay = input(defval = 14, title = "From Day", minval = 1, maxval = 31)
FromMonth = input(defval = 11, title = "From Month", minval = 1, maxval = 12)
FromYear = input(defval = 2018, title = "From Year", minval = 2017)
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 = 9999, title = "To Year", minval = 2017)
start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"
hline(upperBoundLine, title = "Overbought upper line", color=orange, linestyle=dashed)
hline(lowerBoundLine, title = "Oversold lower line", color=orange, linestyle=dashed)
xCCI = cci(close, cciPeriod)
xSMA = sma(xCCI, SlowMA)
xFMA = sma(xCCI, FastMA)
pos = 0
pos := iff(xSMA < xFMA , 1, iff(xSMA > xFMA, -1, nz(pos[1], 0)))
isSellSignal = useSMA ? crossunder(xSMA, xFMA) : crossunder(xCCI, upperBoundLine)
isBuySignal = useSMA ? crossover(xSMA, xFMA) : crossover(xCCI, lowerBoundLine)
// Visualise the Opening positions
plotshape(isSellSignal ? 1 : na, style=shape.arrowdown, location=location.absolute, color=green, text="Sell")
plotshape(isBuySignal ? 1 : na, style=shape.arrowup, location=location.absolute, color=red, text="Buy")
// barcolor(pos == -1 ? red: pos == 1 ? green : blue)
plot(useSMA ? xSMA : na, color=red, title="CCI MA Slow")
plot(useSMA ? xFMA : na, color=blue, title="CCI MA FAST")
plot(not useSMA ? xCCI : na, color=(isSellSignal or isBuySignal) ? red : green, title="CCI Standard")
alertcondition(isBuySignal, title='Buy', message='Buy signal')
alertcondition(isSellSignal, title='Sell', message='Sell signal')