Trend-following RSI Strategy

Coinrule · strategy · 33 行 · 点赞 212 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=1
strategy(shorttitle='Trend-following RSI Scalping Strategy (by Coinrule)',title='Trend-following RSI Strategy ', overlay=true, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_type = strategy.percent_of_equity, default_qty_value = 30, commission_type=strategy.commission.percent, commission_value=0.1)
 
//Backtest dates
fromMonth = input(defval = 1,  title = "From Month")     
fromDay   = input(defval = 10,    title = "From Day")       
fromYear  = input(defval = 2020, title = "From Year")       
thruMonth = input(defval = 1,    title = "Thru Month")     
thruDay   = input(defval = 1,    title = "Thru Day")     
thruYear  = input(defval = 2112, title = "Thru Year")       
 
showDate  = input(defval = true, title = "Show Date Range")
 
start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window
finish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish window
window()  => time >= start and time <= finish ? true : false       // create function "within window of time"
 
 
// RSI inputs and calculations
lengthRSI = input(14, title = 'RSI period', minval=1)
RSI = rsi(close, lengthRSI)
 
//Entry
 
 
strategy.entry(id="long", long = true, when = RSI > 70 and window()) 
 
//Exit
 
Take_profit= ((input (6))/100)
longTakeProfit = strategy.position_avg_price * (1 + Take_profit)
 
strategy.close("long", when = RSI < 55 or close > longTakeProfit and window())

← 返回列表