Complete System Algorithm
1. Data Collection & Processing
1.1. Data Sources:
• Binance Public API - primary source
• Endpoints:
→ /api/v3/ticker/24hr - current prices and changes
→ /api/v3/klines - historical data (candles)
1.2. Request Parameters:
• Symbol: BTCUSDT, ETHUSDT, etc.
• Timeframe: M5, M15, H1, H4, D1, W1
• Limit: 150 candles
• Frequency: Price updates every 15 seconds
2. Technical Indicators Calculation
2.1. RSI (Relative Strength Index):
• Period: 14
• Formula: RSI = 100 - (100 / (1 + RS))
• RS = Average Gain / Average Loss
• Average Gain = Σ(Gains) / Period
• Average Loss = Σ(Losses) / Period
• Interpretation: <30 = Oversold, >70 = Overbought
2.2. MACD (Moving Average Convergence Divergence):
• EMA12 = Exponential Moving Average (12 periods)
• EMA26 = Exponential Moving Average (26 periods)
• MACD Line = EMA12 - EMA26
• Signal Line = EMA9 of MACD Line
• Histogram = MACD Line - Signal Line
• Bullish: MACD Line > 0 & Histogram > 0
• Bearish: MACD Line < 0 & Histogram < 0
2.3. Stochastic Oscillator:
• Period: 14
• %K = ((Current Close - Lowest Low) / (Highest High - Lowest Low)) × 100
• %D = 3-period SMA of %K
• Interpretation: <20 = Oversold, >80 = Overbought
2.4. Bollinger Bands:
• Period: 20, Standard Deviation: 2
• Middle Band = 20-period SMA
• Upper Band = Middle Band + (2 × Standard Deviation)
• Lower Band = Middle Band - (2 × Standard Deviation)
• Interpretation: Price near lower band = oversold, near upper band = overbought
2.5. Trend Detection (SMA):
• SMA20 = 20-period Simple Moving Average
• SMA50 = 50-period Simple Moving Average
• Bullish Trend: Price > SMA20 & SMA20 > SMA50
• Bearish Trend: Price < SMA20 & SMA20 < SMA50
• Neutral: Mixed signals
3. Weighted Signal Strength Calculation
3.1. Weight Calculation for Each Indicator:
RSI Weight (0-1 scale):
if RSI < 50: buyWeight = (50 - RSI) / 50
if RSI > 50: sellWeight = (RSI - 50) / 50
Example: RSI=30 → buyWeight = (50-30)/50 = 0.40
Stochastic Weight (0-1 scale):
if Stochastic < 50: buyWeight = (50 - Stochastic) / 50
if Stochastic > 50: sellWeight = (Stochastic - 50) / 50
Example: Stochastic=20 → buyWeight = (50-20)/50 = 0.60
MACD Weight (0-1 scale):
if bullish: weight = min(|MACD Line|×10 + |Histogram|×20, 1)
if bearish: weight = min(|MACD Line|×10 + |Histogram|×20, 1)
Example: MACD=0.02, Histogram=0.01 → weight = min(0.02×10 + 0.01×20, 1) = 0.40
Bollinger Bands Weight (0-1 scale):
if price < lowerBB: buyWeight = min(|price - lowerBB| / (BB Range × 0.5), 1)
if price > upperBB: sellWeight = min(|price - upperBB| / (BB Range × 0.5), 1)
Example: Price=$100, lowerBB=$95, BB Range=$10 → buyWeight = min(|100-95|/(10×0.5), 1) = 1.0
Trend Weight:
Bullish trend: +0.5 to buyStrength
Bearish trend: +0.5 to sellStrength
Neutral: +0 to both
3.2. Net Strength Calculation:
totalBuyStrength = Σ(buyWeights from 5 indicators)
totalSellStrength = Σ(sellWeights from 5 indicators)
net = totalBuyStrength - totalSellStrength
maxPossibleNet = 3.0 (5 indicators × max 0.6 each)
3.3. Final Signal Strength (0-100%):
absoluteNet = |net|
strength = (absoluteNet / maxPossibleNet) × 100
strength = clamp(0, 100, round(strength))
3.4. Signal Direction Determination:
if net > 0.1: signal = "BUY"
if net < -0.1: signal = "SELL"
else: signal = "NEUTRAL"
3.5. Strength Level Classification:
if strength ≥ 80: level = "VERY STRONG"
if strength ≥ 60: level = "STRONG"
if strength ≥ 40: level = "MODERATE"
if strength ≥ 20: level = "WEAK"
else: level = "VERY WEAK"
4. Support & Resistance Levels
4.1. Swing Point Detection:
• Window size: 7 periods
• Swing High: Price higher than 7 periods before and after
• Swing Low: Price lower than 7 periods before and after
• Filter duplicates and keep unique levels
4.2. Level Selection:
• Support: Highest swing low below current price
• Resistance: Lowest swing high above current price
• Fallback: If no swing points found, use SMA20/SMA50
• Adjustment: Ensure levels are not too close to current price
4.3. ATR (Average True Range) Calculation:
• Period: 14
• True Range = max(High-Low, |High-PrevClose|, |Low-PrevClose|)
• ATR = SMA of True Ranges
• Used for stop loss buffer calculation
5. Take Profit & Stop Loss Calculation
5.1. For BUY Signals:
• Take Profit (TP) = Resistance Level
• Stop Loss (SL) = Support Level - (ATR × 1.2)
• If strength > 80: TP = TP + (ATR × 0.5) // Extended TP
5.2. For SELL Signals:
• Take Profit (TP) = Support Level
• Stop Loss (SL) = Resistance Level + (ATR × 1.2)
• If strength > 80: TP = TP - (ATR × 0.5) // Extended TP
5.3. Risk-Reward Ratio:
• For BUY: RR = (TP - Entry) / (Entry - SL)
• For SELL: RR = (Entry - TP) / (SL - Entry)
• Minimum acceptable RR: 1:1.5
5.4. Percentage Calculations:
• TP% = ((TP - Entry) / Entry) × 100
• SL% = ((Entry - SL) / Entry) × 100
• For SELL signals, formulas are inverted
6. Complete Algorithm Sequence
Step-by-Step Execution:
1. INITIALIZATION:
• User selects cryptocurrency pair
• User selects timeframe (M5-W1)
• Click "GET SIGNAL" button
2. DATA FETCHING:
• Fetch current price from Binance API
• Fetch 150 historical candles for selected timeframe
• Validate data integrity and completeness
3. INDICATOR CALCULATION:
• Calculate RSI (14 period)
• Calculate MACD (12,26,9)
• Calculate Stochastic (14 period)
• Calculate Bollinger Bands (20,2)
• Calculate SMA20 and SMA50 for trend
• Calculate ATR (14 period)
4. SUPPORT/RESISTANCE IDENTIFICATION:
• Detect swing highs and swing lows
• Identify nearest support and resistance levels
• Apply fallback calculations if needed
5. WEIGHTED SIGNAL GENERATION:
• Calculate weights for each indicator (0-1 scale)
• Sum buy weights and sell weights separately
• Calculate net strength
• Convert to percentage (0-100%)
• Determine signal direction (BUY/SELL/NEUTRAL)
• Classify strength level (VERY WEAK to VERY STRONG)
6. TP/SL CALCULATION:
• Calculate Take Profit based on resistance/support
• Calculate Stop Loss with ATR buffer
• Adjust TP for strong signals (>80%)
• Calculate Risk-Reward ratio
• Calculate percentage gains/losses
7. RESULT DISPLAY:
• Display signal with direction and strength level
• Show strength percentage with colored progress bar
• Display indicator grid with values and weights
• Show calculated TP, SL, and RR
• Display support and resistance levels
• Show warning for weak signals (<40%)
8. UPDATE CYCLE:
• Prices update automatically every 15 seconds
• Signals regenerate only on user request
• Historical data updates with each new signal
• Real-time price changes trigger visual updates
7. Visual Display Components
Signal Display
- Signal Header: BUY/SELL (STRENGTH LEVEL)
- Strength %: 0-100% in colored badge
- Progress Bar: Visual strength representation
- Strength Text: Very Weak to Very Strong
- Color Coding: Green=BUY, Red=SELL, Gray=NEUTRAL
Indicator Grid
- 5 Indicators: RSI, Stochastic, MACD, Trend, BB
- Current Value: Numerical value
- Weight Value: Contribution to signal (0.00-1.00)
- Color Badges: Visual state indication
- Direction Arrows: Up/down/neutral
TP/SL Panel
- Take Profit: Target price with percentage gain
- Stop Loss: Protective price with percentage loss
- RR Ratio: Risk-Reward ratio (1:X format)
- Level Source: Support/Resistance reference
- ATR Buffer: Stop loss adjustment factor
Support/Resistance
- Support Level: Price floor calculation
- Resistance Level: Price ceiling calculation
- Swing Points: Based on historical price action
- Fallback Levels: SMA20/SMA50 if no swing points
- Real-time Updates: Based on latest data
8. Technical Specifications
System Performance:
• Response Time: <3 seconds for signal generation
• Accuracy: Weighted multi-indicator approach
• Reliability: Fallback calculations for edge cases
• Scalability: Handles 20+ cryptocurrency pairs
• Real-time: Price updates every 15 seconds
Algorithm Advantages:
• No single point of failure (5 independent indicators)
• Weighted system prevents false signals
• Dynamic TP/SL based on market volatility (ATR)
• Support/Resistance based on actual price action
• Clear strength classification for risk management
Risk Management Features:
• Automatic stop loss calculation
• Minimum 1:1.5 risk-reward ratio
• Strength-based position sizing recommendations
• Weak signal warnings (<40% strength)
• Extended TP for strong signals (>80% strength)