在 PineScript v5 中,我试图制定一种策略,在下午 3:00(GMT+5:30 时区)之后我不打算进行任何交易。因此,如果当前时间小于下午 3:00,那么只有我会“进入”/“退出”交易。否则,我想在下午 3:00 退出所有未平仓头寸。
所以我尝试了这个:
endOfDay = input.int(defval=1500, title="Close all trades, default is 3:00 PM, 1500 hours (integer)")
if (hour(timenow) < endOfDay)
// Entry
float sl = na
if (sureBuyInTrend)
strategy.entry("enter long", strategy.long, lotSize, limit=na, stop=na, comment="Long")
sl = atrLow
if (sureSellInTrend)
strategy.entry("enter short", strategy.short, lotSize, limit=na, stop=na, comment="Short")
sl = atrHigh
// Exit: target or SL
longExitComment = (close < sl) ? "Long SL hit" : sureSellInTrend ? "Long target hit" : "Long close" …Run Code Online (Sandbox Code Playgroud) 我有一个脚本,我试图在 2 mA 与 line.new 交叉的地方绘制一个 X 我已经在另一个脚本中尝试了 line.new ,它似乎有效,所以我不知道为什么它不起作用这个脚本。我只是设置 y 但收到错误。
//@version=5
indicator(title="My MACD with crosses", shorttitle="My MACD", timeframe="", timeframe_gaps=true)
// Get User Input
i_showCross = input.bool(title="Show MA Crossovers", defval=true)
// Calculate MA's using user input selections
fast_ma = i_sma_source == "SMA" ? ta.sma(i_src, i_fast_length) : ta.ema(i_src, i_fast_length)
slow_ma = i_sma_source == "SMA" ? ta.sma(i_src, i_slow_length) : ta.ema(i_src, i_slow_length)
crossOver = ta.crossover(fast_ma, slow_ma)
crossUnder = ta.crossunder(slow_ma, fast_ma)
// show label
crossX = label.new(bar_index, na, str.tostring(fast_ma) + "crossed under " …Run Code Online (Sandbox Code Playgroud) 我对此很陌生,我已经制定了交易策略,但无法关闭特定数量的蜡烛的操作。我使用表达“barssince”,但它很重要,因为满足了条件;有时它会给出一个信号,然后返回以满足条件,并再次重新计算收盘蜡烛。如果有人能帮助我,当然可以。谢谢。
var x = '123'
x := x + '211'
plotshape(true, style=shape.labelup, color=close>open ?color.green:color.red, text= x, location=location.belowbar)
Run Code Online (Sandbox Code Playgroud)
将出现错误“第 39 行:无法使用plotshape参数调用(文字 bool、style=const string、color=series[color]、text=string、location=const string);可用的重载:plotshape(series [bool],const string,输入字符串,输入字符串,series [color],输入整数,series [integer],const string,series [color],const bool,const string,输入整数,字符串) => 无效;plotshape(fun_arg__,常量字符串,输入字符串,输入字符串,fun_arg__,输入整数,系列[整数],常量字符串,fun_arg__,常量布尔,常量字符串,输入整数,字符串)=> void'
鉴于这篇文章,我想问一下为什么下面的脚本适用[a,b]于[c,d].
找不到任何解释为什么这不起作用的文档。
此示例仅适用于 2 个返回值,但实际上我将创建一个具有 6 个或更多变量的函数,以便一次性返回。
我试图避免输入 6 行不同的行,因为我将在每个交易日输入这些数据(该函数将与日期相关,而且我已经有了相应的代码)。
所以我想每天只需要输入 1 行,以保持源代码清晰和可维护。
//@version=4
study("Functions test")
var int c = na
var int d = na
f(x) => [x,x+5]
[a,b] = f(20)
[c,d] := f(30)
plot(a)
plot(b)
plot(c)
plot(d)
Run Code Online (Sandbox Code Playgroud) pma = sma(maSource, periods)
entryLong = close * 1.10
longCondition = close >= pma
if longCondition
strategy.entry(id = "Long Entry", long = true, stop = entryLong)
Run Code Online (Sandbox Code Playgroud)
多个柱可以连续满足这个 long 条件,但我不希望后续柱覆盖前面的柱。理想情况下,我想添加一个检查来查看是否strategy.openentries == 0,但当然这样的变量在Tradingview中不存在。
想做这样的事情:
pma = sma(maSource, periods)
entryLong = close * 1.10
longCondition = close >= pma
if longCondition and strategy.openorders == 0
strategy.entry(id = "Long Entry", long = true, stop = entryLong)
if barssince(longCondition) = 3
strategy.cancel(id = "Long Entry")
Run Code Online (Sandbox Code Playgroud) 我正在尝试修改 TradingView 上的 pine 脚本指标,以便它在主图表上指标标题旁边显示指标/图的值。但是,我不想实际绘制任何内容,因为它会扰乱图表的比例。我也不希望它显示在图表上方或下方的单独窗口中。这可以用 Pine 脚本实现吗?
我尝试将 display=display.none 传递给“plot”函数,但这同时删除了值标签和线条。这是代码(图像示例没有“显示”参数):
//@version=4
study(title="ADR %", overlay=true)
length = input(20, title="length")
dhigh = security(syminfo.tickerid, 'D', high)
dlow = security(syminfo.tickerid, 'D', low)
adr = 100 * (sma(dhigh/dlow, length) - 1)
plot(adr, title="ADR %", display=display.none)
Run Code Online (Sandbox Code Playgroud) 我知道 pinescript 中 security() 调用的最大数量是 40,但我从pinecoder.com遇到了以下解决方法:
security() 调用的限制是 40,但是通过使用带有 security() 返回元组的函数,您可以获取比 40 更多的值。
我不太明白解决方法是什么!如果有人能为我描述它并举例说明,我将不胜感激。
嗨,我对 pine 脚本很陌生。如果我遗漏了一些非常明显的东西,我很抱歉。我试图在给定的脚本上绘制当天的开盘价、最高价、最低价和收盘价。为此,我使用下面的代码。
strategy("Intraday Test Strategy", overlay=true)
dh = security(syminfo.tickerid,"D",high)
do = security(syminfo.tickerid,"D",open)
dl = security(syminfo.tickerid,"D",low)
plot(dh, title="High",color=color.red,linewidth=2,trackprice=true)
plot(do, title="Open",color=color.yellow,linewidth=2,trackprice=true)
plot(dl, title="Low",color=color.green,linewidth=2,trackprice=true)
Run Code Online (Sandbox Code Playgroud)
当我执行此操作时,我看到的只是前一天的高价、开盘价、低价,而不是当天的高价、开盘价、低价。很明显我错过了一些非常基本的东西。如果您能澄清我在这里缺少的内容,我将非常感激。
正如我们从上面的图片中可以看到的那样,前一天的开盘价、最低价和最高价都被绘制在我需要当天价值的地方。