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

Is there any formula for automatic "price to bar ratio" calculation?

I am writing a script that calculates the angle of the trend and for the calculations to coincide with my chart, I use the same "Lock price to bar ratio" setting for the chart and the script. The problem is that each asset has a different price and…
3
votes
2 answers

Open a Market order with PineScript

I have the below script to send a market order and I am logged into my broker in tradingview but when I attach the script to the chart I do not see any positions opened in my broker. Any help is appreciated. strategy(title="Positions",…
Raj
  • 31
  • 1
  • 2
3
votes
2 answers

how to normalize values in pinescript

I'm trying to merge a couple of indicators together, the problem is some of these have different scales, so while an oscillator might range from 0 to 100 another might have a variable range which can sometimes be very small say from -5 to +5. of…
Jimmy
  • 33
  • 1
  • 7
3
votes
1 answer

Pine Script (TradingView) - How to move a Stop Loss to the Take Profit level

There is a Pine Script code on TradingView where we have 2 Take Profit levels and 2 Stop Loss levels: tradingview.com. When the first take profit is achieved, half of the position is closed and the first stop loss is moved to the entry level…
Nikita Doronin
  • 33
  • 1
  • 1
  • 5
3
votes
2 answers

Only exit trade after N number of bars (only working sometimes?)

I am modifying a strategy to only exit the trade after a set number of candles. I put in an input for timeframe (in inputs section of script) and set the exit rule at the bottom (barssince) - it is working a lot of the time, but some trades are…
Drewdavid
  • 3,071
  • 7
  • 29
  • 53
3
votes
1 answer

Pinescript strategy.entry long/short seem delayed by an additional 2 candles

When I enter a strategy.entry position, when I look at the graph that shows the color change for a condition, the actual buy order does not execute until the third candle of the color and vice versa when selling, i.e., it is the third red candle…
Yoyofanusa
  • 31
  • 1
  • 2
3
votes
1 answer

Pine Script: How to display current time in chart's timezone on label, at every price update?

I am attempting to do something seemingly trivial, but running into all sorts of problems. I would like to plot certain basic information on a label every time there is an update to the current price--regardless of the timeframe of my chart. I am…
ZwiTrader
  • 195
  • 1
  • 2
  • 12
3
votes
3 answers

How to get bar index on specific date

I am new to pine script. I want to compare the prices on 2 specific date. But how would I get the bar_index on a particular date? Thanks in advance
Max Cheung
  • 176
  • 3
  • 13
3
votes
1 answer

Percentage Take Profit and Trailing Stop Loss TradingView strategy issue

This is a simple strategy based on EMA cross. The issue comes when trying to exit a % at a certain level and letting the remaining position to be filled by the trailing stop. Let's set a target of 3%. When the price hits the target the strategy…
dgtomu
  • 31
  • 1
  • 2
3
votes
1 answer

Cannot call 'plot' with arguments (series[float],

First mistake is I took some Version 3 code and pasted it into V4 and have got most of the conversion right but I know have error and I just can't figure out when I try to plot the series, getting the following error for each one: line 189: Cannot…
tradeire
  • 31
  • 1
  • 1
  • 2
3
votes
3 answers

Pine-script optimization

In AmiBroker there is optimize option. It allows you to fine tune values for indicators or even any other parameters. Is there anything like that in pine script? couldn't find it easily using google.
Pravin
  • 35
  • 4
3
votes
2 answers

Percentage Change function in pine-script

Is there a function in pine like pct_change() in python, which can calculate percentage change in pine? Since there is not data management system
Slartibartfast
  • 1,058
  • 4
  • 26
  • 60
3
votes
0 answers

pine script : can't use variable as defval of input?

I want to use different default value to start base on different ticker my code: bars1=iff(myticker=='HSI1!',313,iff(myticker=='YM1!',460,999)) lower_tf = input(bars1, title='Lower Timeframe to Assess') it gives error: Syntax error: Arguments of…
Farseer
  • 31
  • 3
3
votes
1 answer

How to conditionally delete line in Pine Script

I am attempting to create a TradingView study that draws a line from a crossunder on the current bar to a crossunder on a previous bar, where the previous bar is less than a set maximum number of bars back. I only want to draw lines with negative…
ughpines
  • 68
  • 1
  • 5
3
votes
1 answer

How to plot only for today?

I'm trying to create a new study in tradingview using Pine Script. isCurrentMonth = month(timenow) == month(time) plot(isCurrentMonth ? close : na) This piece of code could help me display for current month, but I want to display only for current…
Pugazh
  • 9,453
  • 5
  • 33
  • 54