我正在尝试换行,因为它太长,无法在一个屏幕上看到所有内容:
strategy.entry
("Long Continuation",
true, 1, when = FastMA < SlowMA and SlowMA > SlowMA[5] and ShortDiff <
ShortDiff[1]
and close[1] < _PercentAbove and close[1] > _PercentBelow)
Run Code Online (Sandbox Code Playgroud)
它在未包装的情况下工作,但是当我包装它时,我收到错误“添加到图表操作失败,原因:第 15 行:输入‘行尾无行延续’处的语法错误”
我意识到我可以用更好的代码来缩短这个时间,但我只是对 Pine 中的换行工作感到好奇enter code here
尝试在每日开盘时绘制水平射线,我的代码由于某种原因没有绘制任何内容
//@version=4
study("Opens +", overlay=true)
higherTF1 = input("D", type=input.resolution)
dailyopen = security(syminfo.tickerid, higherTF1, open)
var line1 = line.new(bar_index, dailyopen,bar_index, dailyopen, xloc=xloc.bar_index, style=line.style_solid,extend=extend.right)
line.set_color(line1, color.black)
line.set_width(line1, 1)
Run Code Online (Sandbox Code Playgroud) 我尝试用变量编写文本,但不能
aaaa = 121.150
bbbb = 120.100
target = "TP = " + ( aaaa * 0.9 ) + "\n SL = " + bbbb*1.01
plotshape(data , style=shape.triangledown,location=location.abovebar, color=red, text=target)
Run Code Online (Sandbox Code Playgroud)
我希望输出看起来像这样:

