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提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想在圖表上使用此腳本?