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.
4,299
questions
0
votes
0
answers
3
views
Can I use private indicator's signals in Strategy Tester on Tradinview?
I have a private indicator that gives me buy/sell signals. Is it possible to use the indicator's buy/sell signals as points of trade entry with Pinescript to create a Strategy Tester?
I was looking at ...
0
votes
0
answers
6
views
PINESCRIPT - Ternary Operator not producing Expected Result
I created a function to find swing highs and lows. Then I created another function identifying the price of those swing highs and lows. Then...I created an elaborate ternary operator statement to ...
0
votes
0
answers
7
views
How do I check if all the 5 mins Candle Close is above VWAP since 9:15AM? Tradingview
Say, latest 5 mins candle closes below VWAP then I wanted to check if all the 5mins candle before latest candle since 9:15 closed above VWAP in pine script. Trading view
0
votes
0
answers
11
views
Turning a "plotshape" HH/LL into a buy/sell signal
I know this is a simple question, but I am brand new to Pine Script or any kind of language (literally my 2nd day). I'm trying to turn a HH LL indicator into a buy/sell strategy so I can backtest data....
0
votes
1
answer
20
views
how to start a long position by adding a percentage lower condition with Pine Script
I'm trying to figure out how to start a long entry with a percentage lower. For instance, when ema 20 crossover ema 50, the long entry will trigger only 1% lower than the pricelevel once the crossover ...
0
votes
1
answer
9
views
UNABLE to add current alert price in tradingview pinescript
i am unable to find the relevant solution for the price condition image link
plotshape(longCondition, title="Buy Signal", text="BUY", textcolor=color.white, style=shape.labelup, ...
-1
votes
0
answers
17
views
Adjusted SMA indicator - Conversion from Pinescript to Python
could you pls help me convert this pinescript code to python. I want to use in dataframe.
len1 = 33
src1 = high
smma1 = 0.0
sma_1 = ta.sma(src1, len1)
smma1 := na(smma1[1]) ? sma_1 : (smma1[1] * (len1 ...
0
votes
1
answer
18
views
ta.valuewhen calculation only one time for condition true (pinescript/tradingview)
I'm trying to write a StopLoss and TakeProfit script based on the lowest. When the condition "buy" is true the script should take the previous lowest as a StopLoss. The problem is that the ...
0
votes
0
answers
17
views
I am trying to make a MACD strategy but i dont want 2 cosecutive macd values above or below -19 and 19
I am trying to make a MACD strategy but run into issue, I don't want 2 consecutive MACD values to count as a long signal or short signal.
1 In the image I have provided you can see that my script puts ...
0
votes
1
answer
17
views
Pine script signal when bar closes higher or lower than pivot point open
Hello,
I have coded a pivot point in pine script but now I want to add the S2-signal that indicates that:
1 a bar closes ABOVE the OPEN of the first pivot point bar (for an UPtrend) and
2 a bar closes ...
0
votes
0
answers
18
views
Tether depeg duration
Context
On May 12th, Tether ($USDT) significantly departed from it's peg of $1.
Indicator
I'd like to have an indicator which shows the number of continuous hours that Tether has been depegged.
We'll ...
-2
votes
0
answers
15
views
How can I see a stock that has made a 20% plus move in 5 days or more in a certain date period
I want to know when a stock has moved 20% or more in 5 days or less in a certain date period
0
votes
1
answer
26
views
Tradingview Syntax error at input ')'. Error , v5 version Problem
In the code below it gave the error "Syntax error at input ')'".
mtfatr = request.security(syminfo.tickerid, tf2, ta.tr(nATRPeriod))
pricetwo = request.security(syminfo.tickerid, tf2, close)
...
0
votes
1
answer
36
views
Get the price when exit/close strategy
It can use strategy.opentrades.entry_price(0) to get the price when strategy entry.
But how to get the price when strategy exit/close?
0
votes
2
answers
22
views
How to address a color transparency/opacity without touching the color itself? V5
For example I have these color variables:
Color1 = #334455FF
Color2 = #33445588
The only difference is the opacity/transparency component. Can we address this component only, without touching the RGB ...
0
votes
1
answer
20
views
How to create a new tab on Indicator Settings Panel and order inputs there? V5
I have too many inputs for my indicator I develop so some certain important inputs are harder to find. (E.g. experimental or debugging variables.) This makes the Settings Panel too high so it covers ...
0
votes
0
answers
15
views
Backtesting a simple HA momentum strategy on TradingView
I'm trying to backtest a simple heikin ashi movement strategy on tradingview using pinescript. So as per my knowledge, on uptrend the open price of heikin ashi candle always increases and on downtrend ...
-1
votes
0
answers
18
views
Pricing Questions for Pyramid Orders
There are a lot of blockages as I learn by self-taught without knowledge of coding.
It's not easy to find an answer on stackoverflow or kodify, so I'm asking again.
-Question-
I am trying to create a ...
0
votes
1
answer
21
views
How to plot horizontal lines on high and low of the 9.30 candle in 1minute char time frame
How to plot horizontal lines for high and low on the candle formed at 9.30 in 1 minute timeframe in pinescript.
0
votes
1
answer
12
views
I have set up an alertcondition on SPY, once triggered, how can it send me the price of another ticker like TSLA in PineScript?
I'm using TradingView to follow the trend of the SPY index. Once its RSI fall out of range, I have set up a alertcondition to trigger the system to send me a message.
However, I can only find it send ...
0
votes
1
answer
9
views
How to convert a V4 study code to V5 to add it to an indicator?
I have an indicator I built running on V5 pinescript and I want to add this one which is written in V4 pinescript:
//@version=4
study("Tweezer and Kangaroo Tail", overlay = true)
...
0
votes
1
answer
20
views
How to plot only current day open on chart at end as line for NQ cash session?
//@version=4
study("Open of first bar of a day")
// If start of the daily session changed, then it's first bar of the new session
isNewDay = time("D") != time("D")[1]
var ...
0
votes
2
answers
14
views
"line 168: Syntax error at input 'end of line without line continuation'."
I'm trying to create a crypto trading strategy in TradingView, and everything was going well until my script decided to upgrade to v5. Everything works, but when I add these two lines, I get the above ...
0
votes
1
answer
16
views
An argument of 'series string' type was used but a 'simple string' is expected when comparing close and vwap
When trying this code:
strategy.risk.allow_entry_in(close > ta.vwap(hlc3) ? strategy.direction.long : strategy.direction.short)
I get this error:
An argument of 'series string' type was used but ...
-1
votes
0
answers
15
views
converting pine script to mql4 ....This is indicator in Pine Script language. Can anyone help me to convert it into MQL4
This is a High/Low indicator in Pine Script language. Can anyone help me to convert it into MQL4. It should be very easy for some of you
https://www.tradingview.com/script/C3MlAWCw-SSL-Hybrid/
0
votes
1
answer
27
views
Get the bar_index of the first bar that has a lower low than the low of the current bar
To find divergences I'm trying to get the bar_index of the first bar that has a lower low than the low of the current bar.
I wish I could inject current bar values into the condition field of ta....
0
votes
1
answer
22
views
How to cancel orders if they are not triggered within 1 bar?
How do i prevent orders from remaining open and executing later.
For long entries i have a buystop = high, so if the next candle the price doesn't hit the high it'll remain open until x number of ...
0
votes
0
answers
19
views
I confuse convert Tradingview Strategy to study strategy.position_size and strategy.position_avg_price to study
I try to convert Strategty to study I don't know it right?
if Long
strategy.entry("L", strategy.long)
if Short
strategy.entry("S", strategy.short)
I convert to this
...
0
votes
1
answer
33
views
Convert pine script code to version 4 or 5
I would like to convert this script from version 2 to version 4 or 5 in order to create buy and sell alert messages. Can someone help me with this or explain it to me?
In the code below you find the ...
0
votes
0
answers
16
views
Alert function for order blocks
I recently started trying to code in Pine on my own and built my own OB indicator with help from some other indicators. I know want to add an alert, that is triggered when Price comes back to an ...
0
votes
1
answer
29
views
Create MACD band on Tradingview
My idea is to make the MACD histogram oscillating in a range from 0-100 just like the RSI.
I did it successfully, but compared to normal MACD histogram it is too low and hard to see because most ...
0
votes
0
answers
16
views
My strategy.cancel does not close my trades, when criteria is met. Why?
I'm trying to hunt down a bug. My strategy wouldn't close, even if the closing criteria is met. I checked multiple point manually, using the Data Window which confirms that the exit trigger is sent ...
1
vote
0
answers
37
views
How to implement a Super trend crossover
I am new to pine script. I am trying to create strategy with below condition.
if current price is greater than supertrend(5,1) and current price is greater than 20 EMA then "BUY"
if current ...
-3
votes
0
answers
27
views
How to to set time period [closed]
I want to code in pine editor , how I can set particular time only draw the horizontal lines on chart
I need only 02:30 am to 12:30 high & low horizontal line
enter image description here
0
votes
1
answer
21
views
How to add check box for Daily zone
Below is my Code.. how to add input check box for this Daily zone. When i enable this zone should be visible. I tried added last 4 four line to achieve but it throws an error if I enable the last f4 ...
0
votes
2
answers
30
views
Variable not becoming a series of values. Why?
I created this script to detect Swing Highs and Lows and then to determine the High and Low values of these Swings. The code works for the last bar, but I would like these values to be a series I ...
0
votes
0
answers
25
views
Comparing current and previous bars in indicator
I'm trying to modify an open source indicator to set a flag whenever the indicator turns "up/blue" or "down/red" from the neutral/grey state.
Here's a screenshot to illustrate ...
0
votes
1
answer
20
views
How to prevent a plot from the past repainting?
Is there a way to prevent a plot that has already appeared from erasing itself shortly after? I'm using pinescript on TradingView and an indicator sometimes does this. I'm aware it is due to security()...
1
vote
1
answer
22
views
hline() returns with error message in a case. How to fix it?
The following code draws a horizontal line properly at $1234:
hline(1234, title="title", color=#ff0000, linestyle = hline.style_dotted, linewidth=1)
But if I put a price there (don't ...
-1
votes
0
answers
22
views
study error array is too large maximum size is 100000
My indicator combines with 10 indicators but sometimes doesn't work within some time frame. for example, 4H or 30min works but 1H or 15min doesn't work and gets an error.
"study error, array is ...
0
votes
1
answer
12
views
Code for checking the type of last crossover
I want my code to check if the last happened event is either Pitop or Pibottom then give out a signal either called bullish or bearish depending on the last event happened.
Pitop = crossover(MA111,...
0
votes
0
answers
22
views
How to use most recent pivot high/low in strategy?
I am trying to become more familiar with pinescript and am trying to run a strategy with a risk reward ratio that uses most recent pivot high/low (Longs/Shorts) for the SL. The strategy will run but I ...
0
votes
2
answers
35
views
How to automatically change input.timeframe('D') to a period greater than the user's chart. PineScript V5
I'm newbie. I have a Pine script code.
Problem with function:
input.timeframe('D')
I need the script to call an asset formula time higher than the one used in real time.
I use a function:
request....
0
votes
1
answer
24
views
How to skip an Event if recently occurred not too long ago?
The not-working code:
Event = Something and SomethingElse and (ta.barssince(Event) > 20)
Of course, it won't work because at first time, the Event boolean variable is not declared yet.
Perhaps the ...
0
votes
0
answers
27
views
Condition is true if 15 seconds have passed
i am new to pinescript but i am facing an huge problem when i try to work with time.
The problem is:
I have an indicator that shows buy (or sell) on the current candlestick but sometimes it disappear. ...
0
votes
1
answer
18
views
What does it mean when there is only one variable in a single line in PineScript?
When I read some PineScript code, I come across this:
pDir = 1
if array.size(zigzagpivots) >= 1
pDir := array.get(zigzagpivotdirs, 0)/
pDir := pDir % 2 == 0 ? pDir / 2 : ...
0
votes
0
answers
12
views
Keep getting warning about repainting on my tradingview strategy, having a hard time fixing it
I've tried all the solutions provided here:https://www.tradingview.com/pine-script-docs/en/v5/concepts/Repainting.html besides the "nonRepaintingsecurity()" one because it doesn't seem to ...
0
votes
1
answer
21
views
convert formula to pinescript for tradingview
(c/c1>=1.04 and v>v1 and v>=100000) is the formula that I am trying to convert to pinescript but couldn't where
latest close(price) is 4% more than the previous day price(rate of change ROC)
...
0
votes
0
answers
28
views
PineScript: pivot points arrows 5 bars left 5 bars right
Indicator setup to give arrows looking '5 bars left and 5 bars right' to show when the current bar has the lowest (or highest value) of a range.
The code below is almost perfect, except that it will ...
0
votes
1
answer
27
views
pine script : color the current candle different color
i wanna to color all candles , all down candles will be red ,, all up candle will be green and the current candle will be black (if not closed yet)
this is for example
//@version=4
study("color ...