单击图表上指标的齿轮“设置”会弹出一个对话框,其中包含“输入”选项卡和“样式”选项卡。每种样式前面都有一个复选框,用于控制特定绘图的可见性。默认情况下,所有图都是可见的。我希望默认隐藏一些图。我知道执行此操作的唯一方法是手动取消选中对话框中的某些样式,然后使用下拉框“默认”>“另存为默认值”将这些设置保存为新的默认设置。但我怎样才能在代码中做到这一点呢?如何使用 pinescript 将绘图的默认状态设置为“隐藏”?谢谢!
如何以柱开盘价进入策略?
当我使用“process_orders_on_close=true”时,策略输入发生在当前柱的收盘时,当我使用“process_orders_on_close=false”时,则延迟一柱来输入策略。
我已经尝试了更改后的所有操作,但没有任何效果
1.当价格高于或低于特定水平时使用“">=”或“<=”而不是交叉或交叉下
2.“process_orders_on_close=true”消除了延迟,但空头入场/多头入场发生在柱线收盘时,但我需要在柱线开盘时进行。
我的问题与下面提到的链接相同,但链接中提到的所有建议都不起作用。 https://www.tradingview.com/script/Bi3j0E8Q-Help-needed-with-strategy-Entry-is-off-by-2-candles/
我刚刚开始使用 PineScript 进行编码,经过几次尝试,我想寻求帮助。
我试图计算与最后一次多头头寸入场相比发生了多少根柱线。这个问题(或类似的问题)已被问过几次,但我发现barssince()并不能解决问题。简单地说,它根本不起作用。
我想测试的策略如下:如果价格比之前的高点下跌 2.5%,我想平掉多头头寸。前一个高点不需要在固定长度的窗口(例如,最后 10 个柱左右)中进行评估,但需要从完成多头入场的柱开始进行评估。
我尝试平掉多头头寸(以其 ID“买入”开仓),如下所示:
npastdays=barssince(strategy.position_size > 0)
prevHigh=highest(close, npastdays)
if (close < 0.975*prevHigh)
strategy.close("buy")
Run Code Online (Sandbox Code Playgroud)
我什至尝试了其他方法,例如,在开仓时将“op”变量设置为非零值,而不是使用“change(op > 0)”或类似的“crossover(op, value)”。无论哪种方式,“npastdays”变量都不会被计算,它保持未定义状态(nd)。
编辑#1:当开多头仓位时,我再次尝试设置 op:=6.5 (任何数字都可以,或者布尔值),然后:
npastdays=barssince(op==6.5)
if (npastdays!=0) // else, I just opened a long position
prevHigh=highest(close, npastdays)
if (close < 0.975*prevHigh)
strategy.close("buy")
Run Code Online (Sandbox Code Playgroud)
我得到了一个不同的错误,“Pine无法确定系列的引用长度。尝试在研究或策略函数中使用max_bars_back。”。仍然没有解决。
Edit #2: I tried, without success, to use the built-in "bar_index" with the instrucion "posLong := bar_index" when a long entry is done. However, the code works only with a fixed number of bars: …
我正在尝试在 TradingView Pinescript 中创建多个移动平均线脚本。不幸的是,它不断抛出错误:
脚本无法翻译自:[“EMA”,“SMA”,“WMA”,“HMA”,“LIN”]
我似乎无法弄清楚我的语法是否不正确或者是否还缺少其他内容。
任何人可以提供的任何帮助将不胜感激。
study("SPY Indicators", shorttitle="SPY Ind", overlay=true)
//@version=1
// Version 1.0
// Author: Likwid
// Definitions: Price and Timeframes
src = input(close, title = "Source")
resolution = timeframe.period
price = security(syminfo.tickerid, resolution, src)
// Defintions: Moving Average periods and types
ma1Period = input(defval=8, title="Period", inline="1", group="Moving Averages: Zone 1")
ma1Type = input(defval="EMA", title="Type", type=input.string, options=["EMA","SMA","WMA","HMA","LIN"], tooltip="MA Smoothing", inline="1", group="Moving Averages: Zone 1")
ma2Period = input(defval=21, title="Period", inline="2", group="Moving Averages: Zone 1")
ma2Type = input(defval="EMA", title="Type", …Run Code Online (Sandbox Code Playgroud) 为了便于阅读,我一直在尝试将元组作为输入发送到 pinescript 中的函数。但我还没有找到让它发挥作用的方法。
这是我想要实现的基本想法:
aFunction(xy1,xy2) =>
[x1,y1]=xy1
[x2,y2]=xy2
x = some equation
y = another equation
[x,y]
Run Code Online (Sandbox Code Playgroud)
目的是将元组作为输入传递。在某种程度上与此类似(如果尝试,实际上会破坏预处理器):
C1 = [a,b]
C2 = [c,d]
w = aFunction(C1,C2)
Run Code Online (Sandbox Code Playgroud)
通过一些调整,我可以让初始预处理顺利进行,但很长一段时间后,我收到“编译”时错误,无法确定 xy1 和 xy2 的参数类型。
我似乎没有找到“元组”类型转换,甚至没有找到元组参数类型,因为它们的支持相当有限。
请注意,安全函数将元组和更复杂的结构作为输入进行处理,因此在语言中存在安全函数是合理的期望。
PineScript 中是否可以将 String 转换为 Float 或 int?
我们可以使用str.tostringfloat 转换为 string,但是有没有办法从 string 转换为 float 或 int?
我想尝试将此作为向左偏移值的解决方法。由于我无法找到一种方法将值向左偏移,只能向右偏移,所以我想看看是否可以通过在 2021 年 7 月从 Float 到 String 以及在 2021 年 5 月从 String 到 Float 来实现它。
我使用此代码来显示价格线和表格。
//@version=5
indicator('MyIndicator')
ticker = input.symbol(defval='NSE:NIFTY', title='Ticker')
ticker_col = input.color(color.new(color.blue, 0), title='Color')
tickertext_col = input.color(color.new(color.white, 0), title='Text')
ticker_data = request.security(ticker, "", close)
plot(ticker_data, title='Ticker', color=ticker_col, linewidth=1, style=plot.style_line)
table = table.new(position = position.top_right, columns = 3, rows = 4)
table.cell(table_id = table, column = 0, row = 1, text = 'Ticker', text_color = tickertext_col, text_size = size.normal, bgcolor = ticker_col)
Run Code Online (Sandbox Code Playgroud)
使用“输入”部分,我可以为价格线和表格背景分配相同的颜色,因此我想删除“样式”部分中的颜色选项,因为它是多余且无用的。
可行吗?