小编Pin*_*ucF的帖子

如何在Tradingview上的pinescript中在某个时间绘制垂直线?

我想在每天的某个当地时间(例如 08:00 GMT+1)画一条垂直线。

自从我上一篇关于垂直线的文章以来, pine-script 已更新为包含vline(),但是,这里的问题是获取正确的时间。大多数服务器(针对外汇)似乎都位于美国,并且交易视图本地时间设置(显示在左下角)似乎完全独立于 pine-script 中所做的操作。

//@version=4
study("Time Adjusted Vertical Line", overlay=true)

vline(BarIndex, Color, LineStyle, LineWidth) => // Verticle Line, 54 lines maximum allowable per indicator
    return = line.new(BarIndex, -1000, BarIndex, 1000, xloc.bar_index, extend.both, Color, LineStyle, LineWidth)

if(bar_index%10==0.0)
    vline(bar_index, #FF8000ff, line.style_solid, 1) // Variable assignment not required
Run Code Online (Sandbox Code Playgroud)

我无法使上述工作正常,但我至少可以显示以下几行:

//@version=4
study(title="Time Based Session Bars", shorttitle="NowOpen", overlay=true)
line_height = 2    // We must define a height that reaches far above the highest price level in main …
Run Code Online (Sandbox Code Playgroud)

pine-script

8
推荐指数
1
解决办法
2万
查看次数

计算松树脚本中SMA的斜率

我想计算简单移动平均线 (SMA) 的斜率。我已经尝试了以下数学上正确的代码。

rad2degree = 180/3.14159265359  //pi
sma2sample = sma(close,50) 
slopeD = rad2degree*atan( (sma2sample[0] - nz(sma2sample[1]))/1 )
Run Code Online (Sandbox Code Playgroud)

然而,问题是每只股票的价值不同,所以slopeD价值不是在一个固定的范围内,在[-90 to 90]度数之间。哪个更合乎逻辑。

我相信我需要对日期进行标准化以使这个变量处于固定范围内,但我不知道如何。

我怎样才能规范化的范围slopeD

math pine-script

7
推荐指数
1
解决办法
1963
查看次数

Tradingview Pine 脚本 - 如何使自定义交易量指标表现得像内置交易量

我制作了一个自定义交易量指标,但是当应用于图表时,它不会像内置指标那样自动缩放,不会自动粘在图表面板的底部,也不能没有自己明确的额外刻度旁边。

有没有办法让它做所有这些事情?

我在原始指标代码中也没有找到任何帮助。例如,当我尝试应用 format.volume 时,它​​根本拒绝编译。

下面是我的代码,原始代码在下面:

//This inddicator will show volume inversely. So if you are looking at an Altcoin, it will show volume in BTC, if you are looking at for example BTC/USD it will show volume in USD and so on. Works with all altcoins and fiat pairs.
//I find this most useful when shopping for alts to quickly get an idea of their liquidity.

//title the indicator and dont use decimals. (Otherwise when viewing fiat volume you …
Run Code Online (Sandbox Code Playgroud)

pine-script

7
推荐指数
2
解决办法
1万
查看次数

在循环内绘图,无法在局部范围内使用“plot”。(TradingView Pine 脚本)

我在尝试清理代码时无法确定正确的实现,并且发现了一个似乎适合 For 循环的部分,但是,我收到以下错误:

Cannot use 'plot' in local scope. 
Run Code Online (Sandbox Code Playgroud)

当尝试执行以下示例时:

a = 10
b = 5
for i = 1 to b
    j = a * i
    plot(highest(j), title="Resistance", color=b, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
Run Code Online (Sandbox Code Playgroud)

我原来的代码如下:

a=10
plot(highest(a*1), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*2), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*3), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*4), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*5), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
Run Code Online (Sandbox Code Playgroud)

我最终希望绘图的数量(b 变量)可以从 0 …

pine-script

7
推荐指数
1
解决办法
4921
查看次数

TradingView 帮助使用多个strategy.exit 调用

我在修改 TradingView 策略测试器中的未平仓头寸时遇到奇怪的问题。让我先解释一下上下文:
下面一行根据我的入场条件打开一个订单entryLong

strategy.entry("ID", strategy.long, comment="L_Entry", when = entryLong)

这很有效,但是,在关闭订单之前您无法赚钱;)因此:

strategy.exit( "L_STOP", "ID", loss = fixedSL * 10)

fixedSL该行修改未平仓订单,以低于入场位置的价格添加止损。此时,我唯一的退出条件是价格触及我的止损,这总是会导致亏损策略。为了解决这个问题,我包括:

if (exitLong) strategy.exit("L_TRAIL", "ID", trail_points = fixedTP * 10, trail_offset = trailSL * 10)

