-
Notifications
You must be signed in to change notification settings - Fork 16
/
BBW-RSI-60-Strategy.pine
63 lines (49 loc) · 2.99 KB
/
BBW-RSI-60-Strategy.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
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Greeffer
// github.com/modster or modster.github.io
// 210.14% profit in backtesting. Trading BTCUSDT 60 minute time frame on Binance Spot Exchange
//@version=4
// S t u d y
// study('BBW/RSI/60 Study', 'BBW/RSI/60 Study', overlay=true, precision=4)
// S t r a t e g y
strategy("RSI/BB/60 Strategy", "BBW/RSI/60 Strategy", true, format=format.inherit,
scale=scale.right, precision=5, pyramiding=10, default_qty_type=strategy.percent_of_equity,
default_qty_value=10, initial_capital=100000, currency=currency.USD,
commission_type=strategy.commission.percent, commission_value=0.075,
process_orders_on_close=true, calc_on_every_tick=false)
// I N P U T
source = close
sell = input(title="Sell", defval=80, minval=0, maxval=100)
buy = input(title="Buy", defval=20, minval=0, maxval=100)
length = input(title="Length", defval=14, minval=1, maxval=500)
// R S I
myRsi = rsi(source, length)
plot(myRsi, title="myRsi", color=color.blue, display=display.none)
//hline(buy, title='buy', color=color.red, display=display.none) //linestyle=hline.style_dotted, linewidth=1)
//hline(sell, title='sell', color=color.red, display=display.none) //linestyle=hline.style_dotted, linewidth=1)
// B o l l i n g e r B a n d s
[middle, upper, lower] = bb(source, length, 2)
plot(middle, title="middle", color=color.red, linewidth=2, style=plot.style_line, transp=70)
plot(upper, title="upper", color=color.green, linewidth=2, style=plot.style_line, transp=70)
plot(lower, title="lower", color=color.green, linewidth=2, style=plot.style_line, transp=70)
// B o l l i n g e r B a n d W i d t h
bbW = bbw(source, length, 2)
plot(bbW, title="bbWidth", color=color.orange, display=display.none)
// C o n d i t i o n s
buyCondition = crossunder(bbW, 0.01)
sellCondition = cross(source, upper) and myRsi >= sell
stopCondition = crossunder(source, middle) and bbW>0.05
if(stopCondition)
strategy.close("long", when=strategy.position_size > 0, comment="stop", qty_percent=100)
if(buyCondition)
strategy.entry("long", strategy.long, qty=100, stop=lower, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size <= 0)
if(sellCondition)
strategy.order("short", strategy.short, qty=10, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=myRsi>=95)
strategy.order("short", strategy.short, qty=20, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=myRsi>=80)
strategy.order("short", strategy.short, qty=10, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size>40)
// B U Y
//alertcondition(buyCondition, title='Buy', message='{"direction":"buy","close":"{{close}}","time":"{{time}}"}')
// S E L L
//alertcondition(sellCondition, title='Sell', message='{"direction":"sell","close":"{{close}}","time":"{{time}}"}')
// S T O P
//alertcondition(stopCondition, title='Stop', message='{"direction":"stop","close":"{{close}}","time":"{{time}}"}')