Next Steps: Introduction to Pine ScriptWelcome back, traders! In our previous video, we took our first steps into Pine Script™ and learned about creating indicators. Today, we're going to dive deeper into the Pine Script™ landscape and provide some valuable pointers to guide you on your journey of mastering Pine Script™. So let's get started!
The first important distinction we need to make is between "indicators" and "strategies" in Pine Script™. Indicators are primarily used for calculations and displaying information on charts. They are lightweight and don't require the broker emulator, making them faster to execute. You can use indicators to analyze market data and generate visual representations of technical analysis tools, such as moving averages, oscillators, and custom calculations. Indicators are a great choice when you don't need to backtest your strategies.
On the other hand, strategies are used for backtesting and forward testing. They include trade order functionality and can simulate trade executions. With strategies, you can define entry and exit conditions, apply risk management rules, and evaluate the performance of your trading ideas. Strategies provide detailed backtest results in the "Strategy Tester" tab, located next to the "Pine Script™ Editor" tab. They allow you to assess the historical performance of your trading strategy before deploying it in live markets.
Now, let's talk about how scripts are executed in Pine Script™. Unlike traditional programming languages, Pine Script™ runs in a loop-like fashion, executing once on each bar of the chart from left to right. Historical bars refer to those that have already closed when the script executes on them, while the last bar, known as the realtime bar, remains open. The script then executes whenever a price or volume change is detected and once again when the realtime bar closes. This execution model enables real-time monitoring of market conditions and the opportunity to react to price and volume movements.
It's important to note that the script doesn't recalculate on historical bars during realtime execution. This optimization improves efficiency by avoiding unnecessary calculations on past data that have already been processed. Pine Script™ provides this performance enhancement by storing the calculated values of historical bars, allowing the script to focus on updating the current and future bars efficiently.
In Pine Script™, a fundamental concept is the time series. Time series are data structures that hold values for each bar the script executes on. They continuously expand as the script progresses through more bars. By using the history-referencing operator, which is denoted by square brackets , you can access past values of a time series. For example, close refers to the close value on the preceding bar, close refers to the close value two bars ago, and so on. This powerful feature allows you to incorporate historical data into your calculations and create complex trading algorithms.
It's crucial to understand the time series and how they differ from traditional arrays. While the indexing mechanism may resemble arrays, thinking in terms of arrays can be detrimental to understanding this key Pine Script™ concept. Time series in Pine Script™ expand dynamically with each bar, and their values are automatically updated as new data becomes available. This dynamic nature enables you to create adaptive and responsive trading strategies that take into account changing market conditions.
Moving on, let's discuss script publishing. TradingView is a vibrant community of Pine Script™ programmers and traders from around the world. Once you become proficient in Pine Script™, you have the option to share your scripts with others. Before publishing, ensure your scripts are original and well-documented. All publicly published scripts undergo analysis by TradingView's moderators and must comply with Script Publishing Rules. These rules maintain the quality and integrity of the scripts available on the platform.
If you prefer to use your Pine scripts for personal use, you can simply write them in the Pine Script™ Editor and add them to your charts without publishing them. However, if you want to share your scripts with a select group of individuals, you can publish them privately and provide your friends with the browser link to your private publication. This way, you can collaborate with others and receive valuable feedback on your scripts.
To navigate the Pine Script™ documentation effectively, it's essential to spend time exploring the available resources. Our main documentation sources are the Pine Script™ v5 User Manual and the Pine Script™ v5 Reference Manual. The User Manual provides comprehensive explanations and examples to help you grasp the fundamentals of Pine Script™. The Reference Manual serves as a detailed reference guide, documenting the functions, variables, and keywords available in Pine Script™. It's a valuable tool for every Pine Script™ programmer and is essential for writing scripts of reasonable complexity.
Remember to consult the documentation corresponding to the version of Pine Script™ you are working with. It's crucial to stay up to date with the latest advancements and improvements in Pine Script™ by regularly checking the Release Notes.
That wraps up our introduction to Pine Script™ and its landscape. We hope you found these insights helpful in your journey to become a proficient Pine Script™ programmer and trader. Remember to practice, explore, and experiment with the concepts we discussed today. By combining time series with the built-in functions designed to handle them efficiently, you'll be amazed at what you can accomplish with just a few lines of Pine Script™ code.
Thank you for joining us today, and we wish you success in mastering Pine Script™ and achieving your trading goals!
Timeseries
BTCUSD Time serise . daily timeframeIn the daily timeframe after the start of the uptrend in March 2020, the downtrends that formed after the uptrend all corrected about 50% of their previous wave time, so according to the previous cycles, I expect on January 7-8, the bitcoin phase Start your ascent again. You can see in the chart
time series BTC in weekly timeframeWell, in the weekly timeframe time series from about 2010 onwards, each ascending and descending wave consists of four cycles, of which three are ascending and one is descending, as I have shown in the chart. According to these cycles, we are now in the third wave of the third cycle, and in the previous cycles before the end of the third wave, a strong sound wave formed and then began to fall, which I expect this cycle to repeat again.