然后在达到设定利润添加追踪止损。这样,我就可以安全地锁定利润,同时仍然留有增长空间。问题就在这里。每个退出条件都有一个 ID -L_STOPL_Trail(L 代表 Long,bc 这是买入)。我在图表上引用这些 ID 来帮助调试,并且只有L_STOP出现过的 ID 才会关闭订单。这让我相信L_TRAIL退出条件要么从未满足(不太可能),要么从未设置。我知道布尔值exitLong设置为 True 并且该行应该正在执行。

我可以通过在一次调用中设置追踪止损和止损来完全避免这个问题strategy.exit,但是看到屏幕上打印的L_STOPL_TRAIL来了解导致交易退出的原因非常有帮助。当满足条件时,只会打印订单的 ID,因此一次调用只会是L_STOP,这不会提供有关退出触发器的太多信息。

任何和所有反馈都是有帮助的!如有必要,我还可以添加图表的屏幕截图。

pine-script

6
推荐指数
1
解决办法
7395
查看次数

交易视图。Pine-Script:Plotshape,同时使用 location.absolute 和布尔条件..?

在 TradingView PineScript 编程语言中,Plotshape 命令格式为:plotshape(series, title, style, location, .... 其中“Series 被视为除 location.absolute 之外的所有位置值的一系列布尔值。”

因此,使用“系列”,您可以指定是否必须为特定条形图绘制形状。除非......当您使用“location.absolute”时。在这种情况下,“系列”参数是形状的垂直坐标......如果你问我,语法很奇怪。为什么不将坐标添加为单独的参数?

因此,我无法在单个 PlotShape 命令中同时使用布尔值(指示是否必须绘制形状)和绝对位置。因此,我使用布尔值来代替“series”和“location.top”或“location.bottom”。但这并不是我真正想要的。

有人知道这个问题的解决方法吗?

谢谢!

pine-script

6
推荐指数
1
解决办法
1万
查看次数

Converting linreg function from pinescript to Python?

I am trying to convert a TradingView indicator into Python (also using pandas to store its result).

This is the indicator public code I want to convert into a python indicator:

https://www.tradingview.com/script/sU9molfV/

And I am stuck creating that pine script linereg default function.

This is the fragment of the pinescript indicator I have troubles with:

lrc = linreg(src, length, 0)
lrc1 = linreg(src,length,1)
lrs = (lrc-lrc1)
TSF = linreg(src, length, 0)+lrs
Run Code Online (Sandbox Code Playgroud)

This is its documentation:

Linear regression curve. A line …

python python-3.x

6
推荐指数
1
解决办法
222
查看次数

TradingView Pine Script : 在新入场前检查之前的 strategy.entry 价格

有人问了类似的问题,没有回应,我不允许补充。

Tradingview Pine 脚本在策略进入时保存收盘价

我正在尝试制定一个策略,该策略将多次购买(金字塔式)以在收盘前平均下跌,但我想检查之前的入场价格以确保其低于配置的百分比。

到目前为止我所拥有的:

lastBuy=0

if (condition)
    if (lastBuy==0)
        lastBuy=close
        strategy.entry("buy", true)
    else
        if ((close*1.01)<lastBuy)
            lastBuy=close
            strategy.entry("buy", true)
Run Code Online (Sandbox Code Playgroud)

每次传递代码时,它都会将 lastBuy 重置为零,我永远不会检查之前的收盘价。如果我不设置它,我会收到未声明的错误。

在此先感谢您的帮助!

pine-script

5
推荐指数
3
解决办法
6178
查看次数

参考先前退出价格的 Pine 脚本入场策略

我正在尝试在电视中建立一个策略(仅限多头头寸),其中strategy.entry将考虑之前的退出价格。例如:

strategy.entry("long", strategy.long, when = longcondition==true)
strategy.close("long", strategy.close, when = longcondition==false)
Run Code Online (Sandbox Code Playgroud)

除了 longcondition==true 之外,我还想为 Strategy.entry 插入另一个条件,它说明了以下意图:

strategy.entry("long", strategy.long, when = longcondition==true and close[1] < previousExitPrice)
Run Code Online (Sandbox Code Playgroud)

怎样做才正确呢?预先感谢您的答复。

trading algorithmic-trading pine-script

5
推荐指数
1
解决办法
1367
查看次数

来自 Pine 脚本内的参考指标

假设我想将 AO 指示器作为 Pine 脚本标准的一部分包含在内。pine 脚本如何访问指标?策略或研究可以导入由另一个 Pine 脚本或内置指标生成的系列吗?

pine-script

5
推荐指数
1
解决办法
1万
查看次数