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
8
votes
2 answers

How to draw a vertical line at a certain time in pinescript on Tradingview?

I would like to draw a vertical line, every day at a certain local time (e.g. 08:00 GMT+1). Since my last post about vertical lines, pine-script has been updated to include vline(), however, the issue here is getting the time right. Most servers…
not2qubit
  • 14,531
  • 8
  • 95
  • 135
8
votes
1 answer

Calculate SMA's Slope in pine script

I'm want to calculate the slope for the Simple Moving Average's (SMA). I have already tried the following code which is mathematically correct. rad2degree = 180/3.14159265359 //pi sma2sample = sma(close,50) slopeD = rad2degree*atan(…
Aerox
  • 353
  • 3
  • 13
8
votes
1 answer

I got TradingView's 'end of line without continuation' error with Pine Script

I am using this code in Pine Script but getting the "mismatched input 'a' expecting 'end of line without line continuation'" error. How to fix that error with this function code? val(s) => if s != s[1] a = s-s[1] if s = s[1] a …
Bassel Alahmad
  • 155
  • 1
  • 2
  • 9
7
votes
2 answers

How to view aggregated liquidations for cryptocurrencies from Binance?

On these sites (https://coinalyze.net/ethereum-classic/liquidations/, BTC/USDT), I am able to add following indications into grpah [Liquidations, Long Liquidations, Short Liquidations, Aggregated Liquidations COIN-margined Contracts, Aggregated…
alper
  • 2,919
  • 9
  • 53
  • 102
7
votes
3 answers

Plotting within a Loop, Cannot use 'plot' in local scope. (TradingView Pine Script)

I am having trouble figuring out the proper implementation while trying to clean up my code and I found a section that seemed ripe for a For-loop, however, I receive the following error: Cannot use 'plot' in local scope. When trying to do the…
Brett
  • 154
  • 1
  • 2
  • 11
7
votes
2 answers

How to plot a dashed line on pine script V4?

Trying to plot a normal serie line but with the V4 of pine script I can't find how to set the style? This gives me an error : plot(my_serie, color=color.blue,linewidth=2, style=line.style_dashed) Any help appreciated.
Idris
  • 600
  • 2
  • 4
  • 16
7
votes
3 answers

How to put plot statement inside if statement

I want to plot the equity curve on the price, to compare the strategy to simple buy and hold. To make the graph useful, the equity curve could either start on the initial equity, or in line with the first price on the graph or no equity curve at…
Benster
  • 81
  • 1
  • 2
  • 3
7
votes
1 answer

Place multiple stop exit orders for single entry

In a strategy on tradingview, I enter an entry and have a condition to place a trailing stop. At the same time I want a stop-loss order at a fixed price, but when I place two strategy.exit() commands, only one is actually used, because both are of…
Paul
  • 293
  • 2
  • 12
7
votes
2 answers

How to use the active time frame as a variable in a condition?

I want to write an indicator for tradingview that should draw a vertical line on a specific level depending on the active time frame, e.g. on the 5-minute-chart the indicator should draw the line at a different level than on the 60-minute-chart. I…
a kind person
  • 329
  • 1
  • 6
  • 17
7
votes
2 answers

Adding variables to alerts in pinescript

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…
Eric
  • 1,209
  • 1
  • 17
  • 34
7
votes
2 answers

How to implement Moving Average in TradingView?

I want to implement the Moving Average (MA) TradingView. There are already some built-in functions for moving averages (like sma(), ema(), and wma()). Now I want to built my own MA function. Can you help me? Thanks.
ledien
  • 529
  • 2
  • 8
  • 19
6
votes
1 answer

Why am I getting error: could not find function or function reference 'study'?

//DeMark_9_Indicator_Wealth_Insider study("DeMark9 Indicator",overlay=true) TD = close > close[4] ?nz(TD[1])+1:0 TS = close < close[4] ?nz(TS[1])+1:0 TDUp = TD - valuewhen(TD < TD[1], TD , 1 ) TDDn = TS - valuewhen(TS < TS[1], TS , 1…
Narely
  • 61
  • 1
  • 1
  • 3
6
votes
1 answer

Tradingview - pine script for Take profit and Stop loss by percentage

I have a serious problem merging Take profit and Stop loss in one script. I'm using this script for TP https://kodify.net/tradingview/orders/percentage-profit/ and this one for SL https://kodify.net/tradingview/orders/percentage-stop/ I came up with…
mkoism
  • 63
  • 1
  • 1
  • 3
6
votes
3 answers

The function should be called on each calculation for consistency, console output?

My script has just recently started to show these lines in console, when I add to chart or save. "The function 'anonym_function_10' should be called on each calculation for consistency. It is recommended to extract the call from the ternary operator…
cryptobar76
  • 61
  • 1
  • 1
  • 4
6
votes
2 answers

Tradingview - How to use multiple input type=source

I'm currently trying to set up a script to generate conditional alerts whenever another script displays several specific data points. input(type=source) works no problem, but as soon as I try to add more than one source input, it stops working all…
saix
  • 61
  • 2