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

Hide trades on chart, quantity and signal labels via code tradingview/pine script

Every time I update the code for a strategy the styles are reset which means that: Trades on Chart Signal labels Quantity are reset to be displayed. Is there a way to override that behavior so I can keep the 'Trades on Chart' hidden? Thank you…
2
votes
1 answer

How to use tuples as inputs to a function in PineScript?

For readability, I have been trying to send tuples as input to functions in pinescript. But I haven't found a way to make it work. This is the basic idea of what I would like to accomplish: aFunction(xy1,xy2) => [x1,y1]=xy1 [x2,y2]=xy2 …
Edgar Brown
  • 253
  • 2
  • 11
2
votes
0 answers

Is it possible in Pinescript to plot the first engulfing bar (open and close)?

This is the code that I use for the bullish engulfing: engLong = (close >= open[1] and close [1] < open[1]) close_engLong = valuewhen(engLong, close, 0) plot(close_engLong) The engulfing consists of 2 bars and with this code the script draws…
2
votes
1 answer

Pine Script Strategy with Long and Short trades at the same time

I'm making a strategy in Pine script v5, at the moment either if I run ONLY Long trades or Short trades my script works fine, but when i run long and short trades at the same time the strategy first closes the current trade and then opens the new…
2
votes
2 answers

Why does pine script enter at the next candle open even when I am using a market order?

I am trying to implement a 2 period RSI based strategy backtest in Pine Script. The idea is simple Objective 2 Period RSI crosses under 10, when 200 EMA is below the recent close, I go long on the next candle with a market order set to limit 2%…
Abhishek
  • 1,101
  • 8
  • 8
2
votes
2 answers

How to convert TradingView Pine Script code to JavaScript?

There are some indicators on TradingView website that are in pine script and I like to add them to chart library so I have them on my website. But I've done a lot of search, and didn't find how to do that. Any help would be appreciated. This is on…
yaghoob_pr
  • 21
  • 1
  • 4
2
votes
1 answer

Pinescript basic question: Open a trade at a set time each day

I'd like to create a Pinescript strategy that opens a trade at 6pm ET each day. SL: 2xATR. TP: 2x SL. I am struggling with setting a Boolean variable to be TRUE if the close time of the bar is 6pm ET. I'm (obviously) very new to Pinescript and would…
2
votes
0 answers

Pine script - dolar cost average strategy

I'm new to Pinescript and am trying to build a strategy that would place an initial order at a limit price and will DCA (dollar cost average) the position if the price drops by x percent. I've managed to get initial order placed with the code below,…
2
votes
0 answers

TradingView pine script - draw plot for specific date with trendline

Here's what I'm trying to do. I want to create an indicator in pine script where the user inputs the date/time they sold a short call/put and the strike for which they sold. Then I want to create a plot line just for that specific date at the start…
user1015196
  • 617
  • 1
  • 7
  • 24
2
votes
1 answer

Pinescript error - itemType is not defined

while trying to save below code it throws error. line 21: itemType is not defined The error goes off if i remove rsievent from return value within the function. Seems like something woring with handling of string variable '[value, cond,…
2
votes
1 answer

Cannot use 'bgcolor' in local scope [Pinescript] [tradingview]

Cannot use 'bgcolor' in local scope my code : //@version=4 //strategy("try 2", overlay=true) study("Astrolog 2", "Astrolog 2", overlay=true) yearStart = 2015 yearEnd = 2021 for counter = yearStart to yearEnd [1] i_startTime = input(defval =…
Wauputra
  • 211
  • 1
  • 7
2
votes
2 answers

Pine-script How to calculate on close when calc_on_every_tick=true

var line _lpLine = line.new(0, 0, 0, 0, extend=extend.left, style=line.style_dashed, color=color.yellow) _lastTradedPrice = close line.set_xy1(_lpLine, bar_index-1, _lastTradedPrice) line.set_xy2(_lpLine, bar_index, _lastTradedPrice) The code…
bbnm
  • 1,034
  • 1
  • 4
  • 14
2
votes
0 answers

PineScript - How to get historical daily close price

Any built-in function in PineScript to get historical daily closing price? ex - how to get AAPL's daily closing price on 01-Jul-2021 (or any other historical date)?
2
votes
2 answers

Tradingview pinescript's RMA (Moving average used in RSI. It is the exponentially weighted moving average with alpha = 1 / length) in python, pandas

I've been trying to get same results from tradingviews RMA method but I dont know how to accomplish it In their page RMA is computed as: plot(rma(close, 15)) //the same on pine pine_rma(src, length) => alpha = 1/length sum = 0.0 sum :=…
edgarmtze
  • 24,683
  • 80
  • 235
  • 386
2
votes
0 answers

Trade reverse 3 commas error - Pinescript

I came here for a little bit of help regarding a situation I cannot figure out for a trend reverse order. Overall the strategy is based on a PSAR and as a second exit rule, the bot should be closing the current position while opening a new one if…