此为历史版本和 IPFS 入口查阅区,回到作品页
I am Mike-我是廣利
IPFS 指纹 这是什么

作品指纹

2023-04-14(五):TradeView腳本,兩個RSI指標。

I am Mike-我是廣利
·
·
2023-04-14(五):TradeView腳本,兩個RSI指標。

咒語:取兩個RSI指標,一個rsi指標的平均天數是25,另一個rsi指標的平均天數是100。當平均天數25的指標穿越平均天數100往上,做買進操作,止損點設定在前低點。當平均天數25的指標穿越平均天數100往下,做賣出操作,止損點設定在前高點。盈利開始之後,當總盈利低於之前的60%,做止盈操作。

//@version=4

strategy("RSI Cross Over Strategy", overlay=true)


rsi1_length = input(title="RSI 1 Length", type=input.integer, defval=25)

rsi2_length = input(title="RSI 2 Length", type=input.integer, defval=100)

overbought_level = input(title="Overbought Level", type=input.integer, defval=70)

oversold_level = input(title="Oversold Level", type=input.integer, defval=30)

stop_loss_percentage = input(title="Stop Loss Percentage", type=input.float, defval=0.02)

take_profit_percentage = input(title="Take Profit Percentage", type=input.float, defval=0.06)


rsi1 = rsi(close, rsi1_length)

rsi2 = rsi(close, rsi2_length)


long_condition = crossover(rsi1, rsi2)

short_condition = crossunder(rsi1, rsi2)


long_stop = 0.0

short_stop = 0.0


if long_condition

strategy.entry("Long", strategy.long)

long_stop := low[1]

if short_condition

strategy.entry("Short", strategy.short)

short_stop := high[1]

if strategy.position_size > 0

long_stop := max(long_stop, low[1])

stop_loss = strategy.position_avg_price * (1 - stop_loss_percentage)

strategy.exit("Stop Loss", "Long", stop=stop_loss, loss=stop_loss)

take_profit = strategy.position_avg_price * (1 + take_profit_percentage)

if strategy.position_profit > 0 and strategy.position_profit < strategy.netprofit * 0.6

strategy.exit("Take Profit", "Long", limit=take_profit)


if strategy.position_size < 0

short_stop := min(short_stop, high[1])

stop_loss = strategy.position_avg_price * (1 + stop_loss_percentage)

strategy.exit("Stop Loss", "Short", stop=stop_loss, loss=stop_loss)

take_profit = strategy.position_avg_price * (1 - take_profit_percentage)

if strategy.position_profit > 0 and strategy.position_profit < strategy.netprofit * 0.6

strategy.exit("Take Profit", "Short", limit=take_profit)

plot(rsi1, color=color.blue, title="RSI 1")

plot(rsi2, color=color.orange, title="RSI 2")


CC BY-NC-ND 2.0 授权