7-RSI strategy

Hello, I've only been trying to learn PineScript for two months on my own, here I am posting a version of the strategy for a grid bot with 20 orders, order size 5%, earlier I tried to find something similar, but could not. Perhaps others, those who, like me, are just starting to learn PineScript, will find something useful. In the process of using grid bots, I noticed that the RSI indicator is sufficient, so the strategy uses 7 RSI indicators on different timeframes, but it is not necessary to use all 7, usually 3 is enough, therefore, by default, the RSI values are set to limit so that there is no effect on the settings of others. The step between bot orders is set in the settings. The code can of course be simplified, but it's better for understanding, I think.
Скрипт с открытым кодом

В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Хотите использовать этот скрипт на графике?
https://app.revenuebot.io/external/r/15151 - RevenueBot - Free Robot To Earn For You On Top Cryptocurrency Exchanges


hi! Can you add a stop loss ? thank you
rrolik66 wudidechangsheng
@wudidechangsheng, maybe such a code will work, but I have not tried it, I don’t need it.

longStopPerc = input(title="Long Bot Stop Loss (%)",
type=input.float, minval=0.0, step=0.1, defval=0.4, group="Long Bot") * 0.01
shortStopPerc = input(title="Short Bot Stop Loss (%)",
type=input.float, minval=0.0, step=0.1, defval=0.4, group="Short Bot") * 0.01

// Figure out take profit price
longStopPrice = strategy.position_avg_price * (1 - longStopPerc)
shortStopPrice = strategy.position_avg_price * (1 + shortStopPerc)

// exit position based on take profit price
if (strategy.position_size > 0) and longOK
strategy.order(id="exit_Long", long=false, limit=longExitPrice, qty=strategy.position_size)
strategy.order(id="stop_Long", long=false, stop=longStopPrice, qty=strategy.position_size)

if (strategy.position_size < 0) and shortOK
strategy.order(id="exit_Short", long=true, limit=shortExitPrice, qty=abs(strategy.position_size))
strategy.order(id="stop_Short", long=true, stop=shortStopPrice, qty=abs(strategy.position_size))
@rrolik66, Sorry, the code is not working
rrolik66 wudidechangsheng
@wudidechangsheng, The grid bot operation logic does not imply a stop loss. If I made a trend bot, I would definitely add a stop loss. But that would be completely different code.
It seems your Strategy is making 19 trades, at the Max. So, that means, if one is setting the initial capital to $1000, and one has to set the Order Size to 100% / 19 = 5.26% or so ?
rrolik66 CryptoSingh27
@CryptoSingh27, Yes, the first order is a market one, the remaining 19 at regular intervals from the entry price, only 20 orders at 5% of the initial capital. The price is averaged in case of an unsuccessful entry.
script look nice
i want to try it can somebody help me to convert below line in study

longExitPrice = strategy.position_avg_price * (1 + longProfitPerc)
shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)
rrolik66 Shhadow1
@ Shhadow1, in this part of the code, I just modeled the existing trading bot functionality. There is no point in using it in an indicator. A strategy is simply an opportunity to roughly understand how indicators will work if the market repeats itself.
Good job!
Buy I Do not think using "security" is necessary(may be repaint).
I had remove rsi all but "Day" . The reslut almost like yours
this is change

rsi1 = rsi(src, rsi1_Len)
rsi1_sec = rsi1
//security(syminfo.tickerid, rsi1_res, rsi1)
rsi2 = rsi(src, rsi2_Len)
rsi2_sec = rsi2
//security(syminfo.tickerid, rsi2_res, rsi2)
rsi3 = rsi(src, rsi3_Len)
rsi3_sec = rsi3
//security(syminfo.tickerid, rsi3_res, rsi3)
rsi4 = rsi(src, rsi4_Len)
rsi4_sec = rsi4
//security(syminfo.tickerid, rsi4_res, rsi4)
rsi5 = rsi(src, rsi5_Len)
rsi5_sec = rsi5
//security(syminfo.tickerid, rsi5_res, rsi5)
rsi6 = rsi(src, rsi6_Len)
rsi6_sec = rsi6
//security(syminfo.tickerid, rsi6_res, rsi6)
rsi7 = rsi(src, rsi7_Len)
rsi7_sec = rsi7
//security(syminfo.tickerid, rsi7_res, rsi7)
Shhadow1 liuqiba
@liuqiba, thanks for the code
Can this be converted into study i tried but cant do it can u help