TradingView
rrolik66
Aug 1, 2021 8:03 PM

7-RSI strategy 

Bitcoin / U.S. dollarBitstamp

描述

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.
评论
rampaige91
Hi, I forward tested your strategy, and recorded my screen for a few hours. I realized after refreshing the Tradingview window after a few hours, the entries and exits would repaint and change! Is there any way to fix it?
vmnov21
wudidechangsheng
hi! Can you add a stop loss ? thank you
rrolik66
@wudidechangsheng, maybe such a code will work, but I have not tried it, I don’t need it.

//inputs
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))
wudidechangsheng
@rrolik66, Sorry, the code is not working
rrolik66
@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.
CryptoSingh27
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, 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.
Shhadow1
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)
更多