If you’re looking to learn Pine Script coding, you’re in the right place. Read on for this quick and easy Pine Script tutorial as we walk you through a crash course of writing your first TradingView custom indicator.

We’ll be adding to this article as time goes on. Want us to give a specific tutorial? Let us know in our Discord chat.

Weekly High/Low Pine Script Indicator

1. Start a new custom indicator in TradingView.

The goal of this script is to plot the previous weeks’ high and low value. The value should be updated every Sunday.

2. Create variables to hold the high and low values.

Note that we also created two plot variables. This is because we’re going to update our weekHigh/Low vars as we go throughout this week. And our plotHigh/Low vars are the values of last week we’re going to plot throughout this week.

3. If the day is Sunday, store the high and low, and reset the tracking variables.

On Sunday we want to update the plot variables to their corresponding values of the last week. Then we want to reset our in-week variables to be really small and really big so that the next part of our script will work properly.

4. If the day is not Sunday, update the weekHigh and weekLow variables appropriately.

Here, we use the max() and min() functions to do the work for us, and determine if this bar’s high or low is higher or lower than our weekHigh or weekLow variables so far. (This is why we reset them every Sunday above, so that they will always get reset on the first day of the week.

5. Plot!

tradingview pine script custom indicator tutorial

Notes about this script.

  1. First of all, it’ll only work as expected on the Daily (D) TradingView chart. Adjustments will have to be made for it to work on other timeframes.
  2. Signals could easily be added to this indicator. For example, if both the past week’s high and low increased in value from the previous, issue a buy signal.

What did you think of this Pine Script tutorial? Want to learn more? Join our free Discord server to post your questions and get inspired.

Our official Pine Script Course will be released soon. Sign up here for a discount code when its released!