├── BB-2020.js ├── BBW-RSI-60-Strategy.pine ├── BBW-RSI-60-Study.pine ├── StochRSI-Vol.png ├── bb-rsi-15m-3.pine ├── bb-rsi-1m-3.pine ├── bb-rsi-1m-4.pine ├── bb-rsi.pine ├── bollinger-bands-strategy.js ├── colors.pine ├── for-loop.pine ├── greeffer-bb-strategy-0.pine ├── greeffer-bb-strategy-1.pine ├── greeffer-bb-strategy-2.pine ├── greeffer-bb-strategy-3.pine ├── greeffer-bb-strategy-4.pine ├── greeffer-bb-strategy.pine ├── greeffer-rsi.pine ├── label-new.pine ├── package.json ├── pivot-popints.pine ├── rsi-bb-1min-v0.pine ├── rsi-bb-1min-v1.pine ├── tradingview-lightweight-charts.js ├── vol-bbw-rsi-15m.pine └── vol-bbw-rsi-15m.png /BB-2020.js: -------------------------------------------------------------------------------- 1 | //@version=4 2 | study(shorttitle="BB", title="BB-2020", overlay=true) 3 | length = input(20, minval=1) 4 | src = input(close, title="Source") 5 | mult = input(2.0, minval=0.001, maxval=50) 6 | basis = sma(src, length) 7 | dev = mult * stdev(src, length) 8 | upper = basis + dev 9 | lower = basis - dev 10 | x = basis * 0.006 11 | upperavg = basis + x 12 | loweravg = basis - x 13 | plot(upperavg, color=color.red, style=plot.style_stepline, title="upperavg", transp=45) 14 | plot(loweravg, color=color.red, style=plot.style_stepline, title="loweravg", transp=45) 15 | plot(basis, color=color.red, style=plot.style_stepline, title="basis") 16 | p1 = plot(upper, color=color.blue, title="upper") 17 | p2 = plot(lower, color=color.blue, title="lower") 18 | fill(p1, p2) -------------------------------------------------------------------------------- /BBW-RSI-60-Strategy.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Greeffer 3 | // github.com/modster or modster.github.io 4 | // 210.14% profit in backtesting. Trading BTCUSDT 60 minute time frame on Binance Spot Exchange 5 | 6 | //@version=4 7 | 8 | // S t u d y 9 | // study('BBW/RSI/60 Study', 'BBW/RSI/60 Study', overlay=true, precision=4) 10 | 11 | // S t r a t e g y 12 | strategy("RSI/BB/60 Strategy", "BBW/RSI/60 Strategy", true, format=format.inherit, 13 | scale=scale.right, precision=5, pyramiding=10, default_qty_type=strategy.percent_of_equity, 14 | default_qty_value=10, initial_capital=100000, currency=currency.USD, 15 | commission_type=strategy.commission.percent, commission_value=0.075, 16 | process_orders_on_close=true, calc_on_every_tick=false) 17 | 18 | // I N P U T 19 | source = close 20 | sell = input(title="Sell", defval=80, minval=0, maxval=100) 21 | buy = input(title="Buy", defval=20, minval=0, maxval=100) 22 | length = input(title="Length", defval=14, minval=1, maxval=500) 23 | 24 | // R S I 25 | myRsi = rsi(source, length) 26 | plot(myRsi, title="myRsi", color=color.blue, display=display.none) 27 | //hline(buy, title='buy', color=color.red, display=display.none) //linestyle=hline.style_dotted, linewidth=1) 28 | //hline(sell, title='sell', color=color.red, display=display.none) //linestyle=hline.style_dotted, linewidth=1) 29 | 30 | // B o l l i n g e r B a n d s 31 | [middle, upper, lower] = bb(source, length, 2) 32 | plot(middle, title="middle", color=color.red, linewidth=2, style=plot.style_line, transp=70) 33 | plot(upper, title="upper", color=color.green, linewidth=2, style=plot.style_line, transp=70) 34 | plot(lower, title="lower", color=color.green, linewidth=2, style=plot.style_line, transp=70) 35 | 36 | // B o l l i n g e r B a n d W i d t h 37 | bbW = bbw(source, length, 2) 38 | plot(bbW, title="bbWidth", color=color.orange, display=display.none) 39 | 40 | // C o n d i t i o n s 41 | buyCondition = crossunder(bbW, 0.01) 42 | sellCondition = cross(source, upper) and myRsi >= sell 43 | stopCondition = crossunder(source, middle) and bbW>0.05 44 | 45 | if(stopCondition) 46 | strategy.close("long", when=strategy.position_size > 0, comment="stop", qty_percent=100) 47 | 48 | if(buyCondition) 49 | strategy.entry("long", strategy.long, qty=100, stop=lower, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size <= 0) 50 | 51 | if(sellCondition) 52 | strategy.order("short", strategy.short, qty=10, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=myRsi>=95) 53 | strategy.order("short", strategy.short, qty=20, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=myRsi>=80) 54 | strategy.order("short", strategy.short, qty=10, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size>40) 55 | 56 | // B U Y 57 | //alertcondition(buyCondition, title='Buy', message='{"direction":"buy","close":"{{close}}","time":"{{time}}"}') 58 | 59 | // S E L L 60 | //alertcondition(sellCondition, title='Sell', message='{"direction":"sell","close":"{{close}}","time":"{{time}}"}') 61 | 62 | // S T O P 63 | //alertcondition(stopCondition, title='Stop', message='{"direction":"stop","close":"{{close}}","time":"{{time}}"}') -------------------------------------------------------------------------------- /BBW-RSI-60-Study.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Greeffer 3 | // github.com/modster or modster.github.io 4 | // 210.14% profit in backtesting. Trading BTCUSDT 60 minute time frame on Binance Spot Exchange 5 | //@version=4 6 | 7 | // S t u d y 8 | study('BBW/RSI/60 Study', 'BBW/RSI/60 Study', overlay=true, precision=4) 9 | 10 | // V a r i a b l e s 11 | source = close 12 | sell = input(title="Sell", defval=75, minval=0, maxval=100) 13 | buy = input(title="Buy", defval=25, minval=0, maxval=100) 14 | length = input(title="Length", defval=14, minval=1, maxval=500) 15 | 16 | // R S I 17 | myRsi = rsi(source, length) 18 | plot(myRsi, title="myRsi", color=color.blue, display=display.none) 19 | //hline(buy, title='buy', color=color.red, display=display.none) //linestyle=hline.style_dotted, linewidth=1) 20 | //hline(sell, title='sell', color=color.red, display=display.none) //linestyle=hline.style_dotted, linewidth=1) 21 | 22 | // B o l l i n g e r B a n d s 23 | [middle, upper, lower] = bb(source, length, 2) 24 | plot(middle, title="middle", color=color.red, linewidth=2, style=plot.style_line, transp=70) 25 | plot(upper, title="upper", color=color.green, linewidth=2, style=plot.style_line, transp=70) 26 | plot(lower, title="lower", color=color.green, linewidth=2, style=plot.style_line, transp=70) 27 | 28 | // B o l l i n g e r B a n d W i d t h 29 | bbW = bbw(source, length, 2) 30 | plot(bbW, title="bbWidth", color=color.orange, display=display.none) 31 | 32 | // C o n d i t i o n s 33 | buyCondition = crossunder(bbW, 0.01) 34 | sellCondition = cross(source, upper) and myRsi >= sell 35 | stopCondition = crossunder(source, middle) and bbW>0.05 36 | 37 | if(stopCondition) 38 | //strategy.close(id, when, comment, qty, qty_percent) 39 | strategy.close("long", when=strategy.position_size > 0, comment="stop", qty_percent=100) 40 | 41 | if(buyCondition) 42 | // strategy.entry(id, long, qty, limit, stop, oca_name, oca_type, comment, when) 43 | strategy.entry("long", strategy.long, qty=100, stop=lower, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size <= 0) 44 | 45 | if(sellCondition) 46 | // strategy.order(id, long, qty, limit, stop, oca_name, oca_type, comment, when) 47 | strategy.order("short", strategy.short, qty=10, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=myRsi>=95) 48 | strategy.order("short", strategy.short, qty=20, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=myRsi>=80) 49 | strategy.order("short", strategy.short, qty=10, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size>40) 50 | 51 | // B u y 52 | alertcondition(buyCondition, title='Buy', message='{"direction":"buy","close":"{{close}}","time":"{{time}}"}') 53 | 54 | // S e l l 55 | alertcondition(sellCondition, title='Sell', message='{"direction":"sell","close":"{{close}}","time":"{{time}}"}') 56 | 57 | // S t o p 58 | alertcondition(stopCondition, title='Stop', message='{"direction":"stop","close":"{{close}}","time":"{{time}}"}') -------------------------------------------------------------------------------- /StochRSI-Vol.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SammyEnigma/pine-scripts/26dbe7fc88cb7960a48a46c54e5d2f609293614e/StochRSI-Vol.png -------------------------------------------------------------------------------- /bb-rsi-15m-3.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Greeffer 3 | // 70% on 15min trading btcusdt 4 | //@version=4 5 | //study("RSI/BB 1minute Study", shorttitle="BBW/RSI/1m", precision=5) 6 | strategy("RSI/BB 1minute Study", "BBW/RSI/1m", false, format=format.inherit, 7 | scale=scale.right, precision=5, pyramiding=20, default_qty_type=strategy.percent_of_equity, 8 | default_qty_value=10, initial_capital=100000, currency=currency.USD, 9 | commission_type=strategy.commission.percent, commission_value=0.075, 10 | process_orders_on_close=true, calc_on_every_tick=false) 11 | 12 | // R S I 13 | source = close 14 | sell = input(title="Sell", defval=75, minval=0, maxval=100) 15 | buy = input(title="Buy", defval=25, minval=0, maxval=100) 16 | length = input(title="Length", defval=14, minval=1, maxval=500) 17 | myRsi = rsi(source, length) 18 | plot(myRsi, title="myRsi", color=color.blue, linewidth=2, style=plot.style_line, transp=70) 19 | hline(buy, title='buy', color=color.red, linestyle=hline.style_dotted, linewidth=1) 20 | hline(sell, title='sell', color=color.red, linestyle=hline.style_dotted, linewidth=1) 21 | 22 | // B o l i n g e r B a n d s 23 | [middle, upper, lower] = bb(source, length, 2) 24 | plot(middle, title="middle", color=color.red, display=display.none) 25 | plot(upper, title="upper", color=color.green, display=display.none) 26 | plot(lower, title="lower", color=color.green, display=display.none) 27 | 28 | // B o l l i n g e r B a n d W i d t h 29 | bbWidth = bbw(source, length, 2) 30 | plot(bbWidth, title="bbWidth", color=color.orange, display=display.none) 31 | 32 | // S t r a t e g i e s 33 | x = strategy.position_avg_price + strategy.position_avg_price*0.15 34 | buyCondition = crossunder(source, lower) and myRsi <= buy 35 | sellCondition = cross(source, upper) and myRsi >= sell 36 | 37 | if(buyCondition) 38 | // strategy.entry(id, long, qty, limit, stop, oca_name, oca_type, comment, when) 39 | strategy.entry("long", strategy.long, qty=100, stop=x, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size <= 0) 40 | 41 | if(sellCondition) 42 | // strategy.order(id, long, qty, limit, stop, oca_name, oca_type, comment, when) 43 | strategy.order("short", strategy.short, qty=5, stop=x, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size > 80) 44 | strategy.order("short", strategy.short, qty=5, stop=x, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size > 50) 45 | strategy.order("short", strategy.short, qty=5, stop=x, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size > 0) 46 | //strategy.close(id, when, comment, qty, qty_percent) 47 | 48 | 49 | //if(close < x) // + strategy.position_avg_price * 0.05) 50 | //strategy.max_drawdown 51 | // strategy.close(id, when, comment, qty, qty_percent) 52 | // strategy.close("long", when=strategy.position_size>0, comment="NOPE",qty_percent=100) 53 | 54 | //strategy.exit(id, from_entry, qty, qty_percent, profit, limit, loss, stop, trail_price, trail_points, trail_offset, oca_name, comment, when) 55 | //strategy.exit("long0", oca_name="long0", stop=stopX, when=strategy.position_size>0) 56 | 57 | // A l e r t c o n d i t i o n s 58 | //alertcondition(crossunder(myRsi, buy) and crossunder(close, lower), title='Buy', message='{"direction":"buy","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 59 | //alertcondition(crossover(myRsi, sell) and crossover(close, upper), title='Sell', message='{"direction":"sell","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 60 | -------------------------------------------------------------------------------- /bb-rsi-1m-3.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Greeffer 3 | // 13.89% profit on 1m frame 4 | //@version=4 5 | //study("RSI/BB 1minute Study", shorttitle="BBW/RSI/1m", precision=5) 6 | strategy("RSI/BB 1minute Study", "BBW/RSI/1m", false, format=format.inherit, 7 | scale=scale.right, precision=5, pyramiding=20, default_qty_type=strategy.percent_of_equity, 8 | default_qty_value=5, initial_capital=100000, currency=currency.USD, 9 | commission_type=strategy.commission.percent, commission_value=0.075, 10 | process_orders_on_close=true, calc_on_every_tick=false) 11 | 12 | // R S I 13 | source = close 14 | sell = input(title="Sell", defval=70, minval=0, maxval=100) 15 | buy = input(title="Buy", defval=30, minval=0, maxval=100) 16 | length = input(title="Length", defval=14, minval=1, maxval=500) 17 | myRsi = rsi(source, length) 18 | plot(myRsi, title="myRsi", color=color.blue, linewidth=2, style=plot.style_line, transp=70) 19 | hline(buy, title='buy', color=color.red, linestyle=hline.style_dotted, linewidth=1) 20 | hline(sell, title='sell', color=color.red, linestyle=hline.style_dotted, linewidth=1) 21 | 22 | // B o l i n g e r B a n d s 23 | //bBands = bb(close, length, mult) 24 | [middle, upper, lower] = bb(source, length, 2) 25 | plot(middle, title="middle", color=color.red, display=display.none) 26 | plot(upper, title="upper", color=color.green, display=display.none) 27 | plot(lower, title="lower", color=color.green, display=display.none) 28 | 29 | // B o l l i n g e r B a n d W i d t h 30 | bbWidth = bbw(source, length, 2) 31 | plot(bbWidth, title="bbWidth", color=color.orange, display=display.none) 32 | 33 | // S t r a t e g i e s 34 | x = strategy.position_avg_price + strategy.position_avg_price*0.1 35 | 36 | if(crossunder(source, lower) and crossunder(myRsi, buy)) 37 | // strategy.entry(id, long, qty, limit, stop, oca_name, oca_type, comment, when) 38 | strategy.entry("long0", strategy.long, qty=100, stop=x, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size <= 0) 39 | if(crossover(source, upper) and myRsi > 60) 40 | //strategy.exit(id, from_entry, qty, qty_percent, profit, limit, loss, stop, trail_price, trail_points, trail_offset, oca_name, comment, when) 41 | strategy.exit("longo", oca_name="long0", stop=x, trail_price=middle, trail_offset=2, when=strategy.position_size>0) 42 | 43 | // A l e r t c o n d i t i o n s 44 | //alertcondition(crossunder(myRsi, buy) and crossunder(close, lower), title='Buy', message='{"direction":"buy","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 45 | //alertcondition(crossover(myRsi, sell) and crossover(close, upper), title='Sell', message='{"direction":"sell","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 46 | -------------------------------------------------------------------------------- /bb-rsi-1m-4.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Greeffer 3 | // profit 30.4% trading btc on 1m 4 | //@version=4 5 | //study("RSI/BB 1minute Study", shorttitle="BBW/RSI/1m", precision=5) 6 | strategy("RSI/BB 1minute Study", "BBW/RSI/1m", false, format=format.inherit, 7 | scale=scale.right, precision=5, pyramiding=20, default_qty_type=strategy.percent_of_equity, 8 | default_qty_value=10, initial_capital=100000, currency=currency.USD, 9 | commission_type=strategy.commission.percent, commission_value=0.075, 10 | process_orders_on_close=true, calc_on_every_tick=false) 11 | 12 | // R S I 13 | source = close 14 | sell = input(title="Sell", defval=75, minval=0, maxval=100) 15 | buy = input(title="Buy", defval=25, minval=0, maxval=100) 16 | length = input(title="Length", defval=14, minval=1, maxval=500) 17 | myRsi = rsi(source, length) 18 | plot(myRsi, title="myRsi", color=color.blue, linewidth=2, style=plot.style_line, transp=70) 19 | hline(buy, title='buy', color=color.red, linestyle=hline.style_dotted, linewidth=1) 20 | hline(sell, title='sell', color=color.red, linestyle=hline.style_dotted, linewidth=1) 21 | 22 | // B o l i n g e r B a n d s 23 | [middle, upper, lower] = bb(source, length, 2) 24 | plot(middle, title="middle", color=color.red, display=display.none) 25 | plot(upper, title="upper", color=color.green, display=display.none) 26 | plot(lower, title="lower", color=color.green, display=display.none) 27 | 28 | // B o l l i n g e r B a n d W i d t h 29 | bbWidth = bbw(source, length, 2) 30 | plot(bbWidth, title="bbWidth", color=color.orange, display=display.none) 31 | 32 | // S t r a t e g i e s 33 | x = strategy.position_avg_price + strategy.position_avg_price*0.05 34 | //x = close - 200 35 | buyCondition = crossunder(source, lower) and myRsi <= buy 36 | sellCondition = cross(source, upper) and myRsi >= sell 37 | 38 | if(buyCondition) 39 | // strategy.entry(id, long, qty, limit, stop, oca_name, oca_type, comment, when) 40 | strategy.entry("long", strategy.long, qty=100, stop=x, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size <= 0) 41 | if(sellCondition) 42 | // strategy.order(id, long, qty, limit, stop, oca_name, oca_type, comment, when) 43 | strategy.order("short", strategy.short, qty=5, stop=x, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size > 80) 44 | strategy.order("short", strategy.short, qty=5, stop=x, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size > 50) 45 | strategy.order("short", strategy.short, qty=5, stop=x, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size > 0) 46 | //strategy.close(id, when, comment, qty, qty_percent) 47 | 48 | //if(close < x) // + strategy.position_avg_price * 0.05) 49 | //strategy.max_drawdown 50 | // strategy.close(id, when, comment, qty, qty_percent) 51 | // strategy.close("long", when=strategy.position_size>0, comment="NOPE",qty_percent=100) 52 | 53 | //strategy.exit(id, from_entry, qty, qty_percent, profit, limit, loss, stop, trail_price, trail_points, trail_offset, oca_name, comment, when) 54 | //strategy.exit("long0", oca_name="long0", stop=stopX, when=strategy.position_size>0) 55 | 56 | // A l e r t c o n d i t i o n s 57 | //alertcondition(crossunder(myRsi, buy) and crossunder(close, lower), title='Buy', message='{"direction":"buy","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 58 | //alertcondition(crossover(myRsi, sell) and crossover(close, upper), title='Sell', message='{"direction":"sell","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 59 | -------------------------------------------------------------------------------- /bb-rsi.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 3 | // © Greeffer 4 | strategy("Greeffer RSI Strategy", "Greeffer", true, format=format.volume, scale=scale.right, precision=0, pyramiding=5, default_qty_type=strategy.percent_of_equity, default_qty_value=2, initial_capital=100000, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.075, process_orders_on_close=true) 5 | 6 | source = close 7 | length = input(20, minval=1) 8 | mult = input(2.0, minval=0.001, maxval=50) 9 | 10 | basis = sma(source, length) 11 | dev = mult * stdev(source, length) 12 | 13 | upper = basis + dev 14 | lower = basis - dev 15 | 16 | buyEntry = crossover(source, lower) 17 | sellEntry = crossunder(source, upper) 18 | 19 | // R S I 20 | myRsi = rsi(close, 14) 21 | //plot(myRsi, title="myRsi", color=color.blue, linewidth=2, style=plot.style_line, transp=70) 22 | //hline(31, title='oversold', color=color.red, linestyle=hline.style_dotted, linewidth=1) 23 | //hline(69, title='overbought', color=color.red, linestyle=hline.style_dotted, linewidth=1) 24 | 25 | if (crossover(source, lower)) 26 | strategy.entry("BBandRsiLE", strategy.long, stop=lower, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandLE") 27 | else 28 | strategy.cancel(id="BBandLE") 29 | 30 | if (crossunder(source, upper)) 31 | strategy.entry("BBandSE", strategy.short, stop=upper, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandSE") 32 | else 33 | strategy.cancel(id="BBandSE") 34 | 35 | //plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr) 36 | 37 | // L o n g C o n d i t i o n 38 | longCondition = myRsi <= 29 and close > lower 39 | 40 | if (longCondition) 41 | strategy.entry("RsiBuy", true, 2, oca_name="Rsi069", oca_type=strategy.oca.reduce) 42 | // strategy.entry("RsiBuy", true, 2) 43 | // strategy.entry("RsiBuy", true, 1, limit, stop, oca_name="Rsi069", oca_type=strategy.oca.reduce, comment="rsiLong", when=open > high[1]) 44 | 45 | // S h o r t C o n d i t i o n 46 | shortCondition = myRsi >= 70 47 | if (shortCondition) 48 | strategy.entry("Rsi Sell", false, 2,2, oca_name="Rsi069", oca_type=strategy.oca.reduce) -------------------------------------------------------------------------------- /bollinger-bands-strategy.js: -------------------------------------------------------------------------------- 1 | //@version=4 2 | strategy("Bollinger Bands Strategy", overlay=true) 3 | source = close 4 | length = input(20, minval=1) 5 | mult = input(2.0, minval=0.001, maxval=50) 6 | 7 | basis = sma(source, length) 8 | dev = mult * stdev(source, length) 9 | 10 | upper = basis + dev 11 | lower = basis - dev 12 | x = basis * 0.006 13 | basisPlus = basis + x 14 | basisMinus = basis - x 15 | 16 | buyEntry = crossunder(upper, basisPlus) 17 | sellEntry = crossover(source, upper) 18 | 19 | if (crossunder(upper, basisPlus)) 20 | strategy.entry("BBandLE", strategy.long, stop=lower, oca_name="BollingerBands", oca_type=strategy.oca.none, comment="BBandLE") 21 | else 22 | strategy.cancel(id="BBandLE") 23 | 24 | if (crossover(source, upper)) 25 | strategy.entry("BBandSE", strategy.short, stop=upper, oca_name="BollingerBands", oca_type=strategy.oca.none, comment="BBandSE") 26 | else 27 | strategy.cancel(id="BBandSE") 28 | 29 | //plot(rsi(close, 14), title="rsi", color=color.white, linewidth=1, style=plot.style_line, transp=20) 30 | plot(upper, title="upper", color=color.yellow, linewidth=1, style=plot.style_line, transp=20) 31 | plot(lower, title="lower", color=color.yellow, linewidth=1, style=plot.style_line, transp=20) 32 | plot(basis, title="basis", color=color.blue, linewidth=1, style=plot.style_line, transp=20) 33 | plot(basisPlus, title="basisPlus", color=color.red, linewidth=1, style=plot.style_stepline, transp=20) 34 | plot(basisMinus, title="basisMinus", color=color.red, linewidth=1, style=plot.style_stepline, transp=20) 35 | //plot(strategy.netprofit, title="netprofit", color=color.red, linewidth=1, style=plot.style_stepline) 36 | -------------------------------------------------------------------------------- /colors.pine: -------------------------------------------------------------------------------- 1 | color.black, color.silver, color.gray, color.white, color.maroon, color.red, color.purple, color.fuchsia, color.green, color.lime, color.olive, color.yellow, color.navy, color.blue, color.teal, color.aqua, color.orange -------------------------------------------------------------------------------- /for-loop.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | study("For loop") 3 | my_sma(price, length) => 4 | sum = price 5 | for i = 1 to length-1 6 | sum := sum + price[i] 7 | sum / length 8 | plot(my_sma(close,14)) -------------------------------------------------------------------------------- /greeffer-bb-strategy-0.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 3 | // © Greeffer 4 | // 04-11-2020: 5.7% profit in backtests trading BTCUSDTPERP on 1m time frame (no leverage) 5 | 6 | strategy("Greeffer BB Strategy", "Greeffer", false, format=format.price, scale=scale.right, precision=2, pyramiding=11, default_qty_type=strategy.percent_of_equity, default_qty_value=11, initial_capital=100000, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.075, process_orders_on_close=true) 7 | 8 | source = close 9 | length = input(20, minval=1) 10 | mult = input(2.0, minval=0.001, maxval=50) 11 | 12 | basis = sma(source, length) 13 | dev = mult * stdev(source, length) 14 | 15 | upper = basis + dev 16 | lower = basis - dev 17 | 18 | if (crossover(source, upper)) 19 | strategy.entry("sell", strategy.short, comment="sell", when = rsi(close, 14) > 70) 20 | strategy.close("sell", when= rsi(close, 14) < 30, qty_percent = 100, comment = "close sell 50%") 21 | if (crossunder(source, lower)) 22 | strategy.entry("buy", strategy.long, oca_name="BollingerBands", comment="buy", when = rsi(close, 14) > 30) 23 | strategy.close("buy", when = rsi(close, 14) > 70, qty_percent = 100, comment = "close buy 50%") 24 | //strategy.risk.max_drawdown(3, strategy.percent_of_equity) // set maximum drawdown to 50% of maximum equity 25 | //strategy.close_all(when= , comment="close all") 26 | 27 | plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr) -------------------------------------------------------------------------------- /greeffer-bb-strategy-1.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 3 | // © Greeffer 4 | // 04-11-2020: 422% profit in backtests trading BTCUSDTPERP on 1m time frame (no leverage) 5 | 6 | strategy("Greeffer BB Strategy", "Greeffer", false, format=format.price, scale=scale.right, precision=2, pyramiding=50, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100000, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.075, process_orders_on_close=true) 7 | 8 | source = close 9 | length = input(20, minval=1) 10 | mult = input(2.0, minval=0.001, maxval=50) 11 | 12 | basis = sma(source, length) 13 | dev = mult * stdev(source, length) 14 | 15 | upper = basis + dev 16 | lower = basis - dev 17 | 18 | if (crossover(source, upper)) 19 | strategy.entry("sell", strategy.short, comment="sell", when = rsi(close, 14) > 70) 20 | strategy.close("sell", when= rsi(close, 14) < 30, qty_percent = 100, comment = "close sell 50%") 21 | if (crossunder(source, lower)) 22 | strategy.entry("buy", strategy.long, oca_name="BollingerBands", comment="buy", when = rsi(close, 14) > 30) 23 | strategy.close("buy", when = rsi(close, 14) > 70, qty_percent = 100, comment = "close buy 50%") 24 | //strategy.risk.max_drawdown(3, strategy.percent_of_equity) // set maximum drawdown to 50% of maximum equity 25 | //strategy.close_all(when= , comment="close all") 26 | 27 | plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr) -------------------------------------------------------------------------------- /greeffer-bb-strategy-2.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 3 | // © Greeffer 4 | // 04-11-2020: 115% profit in backtests trading BTCUSDTPERP on 30m time frame (no leverage) 5 | 6 | strategy("Greeffer BB Strategy", "Greeffer", false, format=format.price, scale=scale.right, precision=2, pyramiding=10, default_qty_type=strategy.percent_of_equity, default_qty_value=25, initial_capital=1000, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.075, process_orders_on_close=false) 7 | 8 | source = close 9 | length = input(20, minval=1) 10 | mult = input(2.0, minval=0.001, maxval=50) 11 | 12 | basis = sma(source, length) 13 | dev = mult * stdev(source, length) 14 | 15 | upper = basis + dev 16 | lower = basis - dev 17 | 18 | 19 | if (crossover(source, upper)) 20 | strategy.entry("sell", strategy.short, comment="sell", when=rsi(close, 14) > 70) 21 | strategy.close("sell", when= rsi(close, 14) < 30, qty_percent = 50, comment = "close sell 50%") 22 | if (crossunder(source, lower)) 23 | strategy.entry("buy", strategy.long, oca_name="BollingerBands", comment="buy", when = rsi(close, 14) < 30) 24 | strategy.close("buy", when = rsi(close, 14) > 70, qty_percent = 50, comment = "close buy 50%") 25 | //strategy.risk.max_drawdown(3, strategy.percent_of_equity) // set maximum drawdown to 50% of maximum equity 26 | //strategy.close_all(when= , comment="close all") 27 | 28 | plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr) -------------------------------------------------------------------------------- /greeffer-bb-strategy-3.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 3 | // © Greeffer 4 | // 04-11-2020: 58% profit in backtests trading BTCUSDTPERP on 15m time frame (no leverage). Lower risk, higher time frome - good compromise. 5 | 6 | strategy("Greeffer BB Strategy", "Greeffer", false, format=format.price, scale=scale.right, precision=2, pyramiding=10, default_qty_type=strategy.percent_of_equity, default_qty_value=15, initial_capital=1000, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.075, process_orders_on_close=true) 7 | 8 | source = close 9 | length = input(20, minval=1) 10 | mult = input(2.0, minval=0.001, maxval=50) 11 | 12 | basis = sma(source, length) 13 | dev = mult * stdev(source, length) 14 | 15 | upper = basis + dev 16 | lower = basis - dev 17 | 18 | if (crossover(source, upper)) 19 | strategy.entry("sell", strategy.short, comment="sell", when=rsi(close, 14)>80) 20 | strategy.close("sell", when=crossunder(source, lower), comment = "close sell") 21 | 22 | if (crossunder(source, lower)) 23 | strategy.entry("buy", strategy.long, oca_name="BollingerBands", comment="buy", when=rsi(close, 14)>30) 24 | strategy.close("buy", when=crossover(source, upper), comment = "close buy") 25 | 26 | //strategy.risk.max_drawdown(3, strategy.percent_of_equity) // set maximum drawdown to 50% of maximum equity 27 | //strategy.close_all(when= , comment="close all") 28 | 29 | plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr) -------------------------------------------------------------------------------- /greeffer-bb-strategy-4.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 3 | // © Greeffer 4 | // 5 | strategy("Greeffer BB Strategy", "Greeffer", false, format=format.price, scale=scale.right, precision=2, pyramiding=10, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=1000, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.075, process_orders_on_close=true) 6 | source = close 7 | length = input(20, minval=1) 8 | rsiLength = input(14, minval=1) 9 | mult = input(1.9, minval=0.001, maxval=50) 10 | basis = sma(source, length) 11 | dev = mult * stdev(source, length) 12 | upper = basis + dev 13 | lower = basis - dev 14 | 15 | x = bbw(source, length, 2.1) 16 | plot(bbw(source, length, 2.5), title="bb width", color=color.yellow) 17 | if (x<0.01) 18 | strategy.entry("buy", strategy.long, comment="buyx", when=rsi(close, rsiLength)<30) 19 | //strategy.close("buy", when=rsi(close, 14)>80, comment = "close sell") 20 | 21 | if (crossover(source, upper)) 22 | strategy.entry("sell", strategy.short, comment="sell", when=rsi(close, rsiLength)>80) 23 | strategy.close("sell", when=crossunder(source, lower), comment = "close sell") 24 | 25 | if (crossunder(source, lower)) 26 | strategy.entry("buy", strategy.long, comment="buy", when=rsi(close, rsiLength)>30) 27 | strategy.close("buy", when=crossover(source, upper), comment = "close buy") 28 | 29 | 30 | //plot(bbw(close, 20, 2), color=color.yellow) 31 | 32 | 33 | //bb(series, length, mult) 34 | 35 | //strategy.risk.max_drawdown(3, strategy.percent_of_equity) // set maximum drawdown to 50% of maximum equity 36 | //strategy.close_all(when= , comment="close all") 37 | 38 | // plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr) -------------------------------------------------------------------------------- /greeffer-bb-strategy.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 3 | // © Greeffer 4 | // 04-11-2020: 1.4% profit in backtests 5 | strategy("Greeffer BB Strategy", "Greeffer", false, format=format.price, scale=scale.right, precision=2, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=11, initial_capital=100000, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.075, process_orders_on_close=true) 6 | 7 | source = close 8 | length = input(20, minval=1) 9 | mult = input(2.0, minval=0.001, maxval=50) 10 | 11 | basis = sma(source, length) 12 | dev = mult * stdev(source, length) 13 | 14 | upper = basis + dev 15 | lower = basis - dev 16 | 17 | if (crossover(source, upper)) 18 | strategy.entry("sell", strategy.short, comment="sell", when = rsi(close, 14) > 75) 19 | strategy.close("sell", when= rsi(close, 14) < 30, qty_percent = 100, comment = "close sell 50%") 20 | if (crossunder(source, lower)) 21 | strategy.entry("buy", strategy.long, oca_name="BollingerBands", comment="buy", when = rsi(close, 14) > 25) 22 | strategy.close("buy", when = rsi(close, 14) > 70, qty_percent = 100, comment = "close buy 50%") 23 | //strategy.risk.max_drawdown(15, strategy.percent_of_equity) // set maximum drawdown to 50% of maximum equity 24 | //strategy.close_all(when= , comment="close all") 25 | 26 | plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr) -------------------------------------------------------------------------------- /greeffer-rsi.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Greeffer 3 | 4 | //@version=4 5 | strategy(title="Greeffer RSI Strategy", shorttitle="GRsi", overlay=false) 6 | 7 | // R S I 8 | myRsi = rsi(close, 14) 9 | plot(myRsi, title="myRsi", color=color.blue, linewidth=2, style=plot.style_line, transp=70) 10 | hline(29, title='oversold', color=color.red, linestyle=hline.style_dotted, linewidth=1) 11 | hline(70, title='overbought', color=color.red, linestyle=hline.style_dotted, linewidth=1) 12 | 13 | // L o n g C o n d i t i o n 14 | longCondition = myRsi <= 29 15 | if (longCondition) 16 | strategy.entry("RsiBuy", strategy.long) 17 | alertcondition(longCondition, title='Buy Rsi', message='Rsi={{myRsi}}') 18 | 19 | // S h o r t C o n d i t i o n 20 | shortCondition = myRsi >= 70 21 | if (shortCondition) 22 | strategy.entry("RsiSell", strategy.short) 23 | alertcondition(shortCondition, title='Sell Rsi', message='Rsi={{myRsi}}') -------------------------------------------------------------------------------- /label-new.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | study("My Script", overlay=true) 3 | label.new(bar_index, high) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pine-scripts", 3 | "version": "1.0.0", 4 | "description": "A personal collection of pine scripts and strategies.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/modster/pine-scripts.git" 12 | }, 13 | "keywords": [ 14 | "tradingview", 15 | "pine", 16 | "strategy", 17 | "study", 18 | "algo", 19 | "trade" 20 | ], 21 | "author": "modster", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/modster/pine-scripts/issues" 25 | }, 26 | "homepage": "https://github.com/modster/pine-scripts#readme" 27 | } 28 | -------------------------------------------------------------------------------- /pivot-popints.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © LonesomeTheBlue 3 | 4 | //@version=4 5 | study("Price Change Rate by Pivot Points - Dynamic", overlay=true, max_bars_back = 2000) 6 | prd = input(defval = 30, title="Pivot Point Period", minval = 5, maxval = 100) 7 | showpivot = input(defval = true, title="Show Pivot Points") 8 | showret = input(defval = true, title="Show retracement") 9 | showprice = input(defval = false, title="Show Prices") 10 | showline = input(defval = true, title="Show Lines") 11 | showoncurr = input(defval = false, title="Show Label on current High/Low") 12 | 13 | 14 | float ph = na, float pl = na 15 | ph := pivothigh(prd, prd) 16 | pl := pivotlow(prd, prd) 17 | 18 | plotshape(ph and showpivot, text="H", style=shape.labeldown, color=na, textcolor=color.blue, location=location.abovebar, transp=0, offset = -prd) 19 | plotshape(pl and showpivot, text="L", style=shape.labeldown, color=na, textcolor=color.blue, location=location.belowbar, transp=0, offset = -prd) 20 | 21 | _highest(len) => 22 | _hi = high 23 | _hloc = 0 24 | for i = 1 to len -1 25 | if na(high[i]) 26 | break 27 | if nz(high[i]) > _hi 28 | _hi := nz(high[i]) 29 | _hloc := i 30 | [_hi, _hloc] 31 | 32 | _lowest(len) => 33 | _lo = low 34 | _hloc = 0 35 | for i = 1 to len -1 36 | if na(low[i]) 37 | break 38 | if nz(low[i]) < _lo 39 | _lo := nz(low[i]) 40 | _hloc := i 41 | [_lo, _hloc] 42 | 43 | 44 | hcont = true 45 | hcont := pl ? false : nz(hcont[1], true) 46 | lcont = true 47 | lcont := ph ? false : nz(lcont[1], true) 48 | 49 | float lastphi = na, float lastplo = na 50 | hiloc = 0, loloc = 0 51 | lastphi := nz(lastphi[1]) 52 | lastplo := nz(lastplo[1]) 53 | hiloc := nz(hiloc[1]) + 1 54 | loloc := nz(loloc[1]) + 1 55 | hchg = false 56 | if ph 57 | if (hcont and lastphi != 0 and ph > lastphi) or not hcont 58 | hchg := (hcont and lastphi != 0 and ph > lastphi) 59 | lastphi := ph 60 | hiloc := prd 61 | hcont := true 62 | 63 | lchg = false 64 | if pl 65 | if (lcont and lastplo != 0 and pl < lastplo) or not lcont 66 | lchg := (lcont and lastplo != 0 and pl < lastplo) 67 | lastplo := pl 68 | loloc := prd 69 | lcont := true 70 | 71 | [lwd, h_locd] = _lowest(hiloc) 72 | var line lnd = na 73 | var label lbd = na 74 | if hiloc != 0 and lastphi != 0 75 | if change(lastphi) == 0 or hchg 76 | line.delete(lnd) 77 | label.delete(lbd) 78 | if showline 79 | lnd := line.new(bar_index - hiloc, lastphi, showoncurr ? bar_index - h_locd : bar_index - hiloc, lwd, color = color.red, style = line.style_arrow_right) 80 | prctxt = showprice ? tostring(lastphi) + "\n" + tostring(lwd) + "\n" : "" 81 | ret = "" 82 | ret := ret[1] 83 | ret := showret ? hcont ? tostring((lastphi - lwd) / (lastphi - lastplo), '#.###') + "\n" : ret : "" 84 | txt = prctxt + ret + "-% " + tostring(((lastphi - lwd) / lastphi) * 100, '#.#') 85 | lbd := label.new(showoncurr ? bar_index - h_locd : bar_index - hiloc, lwd, text = txt, color = color.red, textcolor = color.white, style = label.style_label_up) 86 | 87 | 88 | [lwu, h_locu] = _highest(loloc) 89 | var line lnu = na 90 | var label lbu = na 91 | if loloc != 0 and lastplo != 0 92 | if change(lastplo) == 0 or lchg 93 | line.delete(lnu) 94 | label.delete(lbu) 95 | if showline 96 | lnu := line.new(bar_index - loloc, lastplo, showoncurr ? bar_index - h_locu : bar_index - loloc, lwu, color = color.lime, style = line.style_arrow_right) 97 | prctxt = showprice ? tostring(lastplo) + "\n" + tostring(lwu) + "\n" : "" 98 | ret = "" 99 | ret := ret[1] 100 | ret := showret ? lcont ? tostring((lwu - lastplo) / (lastphi - lastplo), '#.###') + "\n" : ret : "" 101 | txt = prctxt + ret + "+% " + tostring(((lwu - lastplo) / lastplo) * 100, '#.#') 102 | lbu := label.new(showoncurr ? bar_index - h_locu : bar_index - loloc, lwu, text = txt, color = color.lime, textcolor = color.black, style = label.style_label_down) 103 | -------------------------------------------------------------------------------- /rsi-bb-1min-v0.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Greeffer 3 | 4 | //@version=4 5 | strategy("RSI/BB 1minute Study", "BBW/RSI/1m", false, format=format.inherit, 6 | scale=scale.right, precision=5, pyramiding=4, default_qty_type=strategy.cash, 7 | default_qty_value=20, initial_capital=1000, currency=currency.USD, 8 | commission_type=strategy.commission.percent, commission_value=0.075, 9 | process_orders_on_close=false, calc_on_every_tick=false) 10 | 11 | // R S I 12 | source = close 13 | sell = input(title="Sell", defval=75, minval=0, maxval=100) 14 | buy = input(title="Buy", defval=34, minval=0, maxval=100) 15 | length = input(title="Length", defval=14, minval=1, maxval=500) 16 | myRsi = rsi(source, length) 17 | plot(myRsi, title="myRsi", color=color.blue, linewidth=2, style=plot.style_line, transp=70) 18 | hline(buy, title='buy', color=color.red, linestyle=hline.style_dotted, linewidth=1) 19 | hline(sell, title='sell', color=color.red, linestyle=hline.style_dotted, linewidth=1) 20 | 21 | // B o l i n g e r B a n d s 22 | //bBands = bb(close, length, mult) 23 | [middle, upper, lower] = bb(source, length, 2) 24 | plot(middle, title="middle", color=color.red, display=display.none) 25 | plot(upper, title="upper", color=color.green, display=display.none) 26 | plot(lower, title="lower", color=color.green, display=display.none) 27 | 28 | // B o l l i n g e r B a n d W i d t h 29 | bbWidth = bbw(source, length, 2) 30 | plot(bbWidth, title="bbWidth", color=color.orange, display=display.none) 31 | 32 | // S t r a t e g i e s 33 | //if(bbWidth<0.004) 34 | if (crossunder(myRsi, buy) and cross(source, lower)) 35 | //strategy.entry(id, long, qty, limit, stop, oca_name, oca_type, comment, when) 36 | strategy.entry("long0", strategy.long, 100, stop=strategy.position_avg_price + 37 | strategy.position_avg_price*0.1, oca_name="long0", 38 | oca_type=strategy.oca.reduce, when=strategy.position_size <= 0) 39 | strategy.exit("long0", oca_name="long0", qty_percent=20, stop=strategy.position_avg_price + 40 | strategy.position_avg_price*0.1, trail_price=upper, trail_offset=2, when=strategy.position_size > 0) 41 | 42 | if (crossover(myRsi, sell) and cross(source, upper)) 43 | //strategy.entry(id, long, qty, limit, stop, oca_name, oca_type, comment, when) 44 | strategy.entry("short0", strategy.short, 100, stop=strategy.position_avg_price + 45 | strategy.position_avg_price*0.1, oca_name="long0", oca_type=strategy.oca.reduce, 46 | when=strategy.position_size > 0) 47 | strategy.exit("short0", oca_name="long0", qty_percent=20, stop=strategy.position_avg_price + 48 | strategy.position_avg_price*0.1, trail_price=lower, trail_offset=2, when=strategy.position_size > 0) 49 | 50 | // A l e r t c o n d i t i o n s 51 | //alertcondition(crossunder(myRsi, buy) and crossunder(close, lower), title='Buy', message='{"direction":"buy","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 52 | //alertcondition(crossover(myRsi, sell) and crossover(close, upper), title='Sell', message='{"direction":"sell","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 53 | -------------------------------------------------------------------------------- /rsi-bb-1min-v1.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Greeffer 3 | 4 | //@version=4 5 | //study("RSI/BB 1minute Study", shorttitle="BBW/RSI/1m", precision=5) 6 | strategy("RSI/BB 1minute Study", "BBW/RSI/1m", false, format=format.inherit, 7 | scale=scale.right, precision=5, pyramiding=20, default_qty_type=strategy.percent_of_equity, 8 | default_qty_value=100, initial_capital=100000, currency=currency.USD, 9 | commission_type=strategy.commission.percent, commission_value=0.075, 10 | process_orders_on_close=true, calc_on_every_tick=false) 11 | 12 | // R S I 13 | source = close 14 | sell = input(title="Sell", defval=75, minval=0, maxval=100) 15 | buy = input(title="Buy", defval=34, minval=0, maxval=100) 16 | length = input(title="Length", defval=14, minval=1, maxval=500) 17 | myRsi = rsi(source, length) 18 | plot(myRsi, title="myRsi", color=color.blue, linewidth=2, style=plot.style_line, transp=70) 19 | hline(buy, title='buy', color=color.red, linestyle=hline.style_dotted, linewidth=1) 20 | hline(sell, title='sell', color=color.red, linestyle=hline.style_dotted, linewidth=1) 21 | 22 | // B o l i n g e r B a n d s 23 | //bBands = bb(close, length, mult) 24 | [middle, upper, lower] = bb(source, length, 2) 25 | plot(middle, title="middle", color=color.red, display=display.none) 26 | plot(upper, title="upper", color=color.green, display=display.none) 27 | plot(lower, title="lower", color=color.green, display=display.none) 28 | 29 | // B o l l i n g e r B a n d W i d t h 30 | bbWidth = bbw(source, length, 2) 31 | plot(bbWidth, title="bbWidth", color=color.orange, display=display.none) 32 | 33 | // S t r a t e g i e s 34 | 35 | if (crossunder(source, lower) and crossunder(myRsi, buy)) 36 | strategy.entry("long0", strategy.long,stop=strategy.position_avg_price + 37 | strategy.position_avg_price*0.1, oca_name="long0", 38 | oca_type=strategy.oca.reduce) 39 | strategy.exit("longo", oca_name="long0", qty_percent=100, stop=strategy.position_avg_price + 40 | strategy.position_avg_price*0.1, trail_price=middle, trail_offset=2) 41 | //strategy.close(id, when, comment, qty, qty_percent) 42 | //strategy.close("short0", when=sourceupper, qty_percent=100) 56 | 57 | // A l e r t c o n d i t i o n s 58 | //alertcondition(crossunder(myRsi, buy) and crossunder(close, lower), title='Buy', message='{"direction":"buy","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 59 | //alertcondition(crossover(myRsi, sell) and crossover(close, upper), title='Sell', message='{"direction":"sell","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 60 | -------------------------------------------------------------------------------- /tradingview-lightweight-charts.js: -------------------------------------------------------------------------------- 1 | import { createChart } from 'lightweight-charts'; 2 | 3 | const chart = createChart(document.body, { width: 400, height: 300 }); 4 | const lineSeries = chart.addLineSeries(); 5 | lineSeries.setData([ 6 | { time: '2019-04-11', value: 80.01 }, 7 | { time: '2019-04-12', value: 96.63 }, 8 | { time: '2019-04-13', value: 76.64 }, 9 | { time: '2019-04-14', value: 81.89 }, 10 | { time: '2019-04-15', value: 74.43 }, 11 | { time: '2019-04-16', value: 80.01 }, 12 | { time: '2019-04-17', value: 96.63 }, 13 | { time: '2019-04-18', value: 76.64 }, 14 | { time: '2019-04-19', value: 81.89 }, 15 | { time: '2019-04-20', value: 74.43 }, 16 | ]); -------------------------------------------------------------------------------- /vol-bbw-rsi-15m.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Greeffer 3 | // github.com/modster or modster.github.io 4 | // Trading BTCUSDT 15 minute time frame on Binance Spot Exchange yeiled 547% return in backtests 5 | 6 | //@version=4 7 | 8 | // S t u d y 9 | // study('VOL/BBW/60 Study', 'VOL/BBW/RSI/1 Strategy', overlay=true, precision=4) 10 | 11 | // S t r a t e g y 12 | strategy("VOL/BBW/RSI/15 Strategy", "VOL/BBW/RSI/15 Strategy", true, format=format.inherit, 13 | scale=scale.right, precision=5, pyramiding=10, default_qty_type=strategy.percent_of_equity, 14 | default_qty_value=10, initial_capital=100000, currency=currency.USD, 15 | commission_type=strategy.commission.percent, commission_value=0.075, 16 | process_orders_on_close=true, calc_on_every_tick=false, max_bars_back=300) 17 | // strategy(title, shorttitle, overlay, format, precision, scale, pyramiding, calc_on_order_fills, calc_on_every_tick, max_bars_back, backtest_fill_limits_assumption, default_qty_type, default_qty_value, initial_capital, currency, slippage, commission_type, commission_value, process_orders_on_close, close_entries_rule) 18 | 19 | // V a r i a b l e s 20 | source = input(close, title="RSI Source") 21 | sell = input(title="Sell", defval=75, minval=0, maxval=100) 22 | buy = input(title="Buy", defval=25, minval=0, maxval=100) 23 | length = input(title="Length", defval=14, minval=1, maxval=500) 24 | volMA = sma(volume,7) 25 | showMA = input(true) 26 | 27 | 28 | // V o l u m e 29 | barColorsOnPrevClose = input(title="Color bars based on previous close", type=input.bool, defval=false) 30 | palette = barColorsOnPrevClose ? close[1] > close ? color.red : color.green : open > close ? color.red : color.green 31 | plot(volume, color = palette, style=plot.style_columns, title="Volume", display=display.none) 32 | plot(showMA ? sma(volume,20) : na, style=plot.style_area, color=color.blue, display=display.none) 33 | 34 | // S t o c h R S I 35 | smoothK = input(3, minval=1) // <----------------------------------------------- 36 | smoothD = input(3, minval=1) // <----------------------------------------------- 37 | lengthRSI = input(14, minval=1) 38 | lengthStoch = input(14, minval=1) 39 | 40 | rsi1 = rsi(source, lengthRSI) 41 | k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK) 42 | d = sma(k, smoothD) 43 | //plot(k, color=color.blue) 44 | //plot(d, color=color.orange) 45 | //h0 = hline(80) 46 | //h1 = hline(20) 47 | //fill(h0, h1, color=color.purple, transp=80, display=display.none) 48 | 49 | // B o l l i n g e r B a n d s 50 | [middle, upper, lower] = bb(source, length, 2.2) 51 | plot(middle, title="middle", color=color.red, linewidth=2, style=plot.style_line, transp=70) 52 | plot(upper, title="upper", color=color.green, linewidth=2, style=plot.style_line, transp=70) 53 | plot(lower, title="lower", color=color.green, linewidth=2, style=plot.style_line, transp=70) 54 | 55 | // B o l l i n g e r B a n d W i d t h 56 | bbW = bbw(source, length, 2.2) 57 | plot(bbW, title="bbWidth", color=color.orange, display=display.none) 58 | 59 | // C o n d i t i o n s 60 | buyCondition = bbW<0.022 and volume>=volMA 61 | //buyCondition = crossover(k, d) and k<25 62 | //buyCondition = K>D and rsi<60 and bbw < 0.022 63 | sellCondition = crossover(close, upper) 64 | stopCondition = crossunder(source, middle) and bbW > 0.05 65 | 66 | if(stopCondition) 67 | strategy.close("long", when=strategy.position_size > 0, comment="stop", qty_percent=100) 68 | 69 | if(buyCondition) 70 | strategy.entry("long", strategy.long, qty=100, stop=lower, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size <= 0) 71 | 72 | if(sellCondition) 73 | strategy.order("short", strategy.short, qty=10, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size > 0) 74 | // strategy.order("short", strategy.short, qty=20, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=rsi1>=80) 75 | // strategy.order("short", strategy.short, qty=10, stop=upper, oca_name="long0", oca_type=strategy.oca.reduce, when=strategy.position_size>40) 76 | 77 | // B U Y 78 | //alertcondition(buyCondition, title='Buy', message='{"direction":"buy","close":"{{close}}","time":"{{time}}"}') 79 | //alertcondition(crossunder(myRsi, buy) and crossunder(close, lower), title='Buy', message='{"direction":"buy","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 80 | 81 | // S E L L 82 | //alertcondition(sellCondition, title='Sell', message='{"direction":"sell","close":"{{close}}","time":"{{time}}"}') 83 | //alertcondition(crossover(myRsi, sell) and crossover(close, upper), title='Sell', message='{"direction":"sell","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}') 84 | 85 | // S T O P 86 | //alertcondition(stopCondition, title='Stop', message='{"direction":"stop","close":"{{close}}","time":"{{time}}"}') 87 | -------------------------------------------------------------------------------- /vol-bbw-rsi-15m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SammyEnigma/pine-scripts/26dbe7fc88cb7960a48a46c54e5d2f609293614e/vol-bbw-rsi-15m.png --------------------------------------------------------------------------------