UPSTOX · NEXUS

algorithmic trading core | realtime options engine
Open Source Multi-TF ATR Trail Dry-Run MACD EMA WS V3
Core Config Strategies Workflow Risk Tech

System Core

Autonomous Upstox algo engine for NSE options. Real-time ticks → multi-frame candles → indicators → execution.

5 Timeframes
1m · 3m · 5m · 10m · 15m
Indicators
ATR, MACD, EMA, RSI, ADX, BB
Trailing Stop
ATR-based dynamic
Risk Controls
2% risk/trade
# clone & install
git clone https://github.com/Omega-Xi/Algo-Trading.git
cd Algo-Trading
pip install -r requirements.txt
python main.py --dry-run
SIMULATION ACTIVE  |  Kill switch ready

Engine Config

ParameterValueImpact
DRY_RUNTruePaper trading
INTERVALS1,3,5,10,15Candle granularity
ATR_MULTIPLIER1.5Stop distance
RISK_PERCENT2.0%Risk per trade
R_TO_R_RATIO2.0Risk:Reward
ENTRY_COOLDOWN30sAnti-spam
STRATEGY_MAP = {
  "MACD EMA": macd_ema_strategy,      # ← ACTIVE
  "MACD RSI": macd_rsi_strategy,
  "Golden Strategy": golden_strategy,
  "Bollinger RSI": bollinger_rsi_mean_reversion
}
Current Active: MACD EMA — Trend-following with EMA smoothing

Strategy Vault

MACD EMA ★ ACTIVE
MACD+EMA200
MACD+RSI
MACD+ADX
VWAP+RSI
Bollinger+RSI
DI+/DI- ADX
Golden Strategy
MACD EMA Strategy — Combines MACD crossover with EMA smoothing for reduced noise and better trend identification.

Risk Engine

Position Sizing
Q = (M × R%) / (E - T)
margin * risk / (entry - trigger)
Trailing Stop
max(SL, high - ATR*1.5)
def update_stop_loss(self):
    new_sl = calc_trigger_price(atr, self.highest_price)
    self.trigger_price = max(self.trigger_price, new_sl)
    # modify Upstox order

Margin verified pre-entry: get_margin()

Trade Cycle

Auth & Preload
WS Connected
aggregate_candles()
MACD EMA Signal → ENTER
Monitor / Trail SL
Exit (SL/Target)

Exit Logic

Stop Loss: LTP ≤ trigger_price
Target Hit: LTP ≥ exit_price
Trailing: dynamic SL locks profits
if ltp <= self.trigger_price:
    self.exit_position()
    self.transcriber.record_exit(ltp, "STOPLOSS_HIT")

Data Pipeline

Historic 5d Tick→Candle Indicators
self.tick_buffer.append({"timestamp": ts, "price": ltp})
df.resample('1min').agg({'price': 'ohlc'})

ATR, MACD, EMA, RSI, ADX, Bollinger Bands injected into candle_df

Concurrency & Alerts

threading.Lock() atomic entry/exit

  • 🔐 entry_lock → prevents overlapping signals
  • 🔐 exit_lock → race‑free trailing
if self.exit_lock.acquire(blocking=False):
    try: check_exit_conditions()
    finally: self.exit_lock.release()
Alerts: WS connect/error, trade events, generic errors

Ready to deploy your own trading bot?

Star the repository, fork it, and start trading with our battle-tested MACD EMA strategy.

⭐ Star on GitHub Fork & Contribute MIT License
GitHub
Core Config Strat Flow Risk Tech