我哪里出错了?

问题描述 投票:0回答:1
//@version=5
strategy(title="1bln", overlay = true, initial_capital = 1000)

src = close
lenrsi = input(3, "RSI Length")
lenupdown = input(1, "UpDown Length")
lenroc = input(100, "ROC Length")
updown(s) =>
    isEqual = s == s[1]
    isGrowing = s > s[1]
    ud = 0.0
    ud := isEqual ? 0 : isGrowing ? (nz(ud[1]) <= 0 ? 1 : nz(ud[1])+1) : (nz(ud[1]) >= 0 ? -1 : nz(ud[1])-1)
rsi = ta.rsi(src, lenrsi)
updownrsi = ta.rsi(updown(src), lenupdown)
percentrank = ta.percentrank(ta.roc(src, 1), lenroc)
crsi = math.avg(rsi, updownrsi, percentrank) // Connors rsi

if crsi > 70
    strategy.close_all()

var first_entry_time = strategy.opentrades.entry_time(0)
var second_entry_time = strategy.opentrades.entry_time(1)
var make_first_entry = first_entry_time + 5 * 60 * 1000 // time out first take
var make_second_entry = second_entry_time + 10 * 60 * 1000 // time out second take
var initial_entry_price = strategy.opentrades.entry_price(0)
var second_entry_price = strategy.opentrades.entry_price(1)
lowestLow = ta.lowest(low, 100)
var initial_price_decrease = initial_entry_price - initial_entry_price * 0.005
var second_price_decrease = second_entry_price - second_entry_price * 0.008

if(crsi == 15 and make_second_entry == time and second_price_decrease <= lowestLow)
    strategy.entry("take_3", strategy.long, limit = strategy.initial_capital * 0.25) 
else if(crsi < 20 and make_first_entry == time and initial_price_decrease <= lowestLow)
    strategy.entry("take_2", strategy.long, limit = strategy.initial_capital * 0.2) 
else
    strategy.entry("take_1", strategy.long, limit = strategy.initial_capital * 0.15) 



我编写了一个应该根据 CRSI 指标买入的策略,该策略在买入之间暂停。并检查投入之间的价格差异。 我不明白为什么它不起作用?

我删除了部分代码,但第二次和第三次购买不起作用。

pine-script pine-script-v5
1个回答
0
投票
  1. 您使用
    var
    声明变量,并且无需在任何地方重新定义它们的值,因此它们将从第一次调用时起保持其状态。也许我误解了你的逻辑,你只想为一些交易编写代码只是为了测试,但我会假设你是偶然这样做的(最好在不需要时发出警告,而不是猜测)
  2. 您在未启用
    strategy.opentrades.entry_time(1)
    的情况下使用
    pyramiding
    ,在这种情况下,此调用将始终为
    na
    ,因为您在任何时候都不能同时拥有两个未平仓交易。如果您想在关闭当前一笔交易之前开立多笔交易,请重新定义
    pyramiding
    函数
    strategy()
  3. 参数的值
  4. 遵循 1 和 2。在开仓之前调用
    strategy.opentrades.entry_time()
    返回
    na
    ,您的逻辑基于检查此函数的时间,使用带有
    na
    的布尔表达式,结果始终为
    false
    。由于您声明了将函数计算结果写入其中的变量,并且不在任何地方重新定义其值,因此使用这些变量的条件将始终为
    var
    
        
© www.soinside.com 2019 - 2024. All rights reserved.