I11L

I11L - Better Buy Low Volatility or High Volatility?

This Pine Script code defines a TradingView strategy called "I11L - Better Buy Low Volatility or High Volatility?". The strategy aims to study the difference between buying when an asset's volatility is low and when it is high. It allows the user to select whether to buy during low or high volatility periods by changing the input variable mode.

Here's a brief explanation of the System:

The strategy is initialized with relevant settings such as overlay, pyramiding, default quantity type, initial capital, and others.
The mode input allows the user to choose between "Buy low Volatility" and "Buy high Volatility" options.
volatilityTargetRatio is the user-defined threshold to be used for making buy decisions. A value of 1 equals the average ATR (Average True Range) for the security. A lower value indicates lower volatility.
atrLength is the number of periods to calculate the ATR.
sellAfterNBarsLength sets the number of bars to hold the position before selling it.
The script calculates the ATR using the ta.atr() function, and then divides it by the closing price to normalize the value. It also calculates the simple moving average (SMA) of the normalized ATR over a period of 5 times the ATR length, and then computes the ratio between the normalized ATR and its average.

The script keeps track of the number of holding bars using the variable holdingBarsCounter. When there are open trades, the holding bars counter is incremented.

The decision to buy is made based on the selected mode and whether the computed ratio is above or below the user-defined threshold.

When the holding bars counter exceeds the user-defined limit, the position is closed.

The script plots the computed ratio with different colors based on the buy and close conditions. The ratio is plotted in green when a buy signal is triggered, red when a close signal is triggered, and white in all other cases. The value of 1 (the reference for the average ATR) is also plotted on the chart in white color.

This strategy helps traders study the difference between buying during low and high volatility periods and compare the performance of these conditions. It can be useful for analyzing the effectiveness of volatility-based trading strategies, such as entering positions when the market is calm or during periods of strong price movement.
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?