Buongiorno chiedo di voler cortesemente tradurre il seguente codice Pine Script.
Ringrazio anticipatamente
Cordiali saluti// ____ __ ___ ________ ___________ ___________ __ ____ ___
// / __ )/ / / | / ____/ //_/ ____/ |/_ __< / // / / __ |__
// / __ / / / /| |/ / / ,< / / / /| | / / / / // /_/ / / __/ /
// / /_/ / /___/ ___ / /___/ /| / /___/ ___ |/ / / /__ __/ /_/ / __/
// /_____/_____/_/ |_____/_/ |_____/_/ |_/_/ /_/ /_/ ____/____/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//NOTE: to use this indicator properly, you should turn off TV candle symbol setting by, settings–>symbol–> body, borders, wick are all unchecked.
// © blackcat1402
//@version=5
indicator(title=”[blackcat] L1 Adaptive Choppiness Index”, shorttitle=”ACHOP”, format=format.price, precision=2, max_labels_count = 500)
import blackcat1402/dc_ta/2 as dc
// Function to calculate the adaptive choppiness index
calculate_adaptive_choppiness_index(close_price, cycle_participation) =>
// Calculate the length using Ehlers’ Ho-Dy DC
length = math.ceil(dc.EhlersHoDyDC(close_price, cycle_participation))
// Calculate the Adaptive Choppiness Index
choppiness_index = 100 * math.log10(math.sum(ta.atr(1), length) / (ta.highest(length) – ta.lowest(length))) / math.log10(length)
alma_choppiness_index = ta.alma(choppiness_index, 5, 0.85, 6)
// Return the Adaptive Choppiness Index
alma_choppiness_index
// Input parameters
cycle_participation = input.float(0.25, minval=0.00001, step=0.05, title=”Cycle Participation”)
offset_value = input.int(0, “Offset”, minval=-500, maxval=500)
// Calculate the Adaptive Choppiness Index
choppiness_index = calculate_adaptive_choppiness_index(close, cycle_participation)
// Plot the Adaptive Choppiness Index
plot(choppiness_index, title=”CHOP”, color=color.yellow, offset=offset_value)
// Define the bands
upper_band = hline(61.8, “Upper Band”, color=color.new(#787B86, 0), linestyle=hline.style_dashed)
middle_band = hline(50, “Middle Band”, color=color.new(#787B86, 50))
lower_band = hline(38.2, “Lower Band”, color=color.new(#787B86, 0), linestyle=hline.style_dashed)
// Fill the area between the upper and lower bands
fill(upper_band, lower_band, color=color.new(#2196F3, 90), title=”Background”)
// Add trend and sideways labels based on the Adaptive Choppiness Index
var label trend_label = na
var label sideways_label = na
if (choppiness_index > 61.8)
// label.delete(trend_label)
trend_label := label.new(bar_index, choppiness_index, text=”Trend”, style=label.style_label_up, color=color.green, textcolor=color.white, size=size.auto)
// label.delete(sideways_label)
if (choppiness_index < 38.2)
// label.delete(trend_label)
trend_label := label.new(bar_index, choppiness_index, text=”Trend”, style=label.style_label_down, color=color.red, textcolor=color.white, size=size.auto)
// label.delete(sideways_label)
if (choppiness_index >= 38.2 and choppiness_index <= 61.8)
// label.delete(sideways_label)
sideways_label := label.new(bar_index, choppiness_index, text=”Sideways”, style=label.style_label_right, color=color.orange, textcolor=color.white, size=size.auto)
// label.delete(trend_label)
// Alerts
alertcondition(choppiness_index > 61.8, title=”Trend Alert”, message=”The market is in a trend.”)
alertcondition(choppiness_index < 38.2, title=”Trend Alert”, message=”The market is in a trend.”)
alertcondition(choppiness_index >= 38.2 and choppiness_index <= 61.8, title=”Sideways Alert”, message=”The market is sideways.”)