OPEN-SOURCE SCRIPT
Cập nhật KCandle Strategy 1.0

# KCandle Strategy 1.0 - Trading Strategy Description
## Overview
The **KCandle Strategy** is an advanced Pine Script trading system based on bullish and bearish engulfing candlestick patterns, enhanced with sophisticated risk management and position optimization features.
## Core Logic
### Entry Signal Generation
- **Pattern Recognition**: Detects bullish and bearish engulfing candlestick formations
- **EMA Filter**: Uses a customizable EMA (default 25) to filter trades in the direction of the trend
- **Entry Levels**:
- **Long entries** at 25% of the candlestick range from the low
- **Short entries** at 75% of the candlestick range from the low
- **Signal Validation**: Orange candlesticks indicate valid setup conditions
### Risk Management System
#### 1. **Stop Loss & Take Profit**
- Configurable stop loss in pips
- Risk-reward ratio setting (default 2:1)
- Visual representation with colored lines and labels
#### 2. **Break-Even Management**
- Automatically moves stop loss to break-even when specified R:R is reached
- Customizable break-even offset for added protection
- Prevents losing trades after reaching profitability
#### 3. **Trailing Stop System**
- **Activation Trigger**: Activates when position reaches specified R:R level
- **Distance Control**: Maintains trailing stop at defined distance from entry
- **Step Management**: Moves stop loss forward in incremental R steps
- **Dynamic Protection**: Locks in profits while allowing for continued upside
### Advanced Features
#### Position Management
- **Pyramiding Support**: Optional multiple position entries with size reduction
- **Order Expiration**: Pending orders automatically cancel after specified bars
- **Position Sizing**: Percentage-based allocation with pyramid level adjustments
#### Visual Interface
- **Real-time Monitoring**: Comprehensive information panel with all strategy metrics
- **Historical Tracking**: Visual representation of past trades and levels
- **Color-coded Indicators**: Different colors for break-even, trailing, and standard stops
- **Debug Options**: Optional labels for troubleshooting and optimization
## Key Parameters
### Basic Settings
- **EMA Length**: Trend filter period
- **Stop Loss**: Risk per trade in pips
- **Risk/Reward**: Target profit ratio
- **Order Validity**: Duration of pending orders
### Risk Management
- **Break-Even R:R**: Profit level to trigger break-even
- **Trailing Activation**: R:R level to start trailing
- **Trailing Distance**: Stop distance from entry when trailing
- **Trailing Step**: Increment for stop loss advancement
## Strategy Benefits
1. **Objective Entry Signals**: Based on proven candlestick patterns
2. **Trend Alignment**: EMA filter ensures trades align with market direction
3. **Robust Risk Control**: Multiple layers of protection (SL, BE, Trailing)
4. **Profit Optimization**: Trailing stops maximize winning trade potential
5. **Flexibility**: Extensive customization options for different market conditions
6. **Visual Clarity**: Complete visual feedback for trade management
## Ideal Use Cases
- **Swing Trading**: Medium-term positions with trend-following approach
- **Breakout Trading**: Capturing momentum from engulfing patterns
- **Risk-Conscious Trading**: Suitable for traders prioritizing capital preservation
- **Multi-Timeframe**: Adaptable to various timeframes and instruments
---
*The KCandle Strategy combines traditional technical analysis with modern risk management techniques, providing traders with a comprehensive tool for systematic market participation.*
## Overview
The **KCandle Strategy** is an advanced Pine Script trading system based on bullish and bearish engulfing candlestick patterns, enhanced with sophisticated risk management and position optimization features.
## Core Logic
### Entry Signal Generation
- **Pattern Recognition**: Detects bullish and bearish engulfing candlestick formations
- **EMA Filter**: Uses a customizable EMA (default 25) to filter trades in the direction of the trend
- **Entry Levels**:
- **Long entries** at 25% of the candlestick range from the low
- **Short entries** at 75% of the candlestick range from the low
- **Signal Validation**: Orange candlesticks indicate valid setup conditions
### Risk Management System
#### 1. **Stop Loss & Take Profit**
- Configurable stop loss in pips
- Risk-reward ratio setting (default 2:1)
- Visual representation with colored lines and labels
#### 2. **Break-Even Management**
- Automatically moves stop loss to break-even when specified R:R is reached
- Customizable break-even offset for added protection
- Prevents losing trades after reaching profitability
#### 3. **Trailing Stop System**
- **Activation Trigger**: Activates when position reaches specified R:R level
- **Distance Control**: Maintains trailing stop at defined distance from entry
- **Step Management**: Moves stop loss forward in incremental R steps
- **Dynamic Protection**: Locks in profits while allowing for continued upside
### Advanced Features
#### Position Management
- **Pyramiding Support**: Optional multiple position entries with size reduction
- **Order Expiration**: Pending orders automatically cancel after specified bars
- **Position Sizing**: Percentage-based allocation with pyramid level adjustments
#### Visual Interface
- **Real-time Monitoring**: Comprehensive information panel with all strategy metrics
- **Historical Tracking**: Visual representation of past trades and levels
- **Color-coded Indicators**: Different colors for break-even, trailing, and standard stops
- **Debug Options**: Optional labels for troubleshooting and optimization
## Key Parameters
### Basic Settings
- **EMA Length**: Trend filter period
- **Stop Loss**: Risk per trade in pips
- **Risk/Reward**: Target profit ratio
- **Order Validity**: Duration of pending orders
### Risk Management
- **Break-Even R:R**: Profit level to trigger break-even
- **Trailing Activation**: R:R level to start trailing
- **Trailing Distance**: Stop distance from entry when trailing
- **Trailing Step**: Increment for stop loss advancement
## Strategy Benefits
1. **Objective Entry Signals**: Based on proven candlestick patterns
2. **Trend Alignment**: EMA filter ensures trades align with market direction
3. **Robust Risk Control**: Multiple layers of protection (SL, BE, Trailing)
4. **Profit Optimization**: Trailing stops maximize winning trade potential
5. **Flexibility**: Extensive customization options for different market conditions
6. **Visual Clarity**: Complete visual feedback for trade management
## Ideal Use Cases
- **Swing Trading**: Medium-term positions with trend-following approach
- **Breakout Trading**: Capturing momentum from engulfing patterns
- **Risk-Conscious Trading**: Suitable for traders prioritizing capital preservation
- **Multi-Timeframe**: Adaptable to various timeframes and instruments
---
*The KCandle Strategy combines traditional technical analysis with modern risk management techniques, providing traders with a comprehensive tool for systematic market participation.*
Phát hành các Ghi chú
-Bug fixMã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.