Questions tagged [pine-script-v4]

Pine Script is a scripting language designed by TradingView. It allows users to create custom indicators and run them on their servers.

Pine is a lightweight language focused on the specific task of developing indicators and strategies. Most of TradingView’s built-in indicators have been coded in Pine.

See documentation of Pine Script v4

665 questions
2
votes
0 answers

strategy with default_qty_type=strategy.percent_of_equity and default_qty_value=200 output same result as without leverage

While backtesting a pine strategy on tradingview I noticed that the docs allow to and use couple of options to set a leverage (just like you have on exchanges while trading futures/contracts). Hence, as per the docs recommendations, I added the…
gastngouron
  • 461
  • 1
  • 5
  • 15
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
2 answers

pinescript get index of pivothigh

I would like to get the bar index of the last occurrence of pivothigh so I can use it to plot an indicator starting from that index. Not familiar with pinescript and the references are limited
T Nam
  • 25
  • 1
  • 4
1
vote
1 answer

ta.supertrend is not recognised as a function, importing trading view is not possible

import TradingView/ta/5 s21 = supertrend(21,1) s14 = supertrend(14,2) s7 = supertrend(17,3) long = color(s21)=color(s14)=color(s7)=color.green short = color(s21)=color(s14)=color(s7)=color.red start = timestamp(IST,2020,1,1,0,0,0) end =…
1
vote
1 answer

Pinescript - Query whether a line is present

Is there a way to query the existence of a line.new? I have an indicator where I want to query whether a line has been drawn and if so what color the line has. Unfortunately I only found the query line.get_price in the documentation. The question is…
1
vote
1 answer

why are these dates and times adding vertical lines in the future on tradingview?

i am trying to a add these dates and times on to a Tradingview chart - it appears that they are on the chart but not at correct times and dates, they are after May 24th, which is the future! Any ideas or fixes would be very…
1
vote
1 answer

Draw Horizontal Line with Pine Script and Set Text to always stick to right

//@version=5 indicator("Horizontal Line with Text", overlay=true) var label label1 = na value = 42800 hline(value, title="HR Line", color=color.blue, linestyle = hline.style_solid, linewidth = 2) if(barstate.islast) label1:=…
1
vote
1 answer

Change A Pine Script Timeframe?

The following popular Rsi Divergence script (credit to Shaziru) will plot rsi divergence for the current timeframe it is deployed on. Is it possible using request.security() to convert src_fast/slow inputs to a specific timeframe, say 1D? I'm fairly…
metokitt
  • 53
  • 7
1
vote
0 answers

Normalize multiple Tradingview 0cross indicators to keep within the same range and still cross 0 when they should?

I'm combining three 0cross indicators in Tradingview however they scale differently so to solve the problem I applied the Normalize function after some research. I then noticed that though the scaling was now within the range, they no longer crossed…
vulcan4d
  • 11
  • 2
1
vote
1 answer

Use indicator if true

I am trying to write a strategy "to test which indicator is better" So I ask in the inputs if to use an indicator or not to enter a trade. For example, stochastics. If user selects stochastics to enter the strategy, then Tradingview will have to…
1
vote
1 answer

Send Pine Webhookdata To PHP

I'm trying to send a tradingview webhook to my php server as follows: condition_alert = (crossunder(rsi, rsi2) and crossunder(rsi, rsi2) and rsiColor1[1] == #0ebb23 and rsiDowntrend) if (condition_alert) alert("condition_alert",…
metokitt
  • 53
  • 7
1
vote
1 answer

How do you add alert to OBV-MACD indicator when direction changes

Hello im trying to add and alert to OBV-MACD indicator on pinescript when direction changes but i dont know how. I know probably simple but im new to pinescript so i dont know where to start I think it has to go somewhere here, where the plots…
1
vote
3 answers

Alert in pinescript

i want to add alert while buy / sell signal generated. Below is my pinescript. //@version=5 indicator(title='TEST08032023', overlay=true) s9ema = ta.ema(close, 9) s18ema = ta.ema(close, 18) longCond = ta.crossover(s9ema, s18ema) shortCond =…
1
vote
0 answers

How to have multiple exits with different quantities in pinescript?

I'm writing a strategy that goes long 2 futures contracts at a time. I'm having an issue exiting positions. Sometimes the script sends two 1 lot sells at the same time instead of sending a single alert for both contracts if the stop loss is…
progains
  • 31
  • 1
1
vote
0 answers

How to add Pine Script to TradingView Widget?

I'm using this (https://www.tradingview.com/widget/advanced-chart/) widget at this moment. And trying to add my own created PineScript on Graph but have failed so far? Do you know any method to achieve desired outcome? I'm using NextJS but your…
1
2
3
44 45