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.

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.

6637 questions
3
votes
1 answer

Auto scaling disable for indicators in trading view chart pine editor

I trade using Pivot Points. I use the following on screen indicators indicators “CM_Pivots_Filtered”, “Pivots”, “CD_PivotR” and “CM_Gaps_Intra-Day_V2.1” These pivots work perfectly. However, when I deploy them all and the Auto Scale button is…
rohan sawant
  • 121
  • 1
  • 14
3
votes
1 answer

How to implement a conditional length moving average in TradingView pinescript?

I'd like to implement a moving average where the length is based on an n-back average cycle length K. Thus, I need the length to be a function of the variable K. The built-in moving average allows only a static integer value for length. I have a…
bmf
  • 55
  • 1
  • 7
3
votes
2 answers

Why won't this code run in Pine Script 4? "Undeclared identifier"

Resources are still Pine Script 3 heavy, so I think I'm mixing something up: I tried to create an Average Daily Range indicator, which is basically the ATR that takes a "D" input no matter what the time frame of the current chart is. My code works…
alexeix
  • 77
  • 1
  • 1
  • 8
3
votes
0 answers

How to fix history vs realtime data issue with security function in tradingview backtesting

I'm really struggling using my indicator during backtesting because it plots the future daily highs and lows before it even reaches them. According to pine script, this should solve the problem: // To avoid difference in the calculation on…
3
votes
2 answers

How to get close price for normal candles in Pine script while using Heikin Ashi candles?

I want to plot difference between current Heikin Ashi (HA) close price and real close price (on normal candles) in Pine script 3. Seems like it can work if I use normal candles on chart but if I use Heikin Ashi, I get HA close price instead of…
Helyrk
  • 93
  • 1
  • 8
3
votes
2 answers

Is there a way to detect chart background color in tradingview pine script?

Would like to detect if user has dark mode on or if it has black background set in trading view chart. My script uses black lines because it's adjusted to white background chart, and when someone uses dark background, they don't see a lot of script…
Mikeyy
  • 285
  • 1
  • 7
3
votes
1 answer

In Pine-script, how to assign the value of the previous bar to the current bar based on a condition of the current bar in a custom indicator?

In Pine-script, I need to assign the value of the previous bar to the current bar based on a condition of the current bar in a custom indicator. I have tried various methods of coding this resulting in either an internal server error or compile…
Mark
  • 33
  • 1
  • 1
  • 4
3
votes
0 answers

Pine-Script to Python Why the Converted "On Balance Volume -OBV indicator" not matching with TradingView chart value

I have been trying to get python coded pandas logic output exactly same as the trading view chart output for "OBV - On Balcance Volume" some of the Pine Script Reference for OBV: study(title="On Balance Volume", shorttitle="OBV") src = close obv =…
Marx Babu
  • 750
  • 3
  • 11
  • 34
3
votes
2 answers

How to write a stochastic-RSI indikator

My indicator does not look like the built-in Stochastic RSI indicator from TradingView. How can I get the familiar look, to duplicate the st-RSI indicator? Here is the screen shot that shows the difference between my code and the TradingView…
Sven
  • 45
  • 1
  • 3
  • 6
3
votes
4 answers

Is there any workaround for arrays in Pine Script

Arrays are not available in PineScript. Is there any workaround? Has anyone developed a code, which works as array? What do I need it for? I would like to count number of touches to each trendline or S/R level.
PeterO
  • 89
  • 1
  • 1
  • 5
3
votes
2 answers

TradingView Pine Script - Creating a Stop Loss that moves up under certain conditions

I want to add some code to my strategy on TV that will update the stop loss level when the price moves up by X%. Basically, I am trying to update the variable multiple times. Everything I've tried creates a stop that moves up and down. I want it to…
3
votes
2 answers

How do I add a number suffix to my script? K thousands, M million

Tradingview by default shows volume numbers as (K) Thousands and (M) Millions. How do I add this to a custom script I created? For example, if I see Net Volume as 1740654.0000 on a bar, I would prefer it shows as 1.74M instead.
ECH5030
  • 424
  • 1
  • 4
  • 11
3
votes
1 answer

Highest high "of the last n days", not "n days ago"

If I want to compare the close of today with the high of the last 4 days, what is the format? I have used _hi = close > high[4] ? 1 : 0 But that only counts the high 4 days ago, not the days in between. I have tried _hi = close > high[1,2,3,4] ? 1…
sunspore
  • 127
  • 1
  • 4
  • 13
3
votes
1 answer

Tradingview Pinescript work with the := operator

I want to understand how to := and sum[1] works. This sum returns me 6093. But sum is 0, also sum[1] = 0 , am I right? How it returns me 6093? I searched the tradingview wiki, but i didnt understand. I want to change this code to another language…
Emre Ekşioğlu
  • 359
  • 2
  • 13
3
votes
1 answer

TradingView Pine script's time() function for weekends?

I'm developing an indicator that shows custom time zone sessions by changing chart background. For that I use this function to check if one bar is inside one of my defined time sessions: InSession(sess) => na(time(period, sess)) == false Where sess…
Juan Antonio Tubío
  • 1,172
  • 14
  • 28