Questions tagged [pine-script-v5]

This tag should be used for questions relating to scripts and code built specifically on version 5 of Trading View's Pine Script language.

2372 questions
1
vote
2 answers

Pine Script V5 how to consider the spread and commission in backtesting?

I have my own Pine script strategy V5 and it's profitable on almost all forex pairs and XAU pairs as well. However, it's somehow inflated because it ignores that fact of spread and comission. How can I consider these factors in the backtesting on…
1
vote
1 answer

How do I reset a variable when a condition is met?

Whenever there is a breakout candle I want to store the low of the bar as the stop. Then whenever price reach below the value, I want it to create an arrow and reset the array, until condition is met again (IE when stopped out it should not show…
document
  • 13
  • 3
1
vote
2 answers

How can I get double signal from same variable?

I am setting up a Strategy to use with Wundertrading. As these signal providers work, I need to send a duplicate signal to close any previous open position and then open a position in the opposite direction. With the current code, I have managed to…
1
vote
1 answer

Preset parameters for multi timeframe indicator

I have a multitiframe indicator it is a TMO with 3 plots (each for a different timeframe). I want to be able to preset the Timeframes accroding to the current chart, for example: If we are in the 5m chart : 1st plot current chart, 2nd plot at 15m…
1
vote
0 answers

Issue with the lookback for the last Bull or Bear Candle

I am trying to create a simple bit of code where you can lookback a certain amount of candles and find the last Bull or Bear candle but I seem to have completely missed something as when I add to the chart I am getting a Negative Index Study Error…
Phil FX
  • 11
  • 3
1
vote
1 answer

How do I keep Alerts to fire when trade in opposite direction?

I have a strategy that connects to the broker with alerts (3commas style), but I am able to trade in both directions. The problem is that alerts keep firing when the close_long condition is met while still in a short position, how do I let the…
1
vote
1 answer

Pine Script, function with a switch not recognizing the switch condition

In Pinescript I have created arrays that contain lines, labels, and boxes. To clear the data from the arrays I created a small function where the first argument dictates what kind of array it is going to clear. The 2 errors that I get states that I…
Xalladus
  • 13
  • 2
1
vote
2 answers

How to view the contents of this array in TradingView?

I have a pinescript array declared like this; var array_contents = array.new_float(2) Assume that the contents of this array have been assigned. How can I view the contents of each element in the array in pinescript? I am open to any method…
user3848207
  • 3,737
  • 17
  • 59
  • 104
1
vote
2 answers

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 (plots), one of which I call the signal line and…
1
vote
1 answer

why doesn't pine script work...IF statement doesn't go to ELSE statement

I have tried many other alternatives and it never goes to the ELSE statement to then play the next IF statement it the," id str.contains(orderIds, '1') == false and array.get(openOrder1, 1) == 0 " that doesn't go to the next else statement... and if…
MENTORJJ
  • 25
  • 5
1
vote
0 answers

How max_drawdown and max_runup are calculated when multiple exits (take profit) is used

I don't understand how strategy.max_drawdown and strategy.max_runup are calculated on TradingView Pine Script. My problem is the documented calculation just not correct if there are multiple exit points. I know what is max drawdown and runup, but…
Adam Wallner
  • 2,292
  • 23
  • 20
1
vote
1 answer

Is there an alternative way to add up multiple closes in Pine v5?

Basically creating a custom indicator and need the previous indicator value added up. I’m currently using the following code: exampleName = exCloseVal + exCloseVal[1] + exCloseVal[2] + exCloseVal[3] + exCloseVal[4] + exCloseVal[5] Now let’s say I…
Lew2234
  • 21
  • 4
1
vote
1 answer

strategy.position_avg_price returns "NaN" on alert when triggered in Pinescript

My code on trading view pine script is returning me "NaN" for strategy.position_avg_price when alert is triggered. It works when I back test it. However when I test it live, it is giving me "NaN" value. Alert message with "NaN" message I am trying…
Marcus
  • 11
  • 2
1
vote
1 answer

Compilation error. Line 10: Extraneous input ':' expecting 'end of line without line continuation'

I keep getting compilation errors, I am new to pinescript and cant figure out where I am going wrong. //@version=5 // Define the RSI period period = 14 // Calculate the RSI rsi = rsi(close, period) // Check for bullish divergence if (rsi < 30)…
1
vote
1 answer

Writing a Pinescript code for Auto trading with the MACD but get this error

This is my code that I've written but when I run it I get this error: Compilation error. Line 24: Could not find function or function reference 'crossover' // © KabeerMehdi //@version=5 //MACD auto-trading strategy strategy("MACD",…