1st Pine Script Lesson: Coding an Indicator - Bollinger Band



Welcome to this lesson on Trading View, where we will be learning how to create a Bollinger Band indicator using Pine Script.

Bollinger Bands are a popular tool that helps measure an asset's volatility and identify potential trends in price movement. Essentially, the indicator consists of three lines: a middle line that's a simple moving average (SMA), and an upper and lower band that are two standard deviations away from the SMA. The upper band represents the overbought level, meaning the price of the asset is considered high and may be due for a correction. The lower band represents the oversold level, meaning the price is considered low and may be due for a rebound.

Pine Script is a programming language specifically used for creating custom indicators and strategies on Trading View. It's a powerful tool that allows traders to customize their technical analysis to fit their special trading needs and gain deeper insights into the markets..

In this lesson, we'll be taking a hands-on approach to learning. We'll walk through each step of creating our own Bollinger Band indicator using Pine Script, with the goal of helping you gain confidence in your ability to customize and create indicators that meet your unique trading needs. So, grab a cup of coffee and let's get started!

Step 1: Set up a new chart

Let‘s set up a new clean chart to work with for this example. You will find the menu to manage your layouts on the top right of the TradingView screen.

a) add a new layout
b) rename it to „Mizar Example“
c) select BTCUSDT from Binance
d) set the time frame to 1 hour
e) clean the screen (closing the Volume indicator)
f) save it [Ctrl+S]

Step 2: Coding an indicator

Let‘s code our new indicator („Mizar-Killer-Long-Approach“)and make the possible entry moments visible on the chart. You will find the Pine Editor on the bottom left of the TradingView screen.

a) open the Pine Editor
b) use „Open“ in the Pine Editor menu bar
c) use the item: create a new indicator
d) let‘s use full screen for a better overview use the three dots on the right end of the Pine Editor menu bar and open the script in a separate new browser tab
e) rename it to “Mikilap“ by clicking on the current name
f) save it

Step 3: Coding an indicator

Let‘s start coding Our target:
1. create an own new indicator: Mikilap, which bases in general on RSI and Bollinger Band
2. define the parameter for Mikilap, to select the long entries
3. show the long entries on the chart by - putting a label below the bar - change the background color of the timeframe for the bar on the chart

Initiation/Generals

• Indicator initiation


//Indicator script initiation



indicator = Pine keyword for an indicator script
title = Long form of the name
short title = Short form of the name as shown on the chart
overlay = true: output like labels, boxes, … are shown on the chart
false: output like plots, … are shown in a separate pane

• General variables and input


// Coin Pair with PREFIX
// Bitcoin / USDT on Binance as an example / standard value on an 60 minutes = 1-hour timeframe



Using the input type of a variable allows you to change this setting in the setup on the chart without changing the Pine Script code.

Framework Code on Main Level
• Framework code on the main level around the indicator calculation function


// Defintion of a Pine Script individual function to handle the Request and avoid Repainting Errors



// placeholder for indicator calculations


function_result


// Calling the Milky Way function to start the calculation


Output on the chart - Part 1


// Output on the chart
// Part 1 - plotting a Bollinger Band for the active CoinPair on the chart




Done for today!
• Let‘s save our current script and take a look if we see our Bollinger Band plotted on the chart.
• Step 1: Save (top right)
• Step 2: check in the compiling section, that there are no errors (separate pane below the code)
• Step 3: go to the Mizar Example chart and add an Indicator


How does it look now?
You will see the Bollinger Band as a yellow area around the candles. By pressing the „Settings“ button behind the name of our indicator, the menu for Mikilap will open and you can adjust all the settings we have done with input type variables.


Congrats if you‘ve made it until here! Get prepared for the next lesson, where we will continue with the indicator/entry logic.
Beyond Technical Analysisbollinger_bandsbollingerbandstrategybollingersbandBTCUSDTTechnical Indicatorsindicatorstrategymizarpinescriptpinescripting4tradersTrend Analysis

Juga pada:

Penafian