我正在努力在交易视图中创建一个趋势指标来跟踪趋势的走向。具体来说,我想要一个变量在几天内保持不变,但当满足特定条件时它会发生变化。看起来应该很简单,但每次我尝试时,我都会陷入一个永无休止的循环,而且我似乎无法理解它。变量“趋势”
///Condition
pos = close > open
neg = close < open
pos_cond = pos and pos[1]
neg_cond = neg and neg[1]
///Variables to keep track of trend
Trend = iff(***pos_cond or neg_cond not met***, Trend[1], Trend + real_trend)
trend_change_neg = iff(pos_cond, 1, 0)
trend_change_pos = iff(neg_cond, -1, 0)
real_trend = trend_change_neg + trend_change_pos
Trend = iff(Trend > 2, 2, iff(Trend < -2, -2, Trend))
/////////plots
plotshape(Trend > 0, color = color.green, location = location.top, style = shape.square, title="TrendLong")
plotshape( …Run Code Online (Sandbox Code Playgroud) 我是松树脚本的新手。我想比较 2 个特定日期的价格。
但是我如何获得特定日期的 bar_index 呢?
提前致谢
我试图做一些看似微不足道的事情,但却遇到了各种各样的问题。
每次当前价格更新时,我都想在标签上绘制某些基本信息 - 无论我的图表的时间范围如何。
我能够准确地显示数量和价格信息,但是显示时间一直是一个挑战。
我的第一次尝试是使用以下代码:
if (barstate.islast)
label.set_text(
id=myLabel,
text="\nTime: " + tostring(hour) + ":" + tostring(minute) + ":" + tostring(minute)
)
Run Code Online (Sandbox Code Playgroud)
我很快了解到,即使我的图表设置为纽约的时区(即 UTC-4),调用也会tostring(hour)显示 UTC 的时间。
弄清楚如何指定我希望它显示的时间与我的图表时区相对应是第一个主要障碍,我一直在纠结timestamp(),但syminfo.timezone无济于事。
我的第二个主要问题是tostring(second)无法正确显示秒数,即使对于 UTC 时间也是如此。
在处理 1m 图表时,我想我可以通过实施来解决这个问题
tostring((timenow-time)/1000)
但是,秒数在不同的时间范围内无法正确显示。
除此之外,来自不同时区的不同交易所的图表都将相对于 UTC 时间“错误”地显示时间。
肯定是我错过了一些相当基本的东西,因为时间是如此重要的数据,但我只是无法确定正确的语法。
预先感谢您的任何帮助。
我想知道我们是否可以使用脚本绘制过去的交易。我基本上想访问我的执行历史记录,并以我执行这些操作的价格绘制线条,以便清楚地了解我的盈利和亏损交易。这在松树中可能吗?例如,从我跟踪我的交易的 Excel 开始,如下所示:数据
我会在图表中得到类似的内容:示例
如果可能的话,脚本可以直接从我的经纪人那里获取数据,但如果没有,我总是可以如上所述在 Excel 中记录我的所有交易。
现在我们只能用箭头在 Tradingview 中显示执行情况,并且箭头位于柱的上方或下方。但我们无法从他们那里得到确切的信息。我想要一个脚本来显示执行情况,就像我们在 MT4 中看到的那样:Ninjatrader
只是玩玩,学习如何编写策略。我现在正在尝试的是(伪代码)......
if(previousCandle == red
... AND previousCandle.high >= sma
... AND previousCandle.low <= sma
... AND currentPrice > previousCandle.high)
enter trade
Run Code Online (Sandbox Code Playgroud)
我在 Pine Script 中拥有的是......
redTouch = close < open and high >= ma and low <= ma
longCond = redTouch[1] and close > high[1]
strategy.entry("Long", strategy.long, when = longCond)
Run Code Online (Sandbox Code Playgroud)
所有蜡烛redTouch均已正确识别(之前使用 BG 颜色进行检查),但对于longCondI don’t Want close > high[1],因为它仅在下一根蜡烛上进入交易(并且为时已晚)。
以下屏幕截图显示了当前正在进入交易的位置(红色蜡烛上的蓝线),以及我希望它在哪里触发/进入(绿色蜡烛上的黄线)。
如何更改close > high[1]为price > high[1]或类似的蜡烛内交叉触发?或者您只能在 Pine Script 中的下一个蜡烛中输入交易吗?
我只是第一次尝试 Pine 脚本,无法使这项工作 \xe2\x80\x93 ,根据其他示例,这应该是微不足道的。
\nstudy("Price to Operating Income", overlay=true, scale=scale.left)\nop_income = financial(syminfo.tickerid, "OPER_INCOME", "FQ")\nprice_op_income = close/op_income\nplot(price_op_income)\nRun Code Online (Sandbox Code Playgroud)\n\n\n找不到函数或函数参考财务
\n
这仅仅是因为 TradingView 免费版本中的 Pine Script 无法使用营业收入,还是我遗漏了什么?
\n我有一个 pine 脚本来绘制前一天的高点/开盘价/低点,如下所示:
//@version=4
strategy("Plot Lines", overlay=true)
PDH = security(syminfo.tickerid,"D",high)
PDO = security(syminfo.tickerid,"D",open)
PDL = security(syminfo.tickerid,"D",low)
plot(PDH, title="High",color=color.red,linewidth=2,trackprice=true)
plot(PDO, title="Open",color=color.yellow,linewidth=2,trackprice=true)
plot(PDL, title="Low",color=color.green,linewidth=2,trackprice=true)
Run Code Online (Sandbox Code Playgroud)
该脚本运行良好,但我只想显示前一天并忽略前一天之前的其他日期,这样图表就不会那么混乱。
正如您所看到的,它绘制了前一天的 PDH/PDO/PDL,但我只想要前一天(一天)。任何帮助或建议将不胜感激!
我正在尝试使用基于Web的TradingView平台来制作自己的自定义脚本,以显示各种金融市场属性。这可以通过其pine脚本引擎/解释器实现。
目前,我试图在主图表或指标图表上仅显示一条垂直线。但是,除非使用绘图histogram或column类型,否则他们的脚本引擎似乎并不支持垂直线。无论哪种方式,我都无法获得满意的评价。
一些测试
(1)bgcolor()像这样使用取得了一些次要的成功:
//@version=3
study(title="vbar1", overlay = false)
trange(res, sess) => not na(time(res, sess))
vlinecol = #000000 // black
plot(n, color = na) // check last value from plot but don't display
vline = (n < 5710) ? na : trange("1", "0700-0701") ? vlinecol : na
bgcolor(vline, transp=0)
Run Code Online (Sandbox Code Playgroud)
结果是:
(2)plot()与style=histogram参数一起使用时会得到更好的结果:
//@version=3
study(title="vbar2", overlay = true) // scale=scale.none only for overlay=true
vlinecol = #000000 // black …Run Code Online (Sandbox Code Playgroud) 我想在TradingView Pine Script语言中找到最近200条的价格趋势。
我想画一条线,从最新的柱线(关闭)到较旧的200条柱线。然后,我想以度为单位计算线的角度,以查看趋势的多头或多头。
我可以通过TradingView绘图屏幕中的回归趋势工具轻松完成此操作。我想通过编程来做同样的事情。
我想可以通过以下公式(Java)找到角度:
double rads = Math.Atan((line.Y2 - line.Y1) / (line.X2 - line.X1));
double degrees = rads * (180f / Math.PI);
Run Code Online (Sandbox Code Playgroud)
你能给我一个例子吗?
谢谢
我用它alertcondition来询问绘图中的值,但返回的值有超过 3 个小数位。
我可以格式化它以使输出只显示精度直到 3 位小数吗?
alertcondition(crossover(d2,d3), title="monitor", message='{{ticker}} Monitor If price above Current Price={{close}} PIVOT = {{plot("Pivot")}} SUPPORT = {{plot("S1")}} RESISTANCE = {{plot("R1")}}
Run Code Online (Sandbox Code Playgroud)