Making Your First Indicator: Introduction to Pine Script Welcome back, traders! In today's video, we'll explore the powerful features of the Pine Script™ Editor, where we'll be working on our scripts. This editor offers a range of advantages that make our coding experience more efficient and enjoyable.
The Pine Script™ Editor is specially designed for writing Pine scripts, and it brings several benefits to the table. First, it highlights your code according to Pine Script™ syntax, making it easier to read and identify any errors. Additionally, it provides syntax reminders for built-in and library functions when you hover over them, helping you navigate the language effectively.
Furthermore, the Pine Script™ Editor offers quick access to the Pine Script™ v5 Reference Manual. Just Ctrl+Click (Cmd+Click on Mac) on a Pine Script™ keyword, and a handy popup with relevant information will appear. This allows you to explore the documentation without leaving the editor.
To speed up your coding process, the editor provides an auto-complete feature. Just press Ctrl+Space (Cmd+Space on Mac), and it will suggest code completions based on what you're typing, saving you time and reducing errors. These features combined make coding in Pine Script™ a breeze!
While not as feature-rich as some top editors out there, the Pine Script™ Editor still offers essential functionalities such as search and replace, multi-cursor support, and versioning. It's a reliable tool for writing and managing your Pine scripts effectively.
Now, let's dive into the practical aspect of using the Pine Script™ Editor. To open it, click on the "Pine Script™ Editor" tab at the bottom of your TradingView chart. This will bring up the editor's pane, ready for you to start coding.
For our demonstration, we'll create our first working Pine script, an implementation of the MACD indicator. Let's walk through the steps together:
Click on the "Open" dropdown menu at the top right of the editor.
Select "New blank indicator" to start from scratch.
Replace the existing code in the editor with the example script you see pasted here on my screen.
Click "Save" and give your script a name. It will be saved in your TradingView cloud account.
Finally, click "Add to Chart" in the editor's menu bar to see the MACD indicator in a separate pane below your chart.
Great job! Your first very own Pine script is running on your chart, and the MACD indicator is now displayed on your screen. Keep an eye on those blue and orange lines representing the MACD and signal values, respectively.
Now, let's level up our script by using built-in Pine Script™ functions. The second version of our script will showcase the ta.macd() function, specifically designed for calculating the MACD indicator.
To create the second version of our script, follow these steps:
Open the "New blank indicator" option from the "Open" dropdown menu.
Replace the existing code in the editor with the example script you see pasted here on my screen.
Save the script with a different name.
Click "Add to Chart" to see the updated "MACD #2" indicator in a separate pane.
Well done! In this version, we introduced inputs to allow us to change the lengths of the moving averages. By using the ta.macd() built-in function, we simplified the code and made it more readable.
With the second version of our script, we have improved our code and made it more flexible. Now, we can easily adjust the lengths of the moving averages, tailoring the indicator to our needs.
That's a wrap for this video, traders! We've explored the Pine Script™ Editor, created our first two versions of the MACD indicator, and learned valuable coding techniques. Stay tuned for the next episode, where we'll continue enhancing our indicators and strategies with Pine Script™. If you have any questions or ideas for future episodes, feel free to reach out to me. Until next time!
Pineeditor
Pine Editor Shortcuts Hotkeys (All Hidden Included)For Those who have not explored, Here is the list of All the shortcut keys available.
Very useful for Macros
'show settings menu' - "CONTROL - ," "command - ,
'go to next error' - "ALT - e" "F4"
'go to previous error' - "ALT - SHIFT - e" "SHIFT - F4"
'select all' - "CONTROL - a" "command - a"
'center selection' - "CONTROL - l"
'go to line' - "CONTROL - l" "command - l"
'fold' - "ALT - l |or| CONTROL - F1"
'unfold' - "ALT - SHIFT - l |or| CONTROL - SHIFT - F1"
'toggle fold widget' - "F2" "F2"
'toggle parent fold widget' - "ALT - F2" "ALT - F2"
'fold all' - "CONTROL - command - option-0"
'fold other' - "ALT - 0" "command - option-0"
'unfold all' - "ALT - SHIFT - 0" "command-option-SHIFT - 0"
'find next' - "CONTROL - k" "command - g"
'find previous' - "CONTROL - SHIFT - k" "command-SHIFT - g"
'selector find next' - "ALT - k" "CONTROL - g"
'selector find previous' - "ALT - SHIFT - k" "CONTROL - SHIFT - g"
'find' - "CONTROL - F" "command - f"
'overwrite' - "insert"
'select to start' - "CONTROL - SHIFT - home"
'go to start' - "CONTROL - home" "command - home |or| command-UP"
'select UP' - "SHIFT - UP" "SHIFT - UP |or| CONTROL - SHIFT - p"
'go lineup' - "UP" "UP |or| CONTROL - p"
'select to end' - "CONTROL - SHIFT - end"
'go to end' - "CONTROL - end" "command - end |or| command-DOWN"
'select DOWN' - "SHIFT - DOWN" "SHIFT - DOWN |or| CONTROL - SHIFT - n"
'go line DOWN' - "DOWN" "DOWN |or| CONTROL - n"
'select word LEFT' - "CONTROL - SHIFT - LEFT" "option-SHIFT - LEFT"
'go to word LEFT' - "CONTROL - LEFT" "option - LEFT"
'select to line start' - "ALT - SHIFT - LEFT"
'go to line start' - "ALT - LEFT |or| home"
'select LEFT' - "SHIFT - LEFT" "SHIFT - LEFT |or| CONTROL - SHIFT - b"
'go to LEFT' - "LEFT" "LEFT |or| CONTROL - b"
'select word RIGHT' - "CONTROL - SHIFT - RIGHT" "option-SHIFT - RIGHT"
'go to word RIGHT' - "CONTROL - RIGHT" "option - RIGHT"
'select to line end' - "ALT - SHIFT - RIGHT"
'go to line end' - "ALT - RIGHT |or| end"
'select RIGHT' - "SHIFT - RIGHT" "SHIFT - RIGHT"
'go to RIGHT' - "RIGHT" "RIGHT |or| CONTROL - F"
'select page DOWN' - "SHIFT - pagedown"
'page DOWN' - "option - pagedown"
'go to page DOWN' - "pagedown" "pagedown |or| CONTROL - v"
'select page UP' - "SHIFT - pageup"
'page UP' - "option - pageup"
'go to page UP' - "pageup"
'scroll UP' - "CONTROL - UP"
'scroll DOWN' - "CONTROL - DOWN"
'select line start' - "SHIFT - home"
'select line end' - "SHIFT - end"
'toggle recording' - "CONTROL - ALT - e" "command-option-e"
'replay macro' - "CONTROL - SHIFT - e" "command-SHIFT - e"
'jump to matching' - "CONTROL - p" "CONTROL - p"
'select to matching' - "CONTROL - SHIFT - p" "CONTROL - SHIFT - p"
'expand to matching' - "CONTROL - SHIFT - m" "CONTROL - SHIFT - m"
'remove line' - "CONTROL - d" "command-d"
'duplicate selection' - "CONTROL - SHIFT - d" "command-SHIFT - d"
'sort lines' - "CONTROL - ALT - s" "command-ALT - s"
'toggle comment' - "CONTROL - /" "command-/"
'toggle block comment' - "CONTROL - SHIFT - /" "command-SHIFT - /"
'modify number UP' - "CONTROL - SHIFT - UP" "ALT - SHIFT - UP"
'modify number DOWN' - "CONTROL - SHIFT - DOWN" "ALT - SHIFT - DOWN"
'replace' - "CONTROL - h" "command-option-f"
'undo' - "CONTROL - z" "command-z"
'redo' - "CONTROL - SHIFT - z |or| CONTROL - y"
'copy lines UP' - "ALT - SHIFT - UP" "command-option-UP"
'move lines UP' - "ALT - UP" "option - UP"
'copy lines DOWN' - "ALT - SHIFT - DOWN" "command-option-DOWN"
'move lines DOWN' - "ALT - DOWN" "option-DOWN"
'del' - "delete" "delete |or| CONTROL - d |or| SHIFT - delete"
'backspace' - "SHIFT - backspace |or| backspace"
'cut or delete' - "SHIFT - delete"
'remove to line start' - "ALT - backspace" "command-backspace"
'remove to line end' - "ALT - delete" "CONTROL - k |or| command-delete"
'remove to line start hard' - "CONTROL - SHIFT - backspace"
'remove to line end hard' - "CONTROL - SHIFT - delete"
'remove word LEFT' - "CONTROL - backspace"
'remove word RIGHT' - "CONTROL - delete" "ALT - delete"
'outdent' - "SHIFT - tab" "SHIFT - tab"
'indent' - "tab" "tab"
'block outdent' - "CONTROL - [" "CONTROL - ["
'block indent' - "CONTROL - ]" "CONTROL - ]"
'split line' - "CONTROL - o"
'transpose letters' - "ALT - SHIFT - x" "CONTROL - t"
'to uppercase' - "CONTROL - u" "CONTROL - u"
'to lowercase' - "CONTROL - SHIFT - u" "CONTROL - SHIFT - u"
'expand to line' - "CONTROL - SHIFT - l" "command-SHIFT - l"