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
/
Pleo_Ross.pine
90 lines (78 loc) · 3.87 KB
/
Pleo_Ross.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//@version=3
// study(title="Pleo_Ross Ichimoku Cloud", shorttitle="Pleo", overlay=false)
strategy(title="Pleo_Ross v3", shorttitle="PleoV3", overlay=false)
//Ichimoku input Logic
conversionPeriods = input(9, minval=1, title="Conversion Line Periods"),
basePeriods = input(26, minval=1, title="Base Line Periods")
laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Periods"),
displacement = input(26, minval=1, title="Displacement")
//Ichimoku function Logic
donchian(len) => avg(lowest(len), highest(len))
//Ichimoku line Logic
tenkanLine = donchian(conversionPeriods)
kijunLine = donchian(basePeriods)
leadLine1 = avg(tenkanLine, kijunLine)
leadLine2 = donchian(laggingSpan2Periods)
// Plot Ichimoku Cloud
plot(tenkanLine, color=blue, linewidth=3, title="Tenkan Line")
plot(kijunLine, color=red, linewidth=3, title="Kijun Line")
plot(close, offset = -displacement, color=green, linewidth=2, title="Chikou Lagging Span")
p1 = plot(leadLine1, offset = displacement, color=white, title="Lead 1")
p2 = plot(leadLine2, offset = displacement, color=white, title="Lead 2")
fill(p1, p2, color = leadLine1 > leadLine2 ? green : red)
// store state of open position (whether long or short)
lastOpenPosition = 0.0
lastOpenPosition := lastOpenPosition[1]
// find where the lines cross
weakBuy = crossover(tenkanLine, kijunLine)
weakSell = crossunder(tenkanLine, kijunLine)
isAboveCloud = close > leadLine1[displacement] and close > leadLine2[displacement]
isBelowCloud = close < leadLine1[displacement] and close < leadLine2[displacement]
strongBuy = weakBuy and isAboveCloud
strongSell = weakSell and isBelowCloud
// Opening positions
plotshape(weakBuy and not strongBuy, style=shape.arrowup, location=location.belowbar, color=green, size=size.small)
plotshape(strongBuy, style=shape.arrowup, location=location.belowbar, color=green, size=size.large)
plotshape(weakSell and not strongSell, style=shape.arrowdown, location=location.abovebar, color=red, size=size.small)
plotshape(strongSell, style=shape.arrowdown, location=location.abovebar, color=red, size=size.large)
inPreviousBuy = lastOpenPosition[1] > 0
inPreviousSell = lastOpenPosition[1] < 0
if (weakBuy and not inPreviousBuy)
strategy.close("sell")
if strongBuy
lastOpenPosition := 2
strategy.entry("buy", strategy.long, 2, comment="Strong buy")
else
lastOpenPosition := 1
strategy.entry("buy", strategy.long, 1, comment="Weak buy")
if (weakSell and not inPreviousSell)
strategy.close("buy")
if strongSell
lastOpenPosition := -2
strategy.entry("sell", strategy.short, 2, comment="Strong sell")
else
lastOpenPosition := -1
strategy.entry("sell", strategy.short, 1, comment="Weak sell")
////////////////////
// RSI LOGIC
/////////////////////
rSILength = input(14,title="RSI Period Length")
rSIOverSoldLevel = input(30, title="RSI oversold level")
rSIOverBoughtLevel = input(70, title="RSI overbought level")
price = close
vrsi = rsi(price, rSILength)
// isOverSold = (not na(vrsi)) and crossover(vrsi, rSIOverSoldLevel)
// isOverBought = (not na(vrsi)) and crossunder(vrsi, rSIOverBoughtLevel)
isOverSold = (not na(vrsi)) and vrsi <= rSIOverSoldLevel
isOverBought = (not na(vrsi)) and vrsi >= rSIOverBoughtLevel
plotchar(isOverBought, char='b', location=location.top, color=green)
plotchar(isOverSold, char='s', location=location.bottom, color=red)
// plot(vrsi, color= isOverBought or isOverSold ? blue : purple)
// hline(100, title="Max Line", linestyle=solid, linewidth=1, color=gray)
// hline(0, title="Min Line", linestyle=solid, linewidth=1, color=gray)
// bandTop = hline(rSIOverSoldLevel, title="Upper Line", linestyle=dashed, linewidth=1, color=gray, transp=90)
// bandBot = hline(rSIOverBoughtLevel, title="Lower Line", linestyle=dashed, linewidth=1, color=gray, transp=90)
// fill(bandTop, bandBot, color=purple, transp=90)
////////////////////
// END RSI LOGIC
/////////////////////