Add New Alert Condition: Send Alert when Signal Trigger does not matter if they are…
- User
Add New Alert Condition: Send Alert when Signal Trigger does not matter if they are above or below EMA: //@version=5 indicator("Candles Not Touching EMA 5 with Arrows and Alerts", 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)
// --- New User 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 (%)")
enable_inside_candle_check = input.bool(true, title="Require Current Candle to be Inside or within N% of Last Candle?") inside_candle_percentage_N = input.float(50.0, minval=0.0, title="Tolerance Percentage N%") // --- End New User Inputs ---
// 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)
// --- Existing Candle Size Logic ---
// Calculate candle sizes prev_candle_size = high[1] - low[1] current_candle_size = high - low
// Initialize is_smaller_by_N_percent is_smaller_by_N_percent = true
// If the feature is enabled, update is_smaller_by_N_percent if enable_percentage_check // Avoid division by zero if prev_candle_size != 0 // Calculate size difference percentage size_difference_percent = (prev_candle_size - current_candle_size) / prev_candle_size * 100
code// Check if current candle is N% smaller than previous candle is_smaller_by_N_percent := size_difference_percent >= percentage_N else // If previous candle size is zero, set condition to false is_smaller_by_N_percent := false// --- New Inside Candle Logic Starts Here ---
// Initialize is_inside_candle_or_within_N_percent is_inside_candle_or_within_N_percent = true
// If the feature is enabled, compute the condition if enable_inside_candle_check // Calculate previous candle's range and tolerance prev_candle_range = high[1] - low[1] tolerance = (inside_candle_percentage_N / 100.0) * prev_candle_range
- Assistant