Nija

NIJA Profitability Analysis Guide

Overview

This guide explains how to check if NIJA is making more profit than losses using the profitability analysis tool.

Quick Start

Basic Analysis

Run the profitability analyzer to see if NIJA is profitable:

python analyze_profitability.py

This will show you:

Detailed Analysis

For a detailed breakdown of all trades:

python analyze_profitability.py --detailed

Export to CSV

Export trade history to CSV for further analysis:

python analyze_profitability.py --export-csv

The CSV file will be saved in data/nija_trades_YYYYMMDD_HHMMSS.csv

Understanding the Report

Trade Summary

Financial Summary

Recent Trades

Shows the last 10 trades with:

Current Status (As of 2026-01-26)

❌ NIJA IS CURRENTLY LOSING MONEY

Completed Trades Analysis

  1. ETH-USD (Loss)
    • Entry: $103.65 → Exit: $93.32
    • Net P&L: -$11.10 (-11.10%)
    • Exit Reason: Stop loss hit
    • Issue: Stop loss triggered with -10.62% loss
  2. BTC-USD (Win)
    • Entry: $50,000 → Exit: $51,000
    • Net P&L: +$0.80 (+0.80%)
    • Exit Reason: Take profit hit
    • Issue: Only 2% gain before exit

Root Cause Analysis

The current loss is due to:

  1. Risk/Reward Imbalance: Losing -11.10% on losses vs winning only +0.80%
  2. Stop Loss Too Loose: Allowing -10.62% loss on ETH trade
  3. Profit Target Too Tight: Taking only +2% profit on BTC trade (before fees)
  4. Poor Profit Factor: 0.07 (should be > 1.5 for profitable trading)

Immediate Actions Required

  1. Adjust Stop Loss Levels
    • Current: Allowing ~10% loss per trade
    • Recommended: Tighten to 2-3% maximum loss
    • Location: bot/risk_manager.py or strategy configuration
  2. Widen Profit Targets
    • Current: Taking profits at ~2% gain
    • Recommended: Target at least 4-6% gain (2:1 reward-to-risk ratio)
    • Location: bot/nija_apex_strategy_v71.py or profit-taking configuration
  3. Review Entry Filters
    • Ensure entering only high-quality setups
    • Check market regime filters
    • Verify signal strength requirements
  4. Position Sizing
    • Consider reducing position size while optimizing
    • Current: $100 per trade (from examples)
    • This limits risk during adjustment period

Long-Term Improvements

  1. Implement Trailing Stops
    • Protect profits as they grow
    • Reduce losses by moving stop loss to break-even
  2. Add Win Rate Monitoring
    • Alert if win rate drops below 50%
    • Auto-reduce position size during losing streaks
  3. Risk/Reward Ratio Enforcement
    • Require minimum 2:1 reward-to-risk before entry
    • Reject trades with poor risk/reward profiles
  4. Strategy Backtesting
    • Test parameter changes on historical data
    • Validate improvements before live deployment

Monitoring Profitability

Automated Monitoring

Add to your startup script or cron job:

# Check profitability daily
0 0 * * * cd /path/to/Nija && python analyze_profitability.py >> logs/profitability.log 2>&1

Manual Checks

Run the analyzer:

Integration with Bot

You can integrate profitability checks into the main bot:

from analyze_profitability import ProfitabilityAnalyzer

# In your main bot loop
analyzer = ProfitabilityAnalyzer()
trades = analyzer.load_trades()
stats = analyzer.calculate_stats(trades)

if stats.total_pnl < 0:
    logger.warning(f"⚠️ Bot is losing money: ${stats.total_pnl:.2f}")
    # Take action: reduce position size, tighten filters, etc.

Exit Codes

The script returns different exit codes for automation:

Use in scripts:

if python analyze_profitability.py; then
    echo "Bot is profitable, continue trading"
else
    echo "Bot is losing, review needed"
    # Send alert, stop bot, etc.
fi

Data Sources

The analyzer checks:

  1. SQLite Database: data/trade_ledger.db (completed_trades table)
  2. JSON File: data/trade_history.json (legacy format)

Duplicate trades are automatically removed (database takes priority).

Troubleshooting

“No Completed Trades Found”

This means:

Solution: Wait for positions to close or check profit-taking configuration

“Cannot Load Database”

Solution: Ensure data/trade_ledger.db exists and is not corrupted

“Incorrect P&L Calculations”

Solution: Verify that entry/exit fees are being tracked correctly

Support

For issues or questions:

  1. Check trade ledger integrity: python -c "import sqlite3; conn = sqlite3.connect('data/trade_ledger.db'); cursor = conn.cursor(); cursor.execute('SELECT COUNT(*) FROM completed_trades'); print(f'Completed trades: {cursor.fetchone()[0]}')"
  2. Review bot logs for trade execution errors
  3. Verify profit-taking is configured correctly

Remember: The goal is for NIJA to make MORE profit than losses. This tool helps you quickly determine if that’s happening and what actions to take if it’s not.