Blog

pine script
Pine Script TradingView

Pine Script New Feature: ‘Else If’ Statement

Pine Script : We’re happy to announce that TradingView added support for multiple conditions using the else if construct in our PiineScript language.

Previously, you could only write if/else statements if they were embedded within each other. For example:

//@version=4
//@Algonize

study("My Script")

v = if close > open

    close

else

    if open > close

        open

    else

        na

plot(v)

Now, however, after adding the else if construct, you can simply write it out like this:

//@version=4
//@Algonize

study("My Script")

v=if close > open

    close

else if open > close

    open

else

    na

plot(close)

Note that in order to use the else if construct, you must specify the fourth version of Piine in the first line of your code. To do this, simply add in the following:

//@version=4
//@Algonize

You can learn more about if and else if expressions in our Piine Script Tutorial and Pine Script Reference pages. We hope you find this update useful. As always, feel free to send in your comments, feedback, and suggestions — we love building for you.

Source : TradingView

Leave a Reply

Your email address will not be published. Required fields are marked *