Questions tagged [pine-script]

Pine Script is a domain-specific language for coding custom technical indicators and strategies on TradingView. Use this tag for questions related to programming in Pine Script. Please do not use the [tradingview-api] tag for Pine-related questions.

Filter by
Sorted by
Tagged with
0 votes
0 answers
8 views

TradingView - How do I compute the highest % deviation from the 20 SMA over the past 200 bars?

I'm attempting to programmatically determine when the price on a given asset deviated the most from the 20 SMA. I wrote the code below which loops over the past 200 bars and determines the % ...
  • 2,680
0 votes
1 answer
8 views

How to draw a freehand line using pine script?

I want to draw resistance and support lines by hand, import them to pine script, and calculate the distance(percentage) of the current value of the price and the drawn line(support or resistance). I ...
0 votes
0 answers
18 views

How to calculate the Bar_Index variable's left and right values for box.new()?

I'm attempting to draw a box on a single candle however when using the following code, the width of the box is only the width of the wick of the candle, instead of the candle body. Here's an example ...
0 votes
0 answers
14 views

Extraneous input '0' expecting ']'

I encountered the following error: Extraneous input '0' expecting ']' Please tell me where I went wrong and how to fix it? Thanks a lot. //@version=5 indicator("Count EMA Crossovers", ...
  • 31
0 votes
0 answers
9 views

Tradingview pine script " Cannot use 'plotshape' in local scope." [closed]

Mittels Pine Script soll in einem Tradingview Chart ein Signal generiert werden, wenn ein Kurs an drei aufeinanderfolgenden Tagen steigt. Diese Aufgabe wurde chatGPT gegeben. Der Bot erzeugte mehrere ...
0 votes
0 answers
16 views

Tradingview’s Pine: comparison operator alert

Code below records the lowest and the highest value since the script is started and calculates percentages of these, in comparison to the current value of the active bar. For the alert, a certain ...
0 votes
1 answer
10 views

Pine Script v.5 error: “Could not find function or function reference 'macd'”

I am not a programmer and struggling through Pine Script v.5. I have a Bollinger band indicator which uses as its source the MACD histogram. I am trying to code a strategy that, when the histogram is ...
0 votes
1 answer
16 views

Pinescript plotshapes assistance required

I have made an custom indicator in TradingView which plots arrows whenever buy or sell conditions are met. Here is the code:- Pinescript version = 5 //RSI Calculation rsiValue = ta.rsi(close,14) //...
0 votes
0 answers
11 views

How to Add a Boolean to an Array function?

