This tag should be used for questions relating to scripts and code built specifically on version 5 of Trading View's Pine Script language.
Questions tagged [pine-script-v5]
2372 questions
1
vote
0 answers
buy/sell alert script for determined market structure sequence
i already have plotted the market structure (higher high, lower low, etc.) but i have a problem to create alert script when determined market structure formed, for example i need sell alert when the market structure formed : LL,LH,HL
help me please,…

Rahwana Prabu
- 11
- 1
1
vote
1 answer
Is it possible add cash during the calculation of a strategy? (backtesting strategies for DCA)
I would like to add cash on a monthly basis. 'initial_capital' can only be static, it's not possible to put in a variable unfortunately.
I know I can track the investment with own variables, but I think there must be some way to calculate your…

telejoshi
- 13
- 2
1
vote
1 answer
interesting project Ignoring exit condition on first candle
In a strategy with entry and exit conditions, is it possible to set a conditional expression that ignores the exit condition in the first candle where the entry occurs?
That is, the exit condition is activated from the second candle
I'm new to…

김한수
- 15
- 3
1
vote
1 answer
Close position X bars before a user specified time in Tradingview
Almost every day at 14.30 CET European indices and futures change substantial because data from the US become available.
Also when US markets open at 16.00 CET European markets react again and keep following US markets afterwards.
I noticed that…

SoftwareTester
- 1,048
- 1
- 10
- 25
1
vote
1 answer
How can I get the source code of the built in bullish flag chart pattern on trading view?
How can I get the source code of the built in bullish flag chart pattern on trading view? I have tried finding it in the free indicators but could not find anything. the link for the chart pattern in trading view is as…

Vinod Sharma
- 11
- 2
1
vote
2 answers
pinescript strategy.exit() function sometimes not executed when Take Profit (limit) target is reached?
I'm creating a strategy with the following code, and whilst manually verifying the orders I have encountered a couple of instances where the strategy.exit() function is not executed when the Take Profit (limit) target is reached, despite there being…

Philayyy
- 1,767
- 4
- 16
- 22
1
vote
1 answer
How to wrap long if statements in pinescript?
In pinescript is it possible to wrap a long if statement such that each condition is on a new line?
Example:
if condition_1 or condition_2 or condition_3
//do something
Desired format:
if condition_1 or
condition_2 or
condition_3
//do…

Jean-Baptiste Bolh
- 25
- 3
1
vote
2 answers
Pine Script v5 bug with bool inputs initialized with constant non-bool values (does TradingView actually care about bugs?...)
I have so far found two quite severe bugs in Pine Script v5. And here is another one.
This is not really a question, rather, I think people can benefit from this if they encounter such behavior too, hopefully I can save them some time.
So. Pine…

Alexei Andronov
- 99
- 7
1
vote
1 answer
Declaring and using variables in same line (Pine Script)
Can you explain line 11 and 12? In these lines, the author is declaring TrendUp and TrendDown variables and instantly using it? On that basis what is the initial value of these variables? Please expain whole lines 11 and 12 (below)…

S3emingly
- 15
- 5
1
vote
0 answers
unable to dynamically sort array
I am trying a fib level based trailing stop and trailing target strategy.i want the strategy to check and recalculate the trailing stop and target after close of each candle. for long trades the fibonachi retracement levels above will be target and…

RAGHU RAM G
- 31
- 6
1
vote
1 answer
How to get the latest closing price in pinescript?
I would like to get the latest closing price in pinescript. I thought this is a simple thing to do, yet I face difficulty.
I tried close but this returns the closing price of the bar selected by the mouse. What I want is the closing price of the…

FDL
- 115
- 8
1
vote
1 answer
Once buy condition is true stay true until sell condition is true
In a nutshell: Once buy condition is true, stay true until selling condition is true, even if buy condition becomes false in between.
Basically I'm using 2 ema strategy and want to display only stoploss ema
maSmall = ta.ema(low, 50) //1st 50…

Amit
- 13
- 3
1
vote
1 answer
Using assert in pinescript
I would like to use assert in pinescript for bug detection. assert statement is available in python and C/C++. I hope there is an easy way to use assert in pinescript.
There's a library available but it looks complicated to…

FDL
- 115
- 8
1
vote
1 answer
BUY&SELL both are happening at the same time though the signal either BUY or SELL
Context: I'm backtesting the below strategy. What I observed is, when ever the BUY or SELL signal alert triggers, instead of executing the corresponding order, it executing both SELL&BUY orders. It doesn't matter which signal is triggered. But if…

Ravi Kiran
- 11
- 1
1
vote
1 answer
Why does =: operator affect previous lines?
I'm trying to understand a script in pine script. I can't find the reason for the different outputs for similar codes.
First code:
//@version=4
study("CE", overlay=true)
length = input(title="ATR Period", type=input.integer, defval=22)
mult =…

denizt
- 13
- 2