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
4
votes
1 answer

Pine Script Strategy - How to trigger entry when *price* (not close) crosses a certain value? Currently entering trade one candle too late

Just playing around, learning how to write strategies. The one I'm trying right now is (pseudo-code)... if(previousCandle == red ... AND previousCandle.high >= sma ... AND previousCandle.low <= sma ... AND currentPrice >…
Birrel
  • 4,754
  • 6
  • 38
  • 74
4
votes
1 answer

Extracting string value from a string array in pine

I want to build a strategy for which I need to have the values of all stocks of a given index, let's say the DAX 30. I'm building a string array with 30 values, each value being the ticker name of a DAX stock, e.g.: var dax_names =…
Giuliano
  • 51
  • 1
  • 2
4
votes
1 answer

How can I plot my historical trades/executions in Tradingview the same way as in Ninjatrader?

I'd like to know if we can draw past trades using a script. I basically want to access my history of executions and draw lines at the price where I did them, to have a clear picture of my winning and losing trades. Is that possible in pine? For…
Daniel
  • 41
  • 3
4
votes
2 answers

Get Value of MACD on different TimeFrame

How can you get the value of the Macd Line and Signal Line real-time from different timeframe. Like for example I am on a 4HR chart and I want to get the value of the Macd Line and Signal Line from the 1 hr timeframe. I know how to get the value of…
Pablo
  • 145
  • 1
  • 8
4
votes
2 answers

Tradingview Pine scripts giving resolution error for line draw function

//@version=4 study(shorttitle="try", title="line", overlay=true, resolution="") line.new(x1=bar_index[10], y1=close[10], x2=bar_index, y2=close) I want to draw a simple line in trading view chart using pine scripts. I am getting resolution error.…
bhpwork
  • 41
  • 1
  • 2
4
votes
4 answers

Is there a way to hide specific indicator values from the data window?

I have recently created a script that plots several different indicators on a chart in TradingView. Under specific scenarios, some of the indicators are not active and show "n/a" in the data window. I know that TradingView allows us to hide all…
Arvi
  • 41
  • 1
  • 1
  • 2
4
votes
1 answer

error message:The study references too many candles in history(10001)

I cannot debug the error message.Please help and many thanks. Previously I used pivothigh() and valuewhen() to code, it worked perfect,but I got warning message when setting alerts. So that I use Dif[2]>Dif[1] and Dif[2]>Dif and so on to replace…
David Liao
  • 61
  • 1
  • 7
4
votes
1 answer

How to make global variable in pinescript(Tradingview)

I am working on creating a trend indicator in tradingview to track which way the trend is going. Specifically, I want a variable that will stay the same over days, but when a certain condition is met it will change. It seems like it should be simple…
Jason Maynard
  • 359
  • 1
  • 3
  • 15
4
votes
1 answer

tradingview pine script error "cannot use 'plot' in a local scope"

I am trying to write a simple if-then-else statement using the Pine language under Tradingview. What the code does is based upon user input. If the box is checked, the plot the line. If the box is not checked do not plot the line. This is the code I…
Casey Harrils
  • 2,793
  • 12
  • 52
  • 93
4
votes
2 answers

Converting Float into Int values Pine-script

Hello i am trying to include this type of moving average(elastic volume weighted moving average) evwma = 0.0 evwma := ((volumeSum - volume) * nz(evwma[1]) + volume * src) / volumeSum into my indicator (VWGSV) where the upper forumula must replace…
wuasile kerpici
  • 65
  • 1
  • 1
  • 6
4
votes
2 answers

Tradingview Pine-Script: How to plot only the last x periods

I'd like to plot an indicator only for the last x periods. How do I do that? If I could do time operations (substract x * period from plotStartDate), maybe I could use this code: period = timeframe.ismonthly or timeframe.isweekly ? "12M" :…
cody
  • 6,389
  • 15
  • 52
  • 77
4
votes
1 answer

PineScript - descending MACD histogram

I am learning some PineScript in my free time and I find it really diificult to work with. I am basically trying to recreate a complicated indicator I wrote in C# and I am struggling with simple things. Ommiting the complicated stuff, lets say I…
rvnlord
  • 3,487
  • 3
  • 23
  • 32
4
votes
4 answers

label getting duplicated every time a new bar is presented

i write pine with Tradingview and each time there is a new bar my text is being duplicated. i need the label to move to the new bar only. //@version=4 study("My Script") plot(close) label.new (barstate.islast ? time :…
Oren Teich
  • 47
  • 1
  • 4
4
votes
1 answer

Trouble with my strategy buying but not selling in pine editor

I am using pine editor to make a strategy that buys when the D line which is the green line crosses under 17.5 and then sells when the D line crosses over 78. As you can see from the chart I have posted it should buy and sell a couple times but only…
ColtonMSU
  • 41
  • 6
4
votes
1 answer

Adding a functioning custom indicator to a tradingview strategy

I am very new to pine script and coding in general, and I can't find a way to add the code of a working indicator to a crossover strategy on tradingview. If would appreciate a lot if you could point me in the right direction. I have tried pasting…