pine-script

Adding variables to alerts in pinescript

杀马特。学长 韩版系。学妹 提交于 2021-02-19 01:53:10
问题 I would like to use the same alert condition in a pine script for several stocks in TradingView. The problem is that I won't know which stock triggered the alert unless I create copies of the script and have a custom message for each script. I would like to have something like: alertcondition(someCondition, title='Bullish', message=tickerid) where I use the tickerid variable which is one of pine scripts built in variables. However, when I attempt this, the message I get is literally tickerid

How to get bar index on specific date

浪子不回头ぞ 提交于 2021-02-17 02:46:30
问题 I am new to pine script. I want to compare the prices on 2 specific date. But how would I get the bar_index on a particular date? Thanks in advance 回答1: timestamp function would return UNIX time of specified date and time. If time in ms is more the Jan 3, grab the low. For intraday specify minutes in the timestamp function. //@version=4 study("low on specific date") specificDate = time >= timestamp(2019, 1, 3, 00, 00) var float lowOnDate= na if specificDate and not specificDate[1] lowOnDate :

How to apply formula to several securities

醉酒当歌 提交于 2021-02-15 07:42:11
问题 I would like to apply the below to several securities. The end product would display 3 lines showing percentage change from 1700 to 2100 using a baseline of midpoint from 1500 to 1700 using lowest and highest candle from that period. For example I would like to monitor these 3 securities: BINANCE:NEBLUSD BINANCE:RSRUSD BINANCE:TRXUSD study("Baseline", overlay=false) Coin01 = input(title = "Coin Selection", defval="BINANCE:NEBLUSD") Coin02 = input(title = "Coin Selection", defval="BINANCE

Tradingview Pine script `strategy.exit` and `strategy.close` don't respect `from_entry` value

怎甘沉沦 提交于 2021-02-11 15:17:58
问题 I have several different entries in my strategy, and I want to assign separate stop losses to them: // @version=4 strategy("Test strategy") strategy.entry("E0", strategy.long, limit=10000, when=close[1] > 10000) strategy.entry("E1", strategy.long, limit=10000, when=close[1] > 10000) strategy.exit("SL-E0", "E0", stop=9000) strategy.exit("SL-E1", "E1", stop=9500) As far as I understand the documentation (https://www.tradingview.com/pine-script-reference/#fun_strategy{dot}exit) the 2nd parameter

How to display/hide a hline using input from user?

爱⌒轻易说出口 提交于 2021-02-11 14:39:40
问题 I would like to allow users of my script to display or hide some dashed horizontal lines. I can't find the way to do this using hline. I've managed to do it using plot, but there is no dashed line format for plot. (I know there is a trick to plot dash lines: How to plot a dashed line on pine script V4?, but the end result doesn't look like the original hline dash line.) 回答1: //@version=4 study("") showHline = input(true) hline(50, color = showHline ? color.blue : #00000000) plot(na) 来源: https

Buy and Sell signals are differing by a candle with respect to plot

[亡魂溺海] 提交于 2021-02-11 14:34:53
问题 I tried to plot a graph based on the signals which are generated from the below strategy. But I observed from the script is signal generation points are differing by a Candle . If anyone will know about this please help me. For reference, I attached below snapshots 1. Buy signal snapshot 2. Sell signal snapshots //@version=4 strategy("My Strategy", overlay=true) orderType = 0 longCondition = crossover(sma(close, 14), sma(close, 28)) if (longCondition) strategy.entry("My Long Entry Id",

Pinescript conditional statement plotting

那年仲夏 提交于 2021-02-11 12:13:15
问题 I'm trying to create a plot to the chart based on the following conditions: It's the second consecutive green bar to open above the 9 day MA line It's oversold on the RSI I'm having issue is what order to write the condition, and knowing how many brackets I need? strategy(title="Swing Strat", pyramiding=1, overlay=true, default_qty_value=2, default_qty_type=strategy.fixed, initial_capital=100, currency=currency.GBP) //plotting MA lines MAPeriod9 = input(9, title="9 MA Period") MA9 = sma(close

Detecting session breaks

柔情痞子 提交于 2021-02-11 06:50:21
问题 A question about session breaks. I know that you can add Session Breaks to a chart by activating Session Breaks on the time scale of the chart. It then appears as a vertical line on the chart, whenever a Session Break occurs, indicating the start of a new session. That Session Break line can be formatted in the chart settings, under Appearance > Session Breaks. I'm trying to detect that Session Break in Pine Script. Is there a reliable way in Pine Script to detect the start of a new session?

Converting series integer to integer in pinescript

China☆狼群 提交于 2021-02-10 14:16:26
问题 I am using pinescript, and I have been trying to figure out why the following code does not work. The console keeps showing that series[integer] cannot output integer. I understand that series is not compatible with non-series values. If this is the case, is there a way to change series[integer] to integer? The following code does not work: x = barssince(crossover(cci,100)) y = barssince(crossover(100,cci)) xy = x-y //in this case the xy value is 9 z = highest(cci, abs(xy)) plot(z) The

Why is true / false logic on “style=” not working?

余生颓废 提交于 2021-02-10 12:34:45
问题 this is code that works: plotshape(xvalue, location=location.absolute, style=shape.labeldown, color=red, size=size.tiny, text ="Upper") this is code that doesn't work : plotshape(xvalue, location=location.absolute, style=(label?shape.xcross:shape.labeldown), color=red, size=size.tiny, text ="Upper") Variable "label" here is true/false variable. It compiles without errors, but it just doesn't plot. But it you use same logic on color, for example: color=(label?blue:red) It works without