I have the following array in pinescript that controls the output of the indicator array.set(sr_lines, x + 1, line.new(x1=bar_index, y1=mid, x2=bar_index - 1, y2=mid, extend=extend.both, color=mid >...
0 votes
1 answer
26 views

Using Plotcandle with condition

how can i use a boolean inside Plotcandle? plotcandle(open_c, open_c, close_c, close_c, title='Candles', color=open_c < close_c ? color.new(#003c7f,50) : color.new(#991722,50), wickcolor=na, ...
-1 votes
0 answers
11 views

Tradingview Pinescript5 request.security - can not add Timeframe change to script

Hi I am trying to add Timeframe Change to script below using request.security, but it does not work Script is for displaying Equal Highs and Equal Lows, original version below and modified lower: ...
0 votes
0 answers
10 views

line.new doesn't render a function with volume but close

I am attempting to create prediction lines using the function vwma(). Previously, I tried using the function sma() and it worked, but I am having trouble with vwma() as the lines are not appearing ...
0 votes
1 answer
22 views

Adjust SL to Entry Price at First TP?

I'm trying to create a tradingview pine script strategy that manages trades as such: Every open trade will have a stop loss, and 2 take profit levels. The SL level will be at a multiple of the ATR as ...
0 votes
0 answers
14 views

"Loop takes too long" or bug in Pine Script?

This simple script produces "Loop takes too long" error. Is this a bug in Pine script? Since initiating nL with 100 also produces "Internal server pine compilation error" an error, ...
  • 49
0 votes
1 answer
9 views

How can I plot levels from a spreadsheet in Pinescript?

I have a spreadsheet of intra-day support and resistance levels sorted by date. I want to write a script in Tradingview that plots these levels on a chart for backtesting purposes. So far I tried ...
0 votes
1 answer
15 views

Defining bar as swing top Pine Script

Chart of what I am trying to achieve Hi! I've tried to define a swing top as an upbar followed by a downbar. And the swing top being the high of the first bar, the upbar that is. The ST in green is ...
  • 3
-2 votes
0 answers
11 views

mismatched input 'if' expecting 'end of line without line continuation' error

can you please help with the error I get? I tried the indents but no result // Check for divergence bull_divergence = reg_slope_prices > 30 and reg_slope_stochastic < -30 bear_divergence = ...
0 votes
1 answer
32 views

Pine Script strategy entry strategy close

Good afternoon, I'm using this strategy and I would like it to close the open order before opening the next one. I'm trying to automate the signals by webhook, and it sends the buy and sell signal but ...
0 votes
1 answer
18 views

looking way back in the past data within pine not working anymore

Previously I was able to test couple years of backtest data in pine (even if it was not visble on chart) through the following code // === INPUT BACKTEST RANGE === fromMonth = ...
1 vote
1 answer
12 views

Previous week open and close in a pine script

new to pine. I can get the open/close of the previous trading day no problem as follows: openprice = request.security(syminfo.tickerid, "D", open[1]) But what I want is the previous weeks ...
0 votes
0 answers
11 views

How to factor in a fixed bid-ask spread within a strategy?

During backtesting in TradingView, trades can seem more profitable than they appear because the spread is not factored in. This is especially true on lower timeframes with a tighter stop loss. For ...
  • 3
0 votes
1 answer
20 views

How can I fix a pine script strategy.exit error when I am missing one of the parameters, but they appear to be present in the code?

I am receiving this error message when trying to convert a Pine Script v4 strategy to Pine Script v5. strategy.exit must have at least one of the following parameters: 'profit', 'limit', 'loss', 'stop'...
0 votes
1 answer
33 views

Tradingview’s Pine: saving var between bar

Saving variable value between bars for future use shall be possible by using var during a variable’s declaration. In the case at hand the highest identified bar value shall be saved and updated if an ...
0 votes
1 answer
30 views

I want to make a PineScript V5 Strategy with ADX and RSI But keep receiving the same error

It just seems that I can't figure out the correct script for my strategy, which is the following: Buy signal when the ADX is above 46 and at the same time the RSI is oversold at or below 20 Works ...
-2 votes
0 answers
20 views

zigzag indicator issue on python [closed]

i have this function on pine script that return value _zigzag ,how can i create the same function using python binance api: zigzag() => _isUp = close >= open _isDown = close <= open ...
0 votes
2 answers
27 views

Converting an Indicator in TradingView from V2 to V5

I am trying to convert this indicator "Hilo Activator" from v2 to v5. I did everything except the "stop", it kept saying the that it is undeclared identifier "series". ...
0 votes
1 answer
21 views

How to add an input.bool to Supertrend indicator?

I am working with the following code in pine-script: indicator("Volatility Trend", overlay=true) [supertrend, direction] = ta.supertrend(3, 10) TrendVolatility = input.bool(false, "...
-1 votes
0 answers
8 views

Arrows signal in heikin ashi where no wick

I was looking for Arrow signal on Heiken Ashi chart with no wick for tradingview pinescript I tried some code but it not workenter image description here
0 votes
1 answer
19 views

why is the script not calculating all displayed bars?

I am totally confused why the script only shows labels for last 30 bars? I want to get the high for every 10 bars back and display at the bar with the high (bar_index_high) the high value (highValue). ...
  • 25
0 votes
2 answers
24 views

How to plot beyond the last bar in TradingView Pine Script?

I'm looking for a way to adding some additional bars after the last bar on the chart, and based on the bars extending the indicators on the chart so I can TA based on the future indicator values ...
0 votes
0 answers
17 views

Pine Script receiving an "Syntax error at input"

I'm coding ML script using a library, and it gives syntax error, i'm trying to manipulate data from single array //@version=5 indicator("My script") import E5Trading/E5TradingLibrary/1 as ...
0 votes
1 answer
19 views

Repainting issue with barmerge.lookahead_on in security

I tried to extract closing data from higher timeframe. But It is repainting when I add the lookahead = barmerge.lookahead_on. It is not repainting when the lookahead is not entered. Not sure what's ...
  • 1
0 votes
1 answer
22 views

Color parameter in a Pine Script function doesn't respond to if condition

I am running into very odd results when I try and make Pine Script functions and I am not sure why. Here I have a function that will help me update lines that I keep in Arrays. The issue that I run ...
1 vote
1 answer
33 views

How can i combine RSI and Nadaraya-Watson Envelope

I'm new to programming in Pine Script language and I'm trying to combine the RSI indicator with the Nadaraya-Watson Envelope by LuxAlgo. The strategy basically is that when the price crosses the upper ...
0 votes
1 answer
15 views

Problum auto redirected to the original script/indicator

I just edited one of the existing indicator scripts and added an alert function to it without disrupting other parts of the script. However, when I added the modified script to the chart, the ...
0 votes
1 answer
27 views

Pine script giving error: Incorrect 'for' statement. Expecting 'to <expression>'

//@version=5 indicator("Stock Price Above 200 SMA and 10 Period RSI Below 30", shorttitle="Stock Price and RSI Indicator") // Define inputs sma_period = input(title="SMA ...
0 votes
1 answer
16 views

In Pine Script, my buy and sell signals lag the ma crossover on the chart

I know this a very basic code, but I'm confused as to why when I plot the 12 and 36 period ma, it will show a crossover, but the buy and sell signal will not occur for 2-3 bars afterward. // This ...
0 votes
0 answers
17 views

Hi I'm facing an issue with pine script

I'm facing an issue with my pine script with this error don't know what to do. Cannot call 'plot' with 'series'=void. The argument should be of type: series[float]; help please changing the script!!!
0 votes
1 answer
12 views

How to Integrate Exponential Moving Average into a Strategy on Pine Editor in Trading View

I would like to know if it is possible to integrate into my strategy, an exponential moving average, starting from the indicator: But that the timeframe is modifiable in my strategy. I hope to express ...
  • 1
0 votes
1 answer
15 views

Shifting a plotshape in pinescript

I am building an indicator to detect peaks and have it working fine in thinkscript but need it to work in pine script as well. Thinkscript allows you to offset using future bars but I had to refactor ...
0 votes
1 answer
22 views

How to determine whether an instument accepts decimals for qty?

some instruments accept decimals for strategy.entry qty (eg I can buy 0.01 contract of BTC), however some don't (eg oil futures CL1! accept only whole numbers for contracts). Is there a way to ...
0 votes
1 answer
12 views

SL Exit Problems in my Inside Candle Strategy

Sometimes It exits very accurately, sometimes It get didn't get exitted on time, sometimes It get exiited very incorrectly and sometimes It get exitted at the same time of entry. I am very much ...
0 votes
0 answers
11 views

Right to left trading view features of the chart

I want to know how to right to left features in trading view chart. For example, How to rtl the date of chart I saw the setting in trading view that changes stack to right or left, but that did not ...
-1 votes
0 answers
18 views

Can someone help convert this script into Version 5 [closed]

So, I have this script but its super old, but I am not having any luck converting it to version 5, I do not have enough knowledge in pinescript, so if someone can help me convert it, I really would ...
  • 17
0 votes
1 answer
23 views

Im looking to only have one alert per trend not every cross on a horizontal line script

I have a horizontal line script and when the ma crosses a horizontal line it trades but it continues to trade on every cross. Im only a copy and paste coder and the guy i paid to help me has made it ...
-3 votes
0 answers
13 views

current price plus x amount of pips [closed]

I want to test een script on the forex market with the entry reason being the current price plus + x pips. The take profit needs to be in an amount of pips the stop loss needs to be in an amount of ...
-1 votes
1 answer
29 views

I have a good (working) indicator, but it is in version Pine2. It is not converted to version Pine3 and writes such errors:

I have a good (working) indicator, but it is in version Pine2. It is not converted to version Pine3 and writes such errors: //Error Undeclared identifier bb; FFF (xx,xxur,wwur)=> bb=(xx < ...
0 votes
1 answer
26 views

Why is timeclose and timenow variable in my code works with the indicator function but not the strategy function?

I'm working with a bot in pinescript, here's my code: //@version=5 indicator("timeStrat") secondsLeft = barstate.isrealtime ? (time_close - timenow) / 1000 : na // Display countdown on ...
  • 19
0 votes
1 answer
24 views

Wick doesn't triggered signal of crossunder or crossover

I have an issue with an indicator. I am “shapeploting” crossovers and crossunders. Signal should be triggered if the equal if body or wick is crossing the daily high or low. As you can see in the ...
  • 361
0 votes
0 answers
19 views

What is code / syntax for "Scale Price Chart Only"?

Does anybody know code to make visual like we use 'Scale Price Chart Only' enabled? I have indicator on panel (overlay = false /, not plot on chart) that plot candles and also lines (using 'line.new')....

1
2 3 4 5
124