交易视图-需要简单的策略帮助

时间:2020-07-29 06:23:47

标签: pine-script

我是交易视图的新手,并且几乎没有编程背景。我正在尝试编写一种简单的策略,即在RSI达到30时买入,并在我进入后价格上涨5%时卖出。

我不确定如何退出交易。参见下面的代码。

strategy("Simple RSI", overlay=true, initial_capital=10000, currency='USD')
 
fromYear = year >= 2010
toYear = year <= 2020
 
longCondition = rsi(close, 21) < 30
if (longCondition and fromYear and toYear)
    strategy.entry("Long 1", strategy.long)
    
entry_price = valuewhen(longCondition, open, 0)
exit_price = entry_price * 1.05 
  
closeCondition = exit_price
if (closeCondition)
    strategy.close("Long 1")

0 个答案:

没有答案