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
1
vote
1 answer

How to start coding for pattern detection?

I am trying to write the code to find the following pattern anywhere in the chart. It is very hard for me to understand how to do it or how to start or how to think about coding it. As an example, I want to detect the following pattern, where there…
sey eeet
  • 229
  • 2
  • 8
1
vote
0 answers

"If can not return String when Series is used inside it" Pinescript v2 error

I have been trying to write some code, and I came up with this so far, but I am not being able to figure out the error that it keeps outputting. "'if' can not return String when Series is used inside it" I tried to correct the If statements but it…
1
vote
2 answers

How to remove the error from Pinescript code

I need some help. TIME FRAME = 5 mins. I want an indicator to plot the open and high till the first opposite color candle. Basically: First candle positive and second candle negative, then plot high and low for the first 10 mins (price range of…
1
vote
1 answer

How to store values into an Array while ignoring nan values

Im trying to identify highest high candles and save the difference between the open and close for the last 10 occurrences of these candles into an array, and then get the average of the array. However, I'm having some problems since nan values are…
user2334436
  • 949
  • 5
  • 13
  • 34
1
vote
1 answer

Stop Loss take profit not working, exit signals not working

My exit signals are not working. Entries are made if a long signal is above the 200 ema and the other way around for shorts. BUT exits are still given if a long signal is below the 200 ema and the other way around for shorts. I keep getting the…
Gittiwilo
  • 11
  • 2
1
vote
1 answer

Pinescript - Compilation error. Line 22: Value with NA type cannot be assigned to a variable that was defined without type keyword

//@version=4 study("Hesitation EMA", overlay=true) // Inputs length = input(14, minval=1, title="Length") hesitation = input(0.5, minval=0, maxval=1, title="Hesitation") // Exponential Moving Average (EMA) with hesitation smoothing hesitation_ema…
1
vote
0 answers

Is there any way to lock custom volume profile to right side of chart?

Is there any anything I can do in pine script to lock volume profile to right or left side like built-in one, so it won0t move with scrolling or scaling? Something like like this https://www.tradingview.com/x/vsSBmGRz/ if barstate.isfirst …
helanom
  • 11
  • 2
1
vote
1 answer

In Pinescript I want to show the highest price level every 50 bars

In Pinescript I want to show the highest price level every 50 bars, but no matter what I do I can only show the current high. //@version=5 indicator(title='Deneme', shorttitle='Deneme', overlay=true, timeframe='') barLength =…
aakcay
  • 15
  • 4
1
vote
1 answer

How to replace the line with the label in pine script version 5

I am trying to create an indicator in tradingview that plot the high of the day and low of the day. The below mentioned pine code is working and indicator is plotting the line expected. //@version=5 indicator(title="HOD-LOD", shorttitle="Current Day…
Iamlearner
  • 13
  • 3
1
vote
2 answers

pinescript strategy.exit() function sometimes not executed when Take Profit (limit) target is reached?

I'm creating a strategy with the following code, and whilst manually verifying the orders I have encountered a couple of instances where the strategy.exit() function is not executed when the Take Profit (limit) target is reached, despite there being…
Philayyy
  • 1,767
  • 4
  • 16
  • 22
1
vote
1 answer

I need Help plotting the HH Bar and LL Bar on a Tradingview chart

I am trying to create an indicator to plot swing points on the chart. Basically after 3 bullish bars and 3 bearish bars I want the indicator to look back to the last 6 bars and plot a point figure on the highest bar to illustrate the Swing High and…
The Ronin
  • 11
  • 2
1
vote
1 answer

Declaring and using variables in same line (Pine Script)

Can you explain line 11 and 12? In these lines, the author is declaring TrendUp and TrendDown variables and instantly using it? On that basis what is the initial value of these variables? Please expain whole lines 11 and 12 (below)…
S3emingly
  • 15
  • 5
1
vote
0 answers

unable to dynamically sort array

I am trying a fib level based trailing stop and trailing target strategy.i want the strategy to check and recalculate the trailing stop and target after close of each candle. for long trades the fibonachi retracement levels above will be target and…
1
vote
1 answer

BUY&SELL both are happening at the same time though the signal either BUY or SELL

Context: I'm backtesting the below strategy. What I observed is, when ever the BUY or SELL signal alert triggers, instead of executing the corresponding order, it executing both SELL&BUY orders. It doesn't matter which signal is triggered. But if…
Ravi Kiran
  • 11
  • 1
1
vote
1 answer

Why does =: operator affect previous lines?

I'm trying to understand a script in pine script. I can't find the reason for the different outputs for similar codes. First code: //@version=4 study("CE", overlay=true) length = input(title="ATR Period", type=input.integer, defval=22) mult =…
denizt
  • 13
  • 2
1 2
3
44 45