All Questions
Tagged with pine-script if-statement
49 questions
0
votes
2
answers
116
views
Turn off indicator with if else statement in Pine script
I added 4 indicators in a pine script and changed a bit based on my requirements but I want an option to turn one or more indicator off via indicator settings. So I created if statement with curly ...
0
votes
0
answers
53
views
Why is the last 'if' statement in Pinescript not executing?
I don't understand why the last 'if' statement is not getting executed (Pinescript V5). Can someone pls help?
//@version=5
indicator("Test", overlay = true)
if false
if false
...
0
votes
1
answer
170
views
How can I have a conditional statement remain true for an x amount of candles?
I am attempting to write a script with two indicators. The problem is, they never both ping true on the same candle (Usually one or two candles apart). So my goal is to have both parts of the ...
-1
votes
1
answer
67
views
TradingView's 'end of line without continuation' error with Pine Script
Iam using this code in Pine Script but getting the "mismatched input 'if' expecting 'end of line without line continuation'" error.
How to fix that error with this function code?
//@version=...
0
votes
1
answer
378
views
getting syntax error when checking boolean value with 'If' statement
I'm trying to detect 3 specific EMA crosses, assign them to boolean variable, plot them and set alerts when their conditions are true.
I have no problem detecting and plotting the 3 crosses when they ...
0
votes
1
answer
75
views
Pinescript - Syntax error at input 'long_entry'
I have an issue with prinescript. I don't get how to fix this, line 23. When I use an if statementwhen, I use the ?: I don't get the error.
//@version=5
indicator("Test 1", overlay = true)
/...
1
vote
2
answers
439
views
Boolean input to negate if statements in pinescript
In short I have an indicator that has multiple requirements for setting background colors and bar colors. All of this was fine until I wanted to add a small wrinkle to it.
Basically I have two lines (...
0
votes
1
answer
49
views
Strategy Condition (2nd bar close above/below condition)
I am literally brand new to pine script and have stumbled my way to this point but I really am stumped. Thanks in advance for any direction.
I am trying to create a simple strategy around EMA/SMA. I ...
1
vote
1
answer
53
views
How to open trade after 3 candles since last trade was closed?
I am having trouble with my strategy. It opens and closes trades in the same exact time sometimes. I need the strategy to wait 3 candles before it can close trade, then wait another 3 candles before ...
0
votes
2
answers
299
views
Pinescript - Syntax error at input 'else'
I am having an issue with pinescript. Never used it before and havent coded in years so im very rusty.
I would love an opinion of why I am getting the error on line 21, which is the only 'else if' ...
0
votes
1
answer
390
views
Pinescript IF Statement Array
Hi i am struggling to get my array in Pinescript to produce anything other than a list of Nan. I am trying to create an array of the % difference of the low and 20sma when price bounces off the 20sma ...
0
votes
1
answer
36
views
I would like to specify a date in the condition of the function "if", how can I do that?
I would like to specify a date in the condition of the function "if", how can I do that?
For example, is it possible to set a condition such as "if the closing price rises by 10% within ...
0
votes
1
answer
783
views
Assigned a value to a variable in IF condition which never changes
I am using a variable in the Tradingview pine script whose value change after an IF statement is true.
var x = 0
if ltp > 100 // ltp = Last Trade Price
x := 1
If ltp goes above 100 then the ...
0
votes
1
answer
58
views
Why does this conditional statement return with the undeclared identifier error for ColorA?
This is an extract from the code that is specifically causing me problems. Please bear in mind that this for Pinescript.
The aim is for both of the moving averages that I'm coding to be green when ...
0
votes
1
answer
982
views
variable being shadowed in trading view pinescript, saying use := instead
I am new to pinescript and have coded a simple indicator in trading view pinescript. I can get my buy and sell labels and also send alert when conditions are met.
I am trying to store the entry price ...
0
votes
1
answer
132
views
Pinescript elif function
I tried creating an elif statement in Pinescript but it came out as error. Can anyone please help?
trend_1 = sma(close, 60)
trend_2 = sma(close, 30)
trend_3 = sma(close, 15)
if bar_index >= 252
...
0
votes
1
answer
700
views
Pine Script version 5 Condition 1 applies and if condition 2 applies check if condition 1 is still in places and enter Long or Short
Let's say I have condition 1 which is met several times, how can I check if condition 1 is still met when condition 2 is also met and then to perform a entry Long Position or Short Position. As an ...
0
votes
1
answer
518
views
If/else-like behaviour
I'm actually having a huge problem debugging one of a script i'm programming on tradingview.
To make it simple, on the image below you'll find that at line 54, i'm calculating the value of "a&...
0
votes
2
answers
493
views
Pine Script How To IF-THEN-AND
I have a statement (if x then do y). How can I add a second action (if x then do y AND z)?
count = 0
if (x)
do y AND count += 1
Also, would you specify the type for count, and what is pine script'...
0
votes
1
answer
48
views
Insert a counter variable inside a IFF statement doesn't work
I'm trying to code a script where a counter increment of 1 every time one condition is false, otherwise it's equal to 0.
The condition is a boolean output of the function CROSS().
I've tried:
1° ...
0
votes
1
answer
1k
views
Pine Script - if / else if statement
I get the error : line 56: Mismatched input 'if' expecting 'end of line without line continuation'. on my code BUT when I delete some line of code under it the error disappear and the code compile.
...
0
votes
1
answer
631
views
Pinescript - Simple if else
I am currently trying to get back into coding (its been some time) and for some reason I cant get my pinescipt to execute properly.
The intent is that
Condition for strategy execution is met, on the ...
0
votes
1
answer
109
views
PineScript formulation of condition?
Say I have 3 conditions, and I want to perform some action if 2 of these conditions are fulfilled. With a few number of combinations, like 3, the solution could be something like:
c1=...
c2=...
c3=...
...
0
votes
1
answer
77
views
Can Pinescript do this?
thanks for any help. I'm new to coding. I was wondering if this is something Pinescript can achieve? The code below is not meant to be accurate at all. I'm including it to hopefully give you an idea ...
0
votes
1
answer
891
views
Pine Script Multiple Conditions to Change Bar Colors
I have 10 condition like buy1 buy2 buy3 etc
I want to change bar color due to number of true conditions
3 condition is true bar color is red, 5 condition is true bar color is blue, 9 condition is true ...
3
votes
1
answer
7k
views
Pine script condition 1 and condition 2 fulfilled at up to n steps back
Say I have condition 1 and condition 2. If condition 1 and condition 2 was met within up to, say, 5 bars, then I want to perform some action. As an example let's say condition 1 was met at current ...
0
votes
1
answer
3k
views
Pine Script Multiple Condition / if statement or for-loop
I have multiple conditions like;
Buy1
Buy2
Buy3
Buy4
Buy5
.
.
.
Buy10
I want to change bar colors due to TRUE condition numbers
Example: only buy1 true
If 1 Condition True barcolor(color.red)
Example: ...
0
votes
2
answers
526
views
Pine script conditions / conditional-statements
I have 6 conditions:
c1 = ...
c2 = ...
Then if 4 of them are fullfilled (yielding 15 combinations), I will execute some command. How to do this?
E.g.:
cb1 = c1 and c2 and c3 and c4
cb2 = c1 and c2 ...
0
votes
1
answer
1k
views
Pinescript. Plotting conditional statement
If the variable barup is true, I want it to plot one series; if the variable bardown is true, I want it to plot another series value.
My current code yields the error: Cannot use "plot in local ...
0
votes
1
answer
333
views
Pine script: Switch trendline based on if statement
How do I set my trendline color and plot based on an if statement i.e. if stock data is > 1 year then use trendline 1 else use trendline method 2:
trend_1 = sma(close, 15)
trend_2 = sma(close, 30)
...
0
votes
1
answer
653
views
Can't declare a global variable inside IF statement (Pine Script)
I am new to Pine Script and have some problem declaring a variable inside an if and use it inside another if...
In the first if statement, I tried to get the "close price" of the long signal ...
0
votes
1
answer
13k
views
Pine script if else if
I'm new to Pine and can't get the following if else if to work on an choices input
// Backtest
entrySource = input(title="Enter On", defval = "Buy Big Green", options=["Buy ...
0
votes
1
answer
47
views
Need some help writing a strategy with different positions depending on three 3 signal variables
Hi I'm brand new in coding, and I am getting stuck every new line of code I try to write but hey its a learning process.
I'm doing a strategy based on the MACD variables.
-MACD_Line is either positive ...
1
vote
2
answers
1k
views
Tickerid function to identify the ticker
I cannot find a way in which the command tickerid works for me..
I want to make an IF statment where
If (the current ticker i'm on = a specific ticker i've put)
then (execute a formula)
else
(do ...
0
votes
1
answer
65
views
price movement of 2 candles in raport with ATR
I get this error on my code
Mismatched input 'alert' expecting 'end of line without line continuation'.
I want to make an alert when the price from 2 candles moves more than 1 ATR
my_atr = at(14)
if ...
0
votes
1
answer
575
views
How do I create a condition with my script using the if statement?
I'm faced with a little challenge with the if statements. I want the codes (plotchar) below to be plotted only if the code (plotshape) is false. If the code (plotshape) is true, then code (plotchar) ...
0
votes
2
answers
2k
views
if Syntax in pine script
I'm new to pinescript and I can't figure out what's wrong with my if syntax. Please help
//@version=4
strategy(title="Weighted Moving ATR", shorttitle="WMATR Stra Test", overlay = ...
0
votes
1
answer
2k
views
Pine Script issue with global variable and if condition
When I run this code I get consecutive times the function strategy.close(qty_percent=50, comment="TP-Pertial) though the i is 1 and not 0.
Infact, when I plot i I get 1 as you can see from the ...
0
votes
1
answer
3k
views
If statement and value of an input variable - Pine Script - Tradingview
I'm having issue with using the value of a variable used as input value, in a if statement Here's a piece of my code :
//@version=3
study(title="v5.0", shorttitle="v5.0", overlay=...
0
votes
1
answer
794
views
Pine Script - If statement with a plot
I am new to Pine Script but hoping to get some assistance with two if statements and based on the outcome I need to plot a flat line for the week (Monday to Friday), the following week the Marker (see ...
0
votes
1
answer
354
views
Pine Script conditional statement syntax
I struggle to code an if statement in Pine.
The idea is that the stop-loss is tightened when a waring signal is triggered.
This tighter stop should replace the regular stop-loss and trailing-stop. I ...
0
votes
1
answer
341
views
PineScript RSI Conditional Statement not working
I am trying to change long and short conditions based on RSI values but the below code is not working and the values are not initializing. The error says enterLong not found.
Code:
rs1=rsi(close,14) &...
0
votes
1
answer
6k
views
TradingView Pine-Script: Plot a line only if a input is true
I want to plot some EMAs only if a input is true.. however when i use the if functions, it says "Cannot use 'plot' in local scope."
//@version=4
study(title = "Todos os indicadores", overlay = ...
0
votes
1
answer
317
views
Nested if statement in pine script
I'm trying to build a ema script in trading view but struggling with how to finish up the code. I'm essentially trying to code this, but not sure how to nest this in an if statement:
(tl <= em1 ...
-1
votes
1
answer
289
views
Pine script trade, can't get If else statement working
I have a drop-down choice that works ok, and can't figure out how to get If else
statement to work. Did try If for all of them, then if else and nothing is working. else (typ4 == rma) << is not ...
0
votes
1
answer
161
views
Pine Script for Trading View: How to display on certain time frames
Could you kindly teach me how to not show the vertical line for timeframe of more than or equal to 1 Hour?
I desire to show the vertical lines (when the market opens) .
There is a difficulty using ...
0
votes
3
answers
4k
views
Switch on the fill between plots only if a condition is met
Ok. So I'm trying to make a switch for the fill in between the plots.
So that way, the fill doesn't always show up but only when I want it, and only between the plots I want, not all the ones that are ...
0
votes
1
answer
630
views
ternary operator ?: is throwing errors about wrong arguments
I'm trying to display a different time frame macd on a given time frame chart. so display 5 min macd on 1 min chart etc.
I've decided to accomplish that by multiplying a number 5 to the interval ...
0
votes
1
answer
990
views
Convert block of code PineScript to thinkscript
I want to convert this line of code from pinescript to thinkscript ( Thinkorswim )
How can I write this? I'm having problems with multiple if statements
isAboveEma01 = line_01 > line_01[1] and ...