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
0 answers

How to convert my online pine scripts to indicators for the charting library?

I've been through hundreds of sites, articles, repositories and chat rooms to try and find out how I could convert my scripts from the TV website into custom studies for the charting library. Most of the sites or guides say "send us your scripts and…
4UmNinja
  • 510
  • 4
  • 14
4
votes
1 answer

Compute the cumulative volume within the session in pine-script

I want to compute the cumulative volume of bars - within each trading session - in pine-script (TradingView.com). I wrote the script below but I get error "Script could not be translated from: for i = 1 to session_bar_counter" I've tried the below…
Silviu
  • 135
  • 1
  • 9
4
votes
2 answers

How to use stop-limit in Strategy

I'm trying to place a stop-limit order in my strategy-script but failed to do so. strategy.entry(id = "Long", long = true, limit=high[1]+10) I want a market buy order to be placed when the price is above 10 points previous candle. previous candle…
4
votes
1 answer

How to save value as condition after entering in a strategy?

I am having trouble with the following: I enter a strategy which is closed after close < ema. For the sake of a better exit, I would like to close it when close > ema but the low (of any given bar after the entry) is lower than ema (low < ema). I…
Mihail Bukov
  • 41
  • 1
  • 4
4
votes
1 answer

How to use leverage in pine script

How to use leverage in Pine Script? //@version=3 strategy("My Strategy", overlay=true, initial_capital=100) //enter position if (strategy.position_size == 0) strategy.entry("Short", false, 1) //exit position if (strategy.position_size != 0 and…
Aram
  • 51
  • 1
  • 2
4
votes
1 answer

How do you access the Pine Script Code Behind a public Indicator in TradingView?

Wondering how I can access the Pine Script code behind a public indicator which I have added to a chart in TradingView? Wanting to see exactly what is going on "under the hood". I have a free account (if that affects anything) Thanks!
cwse
  • 584
  • 2
  • 10
  • 20
4
votes
1 answer

Is it possible to trade multiple assets with one script?

I'm trying to implement a pairs trading algo in Pine Script but I don't know how to select a specific asset to buy or sell. It seems I'm locked with the current symbol.
Thiago Locks
  • 301
  • 3
  • 7
4
votes
0 answers

Pine Script - how to add filter from the higher time frame

I have the code below which would add filter based on my current (15min) chart time frame. My question is, how can I add to it to also look for the same but on 1hr chart? In other words, 15min chart and one hour chart would give me a signal to go…
forexfibs
  • 89
  • 1
  • 1
  • 3
4
votes
1 answer

How to use different string literals in PINE plot on trading view?

I have plot defined like this: plotshape(xvalue, location=location.absolute, style=shape.labeldown, color=red, size=size.tiny, text ="Upper") Problem here is with part text="Upper". I wanted to allow user to shorten label so it can be "Upper" or…
Mikeyy
  • 285
  • 1
  • 7
4
votes
1 answer

TradingView - How to set commission in percent?

How do I set strategy.commission.percent in Pine script? I know how to set commission as a percentage in the manual settings. But is there also a way to set commission with code? This is my strategy script: strategy("Working 55 & 200 EMA strategy",…
whitesiroi
  • 2,725
  • 4
  • 30
  • 64
4
votes
1 answer

Tradingview Pine Script, show Close Price in plotshape text

I have a label being plotted on an ema cross. Is it possible to show the close price in the text of the label? The code below doesn't like the builtin 'close' variable I'm trying to use. plotshape(crossover(ema1, ema2), title="Cross Over",…
user1444534
  • 41
  • 1
  • 3
4
votes
2 answers

Tradingview Pine script save close price at time of strategy entry

Hey I'm trying to save the close price at the time of strategy.entry to a variable so I can use it later for an exit. if condition strategy.entry("long", true) buyprice=close (strategy.exit("exit","long", when = close>buyprice*1.1) I get…
Binjo1
  • 43
  • 1
  • 1
  • 5
3
votes
1 answer

How Do I Calculate The Average Time For All Trades Of A Strategy?

Okay, there are two things I can't seem to do. I need to calculate the time between all trades of the strategy (from each individual trade's entry to exit), then out of all of these, average them. Then, convert that output to minutes. Let's call it…
3
votes
1 answer

How to rewrite my Pinescript code to Python

I am trying to rewrite this code to Python: src = input.source(close, "Source") volStop(src) => var max = src var min = src max := math.max(max, src) min := math.min(min, src) [max, min] [max, min] =…
3
votes
1 answer

Shift pinescript series by one

Suppose I have a pinescript series current that looks like this; current = [1 0 0 1 0 0 1 0 0 1] I want to shift this series backward by 1. The shifted variable will look like this; shifted = [1 0 0 1 0 0 1 0 0 1 0] The last sample of shifted will…
FDL
  • 115
  • 8