// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at…
- User
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © golshantashan
//@version=6 indicator(title="Ichimoku", shorttitle="Ichimoku", overlay=true)
// Input parameters conversionPeriods = input.int(9, minval=1, title="Conversion Line Length") basePeriods = input.int(26, minval=1, title="Base Line Length") laggingSpan2Periods = input.int(52, minval=1, title="Leading Span B Length") displacement = input.int(26, minval=1, title="Lagging Span")
// Donchian function donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
// Calculate lines conversionLine = donchian(conversionPeriods) baseLine = donchian(basePeriods) leadLine1 = math.avg(conversionLine, baseLine) leadLine2 = donchian(laggingSpan2Periods)
// Plot Leading Span A and B with offset p1 = plot(leadLine1, offset=displacement - 1, color=#A5D6A7, title="Leading Span A") p2 = plot(leadLine2, offset=displacement - 1, color=#EF9A9A, title="Leading Span B")
// Detect crossover and crossunder cross_up = ta.crossover(leadLine1, leadLine2) cross_down = ta.crossunder(leadLine1, leadLine2)
// Variables for red cloud var int red_last_cross_bar = 0 var float red_max_leadLine2 = na var float red_min_leadLine1 = na var bool is_red_cloud = false var int red_candle_count = 0 var int red_cross_bar_index = na
// Variables for green cloud var int green_last_cross_bar = 0 var float green_max_leadLine1 = na var float green_min_leadLine2 = na var bool is_green_cloud = false var int green_candle_count = 0 var int green_cross_bar_index = na
// Update red and green cloud states if cross_down is_red_cloud := true is_green_cloud := false red_max_leadLine2 := leadLine2 red_min_leadLine1 := leadLine1 red_last_cross_bar := bar_index red_candle_count := 0 red_cross_bar_index := bar_index else if cross_up is_red_cloud := false is_green_cloud := true green_max_leadLine1 := leadLine1 green_min_leadLine2 := leadLine2 green_last_cross_bar := bar_index green_candle_count := 0 green_cross_bar_index := bar_index
// Update values during red cloud if is_red_cloud red_candle_count := red_candle_count + 1 red_max_leadLine2 := na(red_max_leadLine2) ? leadLine2 : math.max(red_max_leadLine2, leadLine2) red_min_leadLine1 := na(red_min_leadLine1) ? leadLine1 : math.min(red_min_leadLine1, leadLine1)
// Update values during green cloud if is_green_cloud green_candle_count := green_candle_count + 1 green_max_leadLine1 := na(green_max_leadLine1) ? leadLine1 : math.max(green_max_leadLine1, leadLine1) green_min_leadLine2 := na(green_min_leadLine2) ? leadLine2 : math.min(green_min_leadLine2, leadLine2)
// Display label at the end of red cloud with OHLC if cross_up and not na(red_max_leadLine2) and not na(red_min_leadLine1) red_candles_since_last_cross = red_candle_count red_pip_diff = (red_max_leadLine2 - red_min_leadLine1) / syminfo.mintick * 0.1 red_label_text = str.tostring(red_candles_since_last_cross) + " candles\n" + "Diff (pips): " + str.tostring(red_pip_diff, "#.##") + "\n" + "Max LeadLine2: " + str.tostring(red_max_leadLine2, "#.##") + "\n" + "Min LeadLine1: " + str.tostring(red_min_leadLine1, "#.##") label.new( bar_index + displacement - 1, high, red_label_text, color=#ff52a370, style=label.style_label_down, textcolor=color.white ) // Reset red cloud variables red_max_leadLine2 := na red_min_leadLine1 := na red_candle_count := 0 red_last_cross_bar := bar_index
- Assistant
- User
کد کامل بده
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.