A comprehensive automated trading system for the Nepal Stock Exchange (NEPSE) that provides real-time technical analysis, trading signals, and portfolio management.
- Real-time Data Fetching: Connects to NEPSE API for live market data
- Technical Analysis: Comprehensive indicator analysis (RSI, MACD, Bollinger Bands, EMA, SMA)
- Candlestick Pattern Recognition: Detects hammer, engulfing, morning star, evening star patterns
- Signal Generation: BUY/SELL/HOLD signals with confidence scores
- Position Sizing: Calculates optimal quantity based on capital and confidence
- Portfolio Management: Track positions, P&L, and performance
- Discord Notifications: Real-time alerts for trading signals via Discord webhooks
- Chart Generation: Professional technical analysis charts
- Database Storage: SQLite database for historical data and signals
- Automated Scheduling: Configurable analysis intervals
- Stop Loss: Configurable stop loss percentages
- Position Limits: Maximum position size per trade
- Volume Filters: Minimum volume thresholds
- Confidence Scoring: Only trade high-confidence signals
- Python 3.8+
- NEPSE API access
- Discord webhook (optional, for notifications)
-
Clone the repository
git clone <repository-url> cd nepse-trading-bot
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables Create a
.envfile:DISCORD_WEBHOOK_URL=your_discord_webhook_url DISCORD_USERNAME=NEPSE Trading Bot DISCORD_AVATAR_URL=your_avatar_url # Optional
-
Initialize the system
python main.py --once
Edit config.py to customize:
- Trading Parameters: Capital, position sizes, stop losses
- Technical Indicators: RSI, MACD, Bollinger Bands settings
- Analysis Settings: History days, symbol limits, intervals
- Risk Management: Volume thresholds, confidence requirements
python main.py --oncepython main.pyfrom main import NepseTradingBot
import asyncio
async def analyze_symbol():
bot = NepseTradingBot()
result = await bot.analyze_symbol("NABIL")
print(result)
asyncio.run(analyze_symbol())- RSI oversold (< 30)
- MACD bullish crossover
- Price below Bollinger lower band
- Bullish candlestick patterns
- High volume confirmation
- RSI overbought (> 70)
- MACD bearish crossover
- Price above Bollinger upper band
- Bearish candlestick patterns
- High volume confirmation
- Mixed or neutral indicators
- Low confidence scores
- No clear pattern direction
- EMA (20): Exponential Moving Average
- SMA (50, 200): Simple Moving Averages
- RSI (14): Relative Strength Index
- MACD: Moving Average Convergence Divergence
- Bollinger Bands (20, 2): Volatility bands
- Volume Analysis: Volume SMA and ratios
- ATR (14): Average True Range
- Hammer: Bullish reversal pattern
- Shooting Star: Bearish reversal pattern
- Doji: Indecision pattern
- Bullish/Bearish Engulfing: Strong reversal signals
- Morning/Evening Star: Three-candle reversal patterns
The system automatically:
- Tracks all positions
- Calculates P&L
- Manages position sizes
- Prevents duplicate positions
- Records trade history
Receive real-time alerts for:
- Trading signals with details
- Portfolio updates
- Market summaries
- Error notifications
- System status
- StockData: Historical price data
- TradingSignal: Generated signals
- Portfolio: Active positions
- MarketSummary: Market statistics
nepse-trading-bot/
βββ main.py # Main application
βββ config.py # Configuration settings
βββ requirements.txt # Dependencies
βββ README.md # This file
βββ data/
β βββ nepse_api.py # API client
βββ analysis/
β βββ technical_indicators.py # Technical analysis
βββ notifications/
β βββ discord_bot.py # Discord notifications
β βββ telegram_bot.py # Telegram notifications (legacy)
βββ visualization/
β βββ chart_generator.py # Chart generation
βββ database/
β βββ models.py # Database models
βββ charts/ # Generated charts
βββ logs/ # Log files
# In technical_indicators.py
def compute_indicators(self, df):
# Add your custom indicator
df['custom_indicator'] = your_calculation(df)
return df# In technical_indicators.py
def _generate_signal_for_row(self, df, index):
# Add your custom signal logic
if your_condition:
return "BUY", confidence# Create new notification class
class CustomNotifier:
async def send_signal(self, signal_data):
# Your notification logic
passThe system tracks:
- Total return
- Win rate
- Average P&L
- Maximum drawdown
- Sharpe ratio
- Position duration
This software is for educational and research purposes only. Trading involves substantial risk of loss. Always:
- Test thoroughly before live trading
- Start with small positions
- Monitor system performance
- Have proper risk management
- Consult financial advisors
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Check the logs in
logs/trading_bot.log - Review configuration settings
- Test with
--onceflag first - Create an issue with detailed error information
For detailed Discord notification setup instructions, see DISCORD_SETUP.md.
- v1.0: Initial release with core functionality
- v1.1: Added candlestick patterns
- v1.2: Enhanced portfolio management
- v1.3: Improved chart generation
- v1.4: Added backtesting capabilities
Happy Trading! π