【发布时间】:2021-10-21 19:43:15
【问题描述】:
我正在尝试在 Pine Script 中实施基于 2 周期 RSI 的策略回测。 这个想法很简单
目标
- 2 周期 RSI 低于 10,当 200 EMA 低于最近收盘价时,我在下一根蜡烛上做多,市场订单设置为比之前的蜡烛收盘价低 2%。
- 2 周期 RSI 超过 90,或自进入以来已超过 10 个柱(以先出现的情况为准)我退出交易。
问题
因此,显然 pine 脚本默认在下一根蜡烛开盘时采取多头/空头头寸。 但是,尽管通过指定限制属性下了市价单,但多头头寸仍以下一根蜡烛的开盘价输入。
更多细节
时间范围 - 1 天
代码链接 - https://in.tradingview.com/chart/GDSsFCKq/#(代码 - SBILIFE (NSE INDIA))
我不确定我在这里做错了什么。请帮忙。
代码
//@version=4
strategy("2RSI Strategy by Larry Connor", overlay=true)
rsi_length = input(title="RSI Length", defval=2)
buying_rsi_value = input(title="Buy at RSI Value", defval=5)
selling_rsi_value = input(title="Sell at RSI Value", defval= 40)
price = close
rsi = rsi(price, rsi_length)
buy = crossunder(rsi, buying_rsi_value)
sell = crossover(rsi, selling_rsi_value)
date = tostring(dayofmonth) + '-' + tostring(month) + '-' + tostring(year)
disable_date_ranges = input(title="Disable Date Ranges", defval=true)
start_date = input(title="Start Date", type=input.time, defval=timestamp("19 Oct 2020
00:00 +0530"))
end_date = input(title="End Date", type=input.time, defval=timestamp("18 Oct 2021
00:00 +0530"))
in_date_range = time >= start_date and time < end_date
ema_len = input(200, minval=1, title="EMA Length")
ema_src = input(close, title="EMA Source")
ema_200 = ema(ema_src, ema_len)
entry_condition= buy and ema_200 < price
exit_condition = sell or entry_condition[10]
previous_day_close = close[1]
two_percent_of_prev_day_close = previous_day_close * 0.02
entry_price = previous_day_close - two_percent_of_prev_day_close
// plotchar(entry_condition, "debug", "", location.bottom)
capital_invested = input(title="Invested capital", defval=100000)
initial_capital = strategy.initial_capital
capital_to_be_invested = capital_invested
if(na(capital_invested) or capital_invested == 0)
capital_to_be_invested = initial_capital
if (not na(rsi) and (in_date_range or disable_date_ranges))
strategy.entry("buy", when=entry_condition and low < entry_price, limit=
entry_price, long= true, qty = capital_to_be_invested/entry_price, comment="Long")
if (exit_condition)
strategy.close("buy", true)
【问题讨论】:
标签: pine-script algorithmic-trading back-testing