Add New Logic alongSide old: Sometime there are conditions when a candle is above EMA…
- User
Add New Logic alongSide old: Sometime there are conditions when a candle is above EMA that is not touching EMA have low N% Daily ATR away from EMA or below EMA that is not touching EMA have high N% Daily ATR away from EMA, and all other logic (Require last N candles to have touched EMA?, Require N% of Current Candle to Overlap with Last Candle?, Require candle to be N% smaller than last candle?) also met, then highlight those candle with orange circle, Add This New Signal in Old Alert Condition: //@version=5 indicator("Candles Not Touching EMA 5 with Overlap and Size Check (Updated)", overlay=true)
// User inputs enable_last_n_check = input.bool(true, title="Require last N candles to have touched EMA?") N = input.int(3, minval=1, title="Number of candles to check") enable_stop_loss_feature = input.bool(true, title="Enable Stop Loss Levels") atr_percent = input.float(2.0, title="ATR Percentage for Stop Loss (%)", minval=0, step=0.1)
// Overlap Method Inputs enable_overlap_check = input.bool(true, title="Require N% of Current Candle to Overlap with Last Candle?") overlap_percentage_N = input.float(50.0, minval=0.0, maxval=100.0, title="Required Overlap Percentage N%")
// Candle Size Inputs enable_percentage_check = input.bool(true, title="Require candle to be N% smaller than last candle?") percentage_N = input.float(20.0, minval=0.01, title="Percentage smaller (%)")
// New Distance from EMA Check Inputs enable_distance_check = input.bool(false, title="Enable Distance from EMA Check?") distance_atr_percent = input.float(2.0, minval=0.0, step=0.1, title="ATR Percentage for Distance from EMA (%)")
// Inputs to select which logic to ignore when Distance Condition is Met ignore_last_n_check = input.bool(false, title="Ignore Last N Candles Touching EMA Check when Distance Condition is Met?") ignore_overlap_check = input.bool(false, title="Ignore Overlap Check when Distance Condition is Met?") ignore_percentage_check = input.bool(false, title="Ignore Size Percentage Check when Distance Condition is Met?")
// Calculate EMA 5 ema5 = ta.ema(close, 5)
// Identify candles that do not touch EMA 5 not_touching = (low > ema5) or (high < ema5)
// Identify candles that touch EMA 5 touching = not not_touching
// Function to check if all of the last N candles touched the EMA all_last_N_touching(N) => result = true for i = 1 to N result := result and touching[i] result
// Initialize condition_for_signal condition_for_signal = true
// If the feature is enabled, update condition_for_signal if enable_last_n_check // Condition for signal: all of the last N candles touched the EMA condition_for_signal := all_last_N_touching(N)
// Overlap Method Logic
// Initialize is_current_candle_N_percent_overlapping is_current_candle_N_percent_overlapping = true
// If the feature is enabled, compute the condition if enable_overlap_check // Calculate current candle's range current_candle_range = high - low // Avoid division by zero if current_candle_range != 0 // Calculate overlap between current candle and previous candle overlap_high = math.min(high, high[1]) overlap_low = math.max(low, low[1]) overlap_range = overlap_high - overlap_low // If overlap_range is negative or zero, set condition to false if overlap_range <= 0 is_current_candle_N_percent_overlapping := false else // Calculate percentage of current candle's range that overlaps with previous candle's range percentage_of_current_overlapping = (overlap_range / current_candle_range) * 100.0 // Check if percentage is greater than or equal to N% is_current_candle_N_percent_overlapping := percentage_of_current_overlapping >= overlap_percentage_N else // If current candle range is zero, set condition to false is_current_candle_N_percent_overlapping := false
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.