您如何在 Pinescript 上将 RSI 与布林带策略混合使用

时间:2021-04-15 12:35:40

标签: pine-script

**我正在尝试将 RSI 与 BB 混合用于一个项目,但如果没有之前的 pinecript 经验,这真的很困难。我们预计突然开始使用pinescipt,我不知道如何使用策略功能。 我使用过其他交易者代码并对其进行了一些调整,但我不了解其中的某些功能。 例如,if(not na (vrsi) 是什么意思?stop=BBlower 是什么意思?if(strategy.postion_size>0) 是什么意思,你如何将 0.25% 的滑点转换为刻度?还有吗?绘制追踪止损的方法?

//@version=4
strategy("Bollinger + RSI", shorttitle="BB & RSI", overlay=true)
RSIlength = input(6,title="RSI Period Length") 
RSIoverSold = 20
RSIoverBought = 70
price = close
vrsi = rsi(price, RSIlength)
BBlength = input(20, minval=1,title="Bollinger Period Length")
BBmult = 2 // input(2.0, minval=0.001, maxval=50,title="Bollinger Bands Standard Deviation")
BBbasis = sma(price, BBlength)
BBdev = BBmult * stdev(price, BBlength)
BBupper = BBbasis + BBdev
BBlower = BBbasis - BBdev
source = close
buyEntry = crossover(source, BBlower)
sellEntry = crossunder(source, BBupper)
longLossPerc = input(title="Long Stop Loss (%)",
 type=input.float, minval=0.0, step=0.1, defval=1) * 0.01
 shortLossPerc = input(title="Short Stop Loss (%)",
 type=input.float, minval=0.0, step=0.1, defval=1) * 0.01
 longStopPrice  = strategy.position_avg_price * (1 - longLossPerc)
 shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)
 startDate = input(title="Start Date", type=input.integer,
 defval=1, minval=1, maxval=31)
 startMonth = input(title="Start Month", type=input.integer,
 defval=1, minval=1, maxval=12)
 startYear = input(title="Start Year", type=input.integer,
 defval=2007, minval=1800, maxval=2100)     
 endDate = input(title="End Date", type=input.integer,
 defval=31, minval=1, maxval=31)
 endMonth = input(title="End Month", type=input.integer,
 defval=3, minval=1, maxval=12)
 endYear = input(title="End Year", type=input.integer,
 defval=2009, minval=1800, maxval=2100)     
 inDateRange = (time >= timestamp(syminfo.timezone, startYear,
 startMonth, startDate, 0, 0)) and
 (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
 if (not na(vrsi))
 if (inDateRange and crossover(vrsi, RSIoverSold) and crossover(source, BBlower))
    strategy.entry("RSI_BB_L", strategy.long, stop=BBlower, oca_type=strategy.oca.cancel, 
    comment="RSI_BB_L")
 else
    strategy.cancel(id="RSI_BB_L")

if (inDateRange and crossunder(vrsi, RSIoverBought) and crossunder(source, BBupper))
    strategy.entry("RSI_BB_S", strategy.short, stop=BBupper, oca_type=strategy.oca.cancel,  
comment="RSI_BB_S")
else
      strategy.cancel(id="RSI_BB_S")        
if (strategy.position_size > 0)
strategy.exit(id="exitLong stp", stop=longStopPrice)

if (strategy.position_size < 0)
strategy.exit(id="exitshort stp", stop=shortStopPrice
a

0 个答案:

没有答案