Pinescript Discussion

Welcome to this discussion thread. Feel free to ask questions or discuss things related to this section.

@filip @ivan

If anyone just starting out is looking for some good pine script resources and code snipets, check out I am not affiliated with them, but when I was learning all this stuff on my own I found them to be a great resource.

Code snip on basic timestamp and other strategy inputs as demostrated by @filip

Nice overview of the Strategy Tester information available (look at Sharp Ratio as well)

Nice overview of how to simulate strategy in a study so you can set alerts (no backtest information available in a study). This is a pain with Tradingview as alerts are not available with Strategy (supposidly to be added in 2019) and Strategy Tester is not available with Study… so I found it was helpful to tune a strategy, then convert it to study and set alerts to forward test.

If anyone has any other pine related resource please do share… ;o)


Hi Filip,
Can you provide me the link in tradingview you mentioned in the video.
Kr. Roland

SOrry about that, I have included it in the lectures now.

here it is :

Hi @filip, first of all thank you for great course. I started from scratch and I learned a lot.
But I don`t understand one thing about the pine script.
Is the pine script only for developing startegies and backtesting, or can I use my pine script as a trading bot and execute it to live exchange? Is there any way?
Or is necessary to use javascript language to program trading bot?


1 Like

Thank you very much, I appreciate your feedback. You can use pinescript to trade as well, by using some of the trading partners tradingview has.

1 Like

Hi @filip,

Great course, thanks !

I’m not sure I get why the result varies with the initial capital. Which parameter causes this variation ?


The absolute result or the percentage result? Could either way depend on how large of a position you take.

The percentage result

Then it’s quite simple to explain the difference in the result. Since you have different initial capital the percentage result will differ. Let’s say your strategy makes $100 result. If you start with an initial capital of $1000, that’s a 10% return. But if you run the same strategy with $2000 initial capital, then the result is only 5%.

@filip the simple strategy that you built in pinscript - it automatically applies to the whole chart, meaning the day 1 btc was traded on coinbase? Is there a way to apply it for a spesific period? Should I use n variable?


I think I showed you this in the Backtesting Part 1 and 2. Take a look and let me know if you have questions :slight_smile:

Yeah you right, I just did not get to that part at that point. Thank you!

1 Like

Hi, I’m new with pinescript and would like to know if anyone would help me. How can it be the same for several pairs on one indicator like but should looks like that:

Here is the code for static screener using some strategy:

With this code change few options.

To be more specific

I want to create an indicator with 3 (or more) boxes. One box = 1 pair (like ETHUSDT, BTCUSDT, etc.) For example: #1 BOX - BTCUSDT #2 BOX - ETHUSDT #3 BOX - MATICUSDT If RSI 0 >= X, make BOX Green color IF RSI 30<= Y, make BOX Red color

*1. If RSI of the specific pair is less than 30 change color of the specific pair to GREEN *
2. If RSI of the specific pair is more than 70 change color of the specific pair to RED

You can check out the tickerid function to get data from other tickers and use those in the same script.

I’m trying to generate multiple alarms in trading view / pine script. it compiles but generate no alarms.
could you please help me ?

study(“Indicatore di Test”, shorttitle =" TEST", overlay=false)

//===== INPUTS ==========================================================================//
Factor = input(1,“supertrend factor”, type= input.float)
Pd = input(10,“supertrend period”, minval=1,maxval = 100)
atrPERC = input(50,title="% ATR for stop loss line") // **** Manual stop loss set

// ****** CALCOLO SUPERTREND ********************
Up = hl2-(Factoratr(Pd))
Dn = hl2+(Factor
TrendUp = 0.0
TrendUp := close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
TrendDown = 0.0
TrendDown := close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
Trend = 0.0
Trend := close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl = Trend==1? TrendUp: TrendDown
TslSTOPLOSS = Trend==1? (TrendUp-atrPERC/100atr(20)): (TrendDown+atrPERC/100atr(20) )// linea di stop loss
TslSTOP = Trend==1? TrendUp: TrendDown
linecolor = Trend == 1 ? :

plot(Tsl, color = linecolor , style = plot.style_line , linewidth = 1,title = “SuperTrend”)

SupertrendLong = false
SupertrendShort = false

if Trend == 1 and Trend[1] == -1
SupertrendLong = true
SupertrendShort = false

if Trend == -1 and Trend[1] == 1
SupertrendLong = false
SupertrendShort = true

// ***** GENERAZIONE ONE ALLARM FOR ALL **************

// ----------------------- azzeramento messaggio --------------------------------
trigger = false
messaggio = “---------------”

// ------------------------ assegnazione dati messaggio ------------------------------

// ------------- Long Reversal Trade ----------------------------
//if go_long == true
// trigger = true
// messaggio = " HA + CCI Long signal!!"

// ------------- Long Reversal Trade ----------------------------
//if go_short == true
// trigger = true
// messaggio = " HA + CCI Short signal!!"

// -------------Supertrend Long Trade ----------------------------
if SupertrendLong == true
trigger = true
messaggio = " Supertrend Long signal!!"

// -------------Supertrend Short Trade ----------------------------
if SupertrendShort == true
trigger = true
messaggio = " Supertrend Short signal!!"

// -------------Trend following Long Trade ----------------------------

//if TF_Long == 1
// trigger = true
// messaggio = " Trend Following Long signal!!"

    // -------------Trend following Short Trade ----------------------------

//if TF_Short == 1
// trigger = true
// messaggio = " Trend Following Short signal!!"

// ----------------------------- generazione messaggio allarme -------------------------------------
alertcondition(trigger, title=‘ONE Allarm’, message=messaggio)

When trying out the same example as you did in Building a Simple Strategy, on the strategy tester I only see “No data” message

strategy(“MAStrategy”, overlay=true)

m=sma(close, 10)
buy=close > m
sell=close < m

strategy.entry(“buy”, true, 0.015, when=buy)

strategy.close(“sell”, when=sell)

I can’t get this code to work. its almost identical to whats in the video . It compiles but no arrows plotting on chart:


buy = close > m
sell = close < m

strategy.entry(“buy”, true, 5, when = buy)
strategy.exit(“buy”, when=sell)

Any help would be appreciated @filip

I had the same problem @Filando , but it was returning a Add to Chart operation failed, reason: The script must have one study() or strategy() function call message to me.

It worked for me after I deleted all the code that appeared when I first opened pine editor, which looked like this:

study(“My Script”)

Seems that if the script is a trading strategy, it should not contain any study() function according to this resource

@Leo I fixed the issue. It seems the problem with the strategy.exit code. I switched it to strategy.close and resolve the problem. Just trying to see if I can build a money machine now lol.

1 Like