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
/
Ichi_Renkos_Revenge.pine
130 lines (113 loc) · 5.58 KB
/
Ichi_Renkos_Revenge.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//@version=3
// HIGH LEVEL STRATEGY
// Based on logic described here - https://www.youtube.com/watch?v=sghyPtOimXQ
// 1. Open buy position when:
// a) tenkan/kijun lines crossover, AND
// b) current price is above the green cloud
// 2. Exit previous buy position when:
// a) price has touched the cloud again, OR
// b) open sell position mentioned below in 3., OR
// c) price crosses below the kijun line (aggressive), OR
// d) price crosses below all 4 lines (conservative), OR
// e) renko sell signal seen
// 3. Open sell position when:
// a) tenkan/kijun lines crossunder, AND
// b) current price is below the red cloud
// 4. Exit previous sell position when:
// a) price has touched the cloud again, OR
// b) open buy position mentioned below in 1., OR
// c) price crosses above the kijun line (aggressive), OR
// d) price crosses above all 4 lines (conservative), OR
// e) renko buy signal seen
strategy(title="Ichimoku Renko Revenge V1", shorttitle="Ichi_RenkoV1", overlay=true)
//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)
isAggressiveStrategy = input(true, title="Use aggressive closing of positions")
// store state of open position (whether long or short)
lastOpenPosition = 0.0
lastOpenPosition := lastOpenPosition[1]
price = 0.0
price := na
//////////////
// RENKO LOGIC
//////////////
//Entry/exit just after 1 RENKO BRICKS
isRenkoBuyEntry = close > open[1] and close[1] < open[2]
isRenkoSellEntry = close < open[1] and close[1] > open[2]
//Entry/exit just after 2 RENKO BRICKS
//isRenkoBuyEntry = open[0] > open[1] and open[0] > open[2]
//isRenkoSellEntry = open[0] < open[1] and open[0] < open[2]
// Logic for open positions
isBuySignal = crossover(tenkanLine, kijunLine) and leadLine1 > leadLine2
isSellSignal = crossunder(tenkanLine, kijunLine) and leadLine1 < leadLine2
isAboveCloud = close > leadLine1[displacement] and close > leadLine2[displacement]
isBelowCloud = close < leadLine1[displacement] and close < leadLine2[displacement]
strongBuy = isBuySignal and isAboveCloud
strongSell = isSellSignal and isBelowCloud
// Logic for exit positions
inOpenPosition = lastOpenPosition[1] != 0
inPreviousBuy = lastOpenPosition[1] > 0
inPreviousSell = lastOpenPosition[1] < 0
isAboveAllLines = isAboveCloud and close > tenkanLine and close > kijunLine
isBelowAllLines = isBelowCloud and close < tenkanLine and close < kijunLine
// isBuyExit = inPreviousBuy and ( (isAggressiveStrategy ? crossunder(close, kijunLine) : isBelowAllLines) or isSellSignal or isRenkoSellEntry )
// isSellExit = inPreviousSell and ( (isAggressiveStrategy ? crossover(close, kijunLine) : isAboveAllLines) or isBuySignal or isRenkoBuyEntry )
// renko only exits
isBuyExit = inPreviousBuy and isRenkoSellEntry
isSellExit = inPreviousSell and isRenkoBuyEntry
// Visualise the Opening positions
plotshape(isBuySignal and not strongBuy, style=shape.arrowup, location=location.abovebar, color=green, size=size.small)
plotshape(strongBuy, style=shape.arrowup, location=location.abovebar, color=green, size=size.large)
plotshape(isSellSignal and not strongSell, style=shape.arrowdown, location=location.belowbar, color=red, size=size.small)
plotshape(strongSell, style=shape.arrowdown, location=location.belowbar, color=red, size=size.large)
// Visualise the Exit positions
plotshape(isBuyExit, style=shape.xcross, location=location.abovebar, color=green, size=size.small)
plotshape(isSellExit, style=shape.xcross, location=location.belowbar, color=red, size=size.small)
// Visualise Renko Exit Positions
plotshape(isRenkoBuyEntry, style=shape.diamond, location=location.abovebar, color=green, size=size.tiny, text="rb")
plotshape(isRenkoSellEntry, style=shape.diamond, location=location.belowbar, color=red, size=size.tiny, text="rs")
if isBuyExit
strategy.close("buy")
lastOpenPosition := 0
price := close
if isSellExit
strategy.close("sell")
lastOpenPosition := 0
price := close
if (isBuySignal and not inPreviousBuy)
price := close
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 (isSellSignal and not inPreviousSell)
price := close
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")
// Visualise price change for open positions
plot(price, style=line, color=inOpenPosition ? purple : white, title="Open Postion")
bgcolor(inPreviousBuy ? green : na, transp=70)
bgcolor(inPreviousSell ? red : na, transp=70)