Trading strategies to backtest: shipped, rule-based or written as specs

Start from one of eleven shipped strategies for NIFTY, BANK NIFTY and SENSEX options and MCX gold futures, write entry rules from 24 indicator series, or describe a whole strategy as data. Every one plugs into the same harness, with the same fills, charges, exits and risk limits.

Three ways to plug a strategy in

However a strategy is written, it does one thing: read closed candles and return the positions it wants. The harness does everything else.
  1. Pick a shipped strategy

    Eleven strategies with tested defaults. Change any setting, or sweep several at once.

  2. Write indicator rules

    Name the indicators you need and compare them with the close, each other or a number.

  3. Describe it as a spec

    The whole strategy as data: entries, legs, exits, risk, day rules and costs, checked before it runs.

  • Market data

    One-minute bars, checked as they arrive and resampled to your candle.

    flux.data
  • Expiries and contracts

    Expiry calendars with holidays, and strikes picked from the closed candle.

    flux.options
  • Fills

    Every order fills at the next bar’s open, never on a price already seen.

    flux.execution
  • Costs

    Brokerage, STT or CTT, exchange and SEBI fees, stamp duty, GST and slippage.

    flux.trading.charges
  • Exits

    Stops, targets, trails and exits before expiry, checked on every bar.

    flux.trading.exits
  • Risk limits

    Lot caps, cash, futures margin, loss at expiry and daily limits.

    flux.trading.risk
  • Portfolio

    Positions in units, cash, cost basis and equity, in exact decimals.

    flux.domain.portfolio
  • Reports and runs

    Calendar, equity, breakdowns and trades, with every run stored.

    flux.api.runs

Plugs in

Your strategy

Reads closed candles and returns the position it wants, in signed lots. It never places an order or touches cash.

  • A shipped strategy
  • Your own indicator rules
  • A strategy spec, written as data

Backtests today. Paper and live trading are coming soon.

The harness: everything around the strategy is supplied by Veloce, the same way on every run.

Index options, selling premium

Defined-risk structures that sell time value: the wings are bought first, so every sold leg is hedged from the moment it opens.
  • Iron condor

    iron-condor

    Once per expiry, at the entry time, sells a put and a call a set number of strikes either side of the at-the-money strike and buys wings further out.

    Candle
    1 minute
    Defaults
    Entry 10:00Short strikes 4 steps outWings 4 steps widerAt least 5 days to expiry
    Exits
    Take profit at 50% of the credit, stop at 2× the credit, exit 1 day before expiry
  • Hedged straddle

    straddle-seller

    Each morning sells the at-the-money call and put and buys a call and a put a set number of strikes away, then closes everything at the square-off time.

    Candle
    1 minute
    Defaults
    Entry 09:20Square-off 15:15Wings 4 steps outTrades on expiry day too
    Exits
    Each sold leg is bought back if it loses 30% of its premium
  • MACD credit spread

    macd-seller

    On a MACD and 200-period trend signal, sells a put spread when bullish or a call spread when bearish, and flips the spread when the signal reverses.

    Candle
    5 minutes
    Defaults
    MACD 12, 26, 9Trend 200Short strike 2 steps outWing 4 steps wider
    Exits
    Take profit at 50% of the credit, stop at 1× the credit, exit 1 day before expiry

Index options, buying on a signal

Indicator signals on the index, traded by buying a call on a bullish signal and a put on a bearish one, one contract at a time.
  • Moving average crossover

    sma-buyer

    Buys a call when the fast simple moving average crosses above the slow one and a put when it crosses below, holding one contract at a time.

    Candle
    3 minutes
    Defaults
    Fast 9, slow 21At-the-money strikeEntries 09:15 to 15:00Square-off 15:15
    Exits
    Opposite signal or square-off; optional stop, target and trailing stop
  • EMA crossover

    ema-buyer

    The same as the moving average crossover, on exponential moving averages.

    Candle
    5 minutes
    Defaults
    Fast 9, slow 21At-the-money strikeEntries 09:15 to 15:00Square-off 15:15
    Exits
    Opposite signal or square-off; optional stop, target and trailing stop
  • MACD with a 200 trend filter

    macd-buyer

    Buys calls when the MACD histogram turns positive above a 200-period average, and puts when it turns negative below it.

    Candle
    3 minutes
    Defaults
    MACD 12, 26, 9Trend 200At-the-money strikeSquare-off 15:15
    Exits
    Opposite signal or square-off; optional stop, target and trailing stop
  • Supertrend flip

    supertrend-buyer

    Buys a call when the Supertrend turns up and a put when it turns down.

    Candle
    5 minutes
    Defaults
    ATR period 10Multiplier 3At-the-money strikeSquare-off 15:15
    Exits
    Opposite signal or square-off; optional stop, target and trailing stop
  • RSI reversal

    rsi-buyer

    Buys a call when RSI climbs back above the oversold level and a put when it falls back below the overbought level.

    Candle
    5 minutes
    Defaults
    RSI 14Oversold 30Overbought 70Square-off 15:15
    Exits
    Opposite signal or square-off; optional stop, target and trailing stop
  • Opening range breakout

    orb-buyer

    Marks the high and low of the first minutes of the session, then buys a call on a close above the range or a put on a close below it.

    Candle
    5 minutes
    Defaults
    Range 15 minutesOne breakout a dayAt-the-money strikeSquare-off 15:15
    Exits
    Opposite breakout or square-off; optional stop, target and trailing stop
  • Options on your own rules

    rule-buyer

    Buys calls when your bullish conditions all hold and puts when your bearish conditions all hold, from indicators you define.

    Candle
    5 minutes
    Defaults
    Starts from EMA 9 crossing EMA 21At-the-money strikeEntries 09:15 to 15:00Square-off 15:15
    Exits
    Opposite signal or square-off; optional stop, target and trailing stop

MCX gold futures, long and short

Your own rules on GOLD or GOLD MINI futures, reversing in one order when the signal flips, within a margin limit.
  • Gold futures on your own rules

    futures-trader

    Goes long a gold or gold mini future when your bullish conditions hold and short when your bearish ones do, reversing in one order when the signal flips.

    Candle
    5 minutes
    Defaults
    GOLDM by defaultEntries 09:00 to 23:00Square-off 23:15Margin 10% of a lot’s value
    Exits
    Opposite signal or square-off; optional stop, target and trailing stop

Entry rules from 24 indicator series and the close

Name the indicators you need, then write conditions that compare them with each other, with the close, or with a number. A side fires when every one of its conditions holds on the same closed candle.
Price
Close
Moving averages
SMAEMAWMAHMA
Trend
SupertrendADX+DI−DI
Bands and channels
Bollinger upperBollinger lowerKeltner upperKeltner lowerDonchian upperDonchian lower
Oscillators
RSIStochastic %KStochastic %DWilliams %RCCIRate of change
Volatility
ATR
MACD
MACDMACD signalMACD histogram

Each indicator takes a period and, where it has one, a multiplier (Supertrend and the bands) or a slow period and signal smoothing (MACD). Empty settings take the indicator’s usual default.

A bullish side, as the builder stores it

Bullish
  1. fast = EMA 9crosses aboveslow = EMA 21
  2. andtrend = ADX 14above20
  3. andCloseabovebase = SMA 200

All three must hold on one closed candle. The order fills at the next candle’s open.

Comparisons a condition can make
ComparisonHolds when the left side
crosses_aboveWas at or below on the previous closed candle and is above on this one.
crosses_belowWas at or above on the previous closed candle and is below on this one.
aboveIs above on this closed candle, whatever it did before.
belowIs below on this closed candle.

Index-option signals can ignore candles that close after a cutoff time. The shipped moving average buyer uses 15:15, so the closing auction’s jump to the official close never triggers a trade.

A whole strategy, written down as data

A strategy spec says what to trade, when to enter and exit, the risk limits and the costs, as structured JSON. Veloce checks every field before a run starts, so a spec that asks for something impossible is refused with the reason, not run with a guess.

The parts of a strategy spec
FieldWhat it decidesChoices
entryWhen to openA signal (one of six named signals, or your own rules), a first and last entry time, weekdays, a signal cutoff, the fewest days to expiry, and re-entry: when flat, once a day or once per expiry
legsWhat to open on entry or a bullish signalOptions by strike (steps from the money, or the premium closest to a price) and by expiry (the nth, or the nearest at least some days away), or the underlying future; each with a side and a ratio
bearish_legsWhat to open on a bearish signalThe same choices as legs; needs a signal
square_offWhen to close each dayA time, or empty to hold overnight
exitsWhen to closeStop loss, take profit, trailing stop and exit before expiry, checked per leg or per underlying and expiry
riskLimits on new lotsLots per contract, a share of equity, gross exposure, cash, futures margin, loss at expiry and a daily loss limit
dayAccount-wide daily rulesExit by a time, a daily target and stop, and days to skip
costsFees and slippageThe NSE options or MCX futures schedule, or your own fees and taxes; slippage in ticks or as a share of price
iron-condor.jsonStrategy spec
{
  "name": "iron-condor",
  "description": "sell weekly iron condors",
  "candle_minutes": 1,
  "entry": {
    "first_entry": "10:00",
    "min_days_to_expiry": 5,
    "reenter": "each_expiry"
  },
  "legs": [
    {
      "kind": "option",
      "option_type": "put",
      "side": "buy",
      "strike": {
        "kind": "atm_offset",
        "steps": 8
      }
    },
    {
      "kind": "option",
      "option_type": "call",
      "side": "buy",
      "strike": {
        "kind": "atm_offset",
        "steps": 8
      }
    },
    {
      "kind": "option",
      "option_type": "put",
      "side": "sell",
      "strike": {
        "kind": "atm_offset",
        "steps": 4
      }
    },
    {
      "kind": "option",
      "option_type": "call",
      "side": "sell",
      "strike": {
        "kind": "atm_offset",
        "steps": 4
      }
    }
  ],
  "exits": {
    "group_by": "expiry",
    "rules": [
      {
        "kind": "take_profit",
        "amount": {
          "kind": "share_of_credit",
          "fraction": "0.5"
        }
      },
      {
        "kind": "stop_loss",
        "amount": {
          "kind": "share_of_credit",
          "fraction": "2"
        }
      },
      {
        "kind": "before_expiry",
        "days": 1
      }
    ]
  }
}
The shipped iron condor: wings 8 strikes out bought first, shorts 4 strikes out, one entry per expiry from 10:00 with at least 5 days left, and exits on the four legs together.
futures-trader.jsonStrategy spec
{
  "name": "futures-trader",
  "description": "trade MCX gold futures long and short on your own rules",
  "entry": {
    "signal": {
      "kind": "rules",
      "indicators": [
        {
          "name": "fast",
          "kind": "ema",
          "period": 9
        },
        {
          "name": "slow",
          "kind": "ema",
          "period": 21
        }
      ],
      "bullish": [
        {
          "left": "fast",
          "comparison": "crosses_above",
          "right": "slow"
        }
      ],
      "bearish": [
        {
          "left": "fast",
          "comparison": "crosses_below",
          "right": "slow"
        }
      ]
    },
    "first_entry": "09:00",
    "last_entry": "23:00"
  },
  "legs": [
    {
      "kind": "underlying",
      "side": "buy"
    }
  ],
  "bearish_legs": [
    {
      "kind": "underlying",
      "side": "sell"
    }
  ],
  "square_off": "23:15",
  "risk": {
    "rules": [
      {
        "kind": "futures_margin"
      }
    ]
  },
  "costs": {
    "charges": [
      {
        "kind": "mcx_futures"
      }
    ]
  }
}
The gold futures strategy: an EMA 9 and 21 cross decides long or short, entries from 09:00 to 23:00, square-off at 23:15, a margin limit and the MCX futures charges.

What the checks catch

  • A strategy with no legs at all, or bearish legs without a signal to open them.
  • A first entry after the last entry, or a last entry at or after the square-off.
  • A signal cutoff without a signal, and repeated or missing weekdays.
  • Numbers out of range, such as a strike more than 50 steps from the money.

Fields left out take their defaults: a 5-minute candle, one lot a leg, the nearest expiry, the at-the-money strike, the NSE options schedule and one tick of slippage at the next open.

Strategy questions

Do I need to write code to backtest a strategy in Veloce?

No. You can run one of the eleven shipped strategies with your own settings, build entry conditions from indicators, or describe a whole strategy as a spec, which is structured data rather than code.

Which indicators can the rule builder use?

The close and 24 indicator series: SMA, EMA, WMA and HMA; Supertrend, ADX and the two directional indicators; Bollinger, Keltner and Donchian upper and lower bands; RSI, stochastic %K and %D, Williams %R, CCI and rate of change; ATR; and MACD with its signal line and histogram.

When does a rule-based strategy enter?

When every condition on one side holds on the same closed candle, inside the entry window. The order then fills at the open of the next candle, so a signal never trades on the price that produced it.

Can a strategy trade both calls and puts?

Yes. A strategy has legs for a bullish signal and bearish legs for a bearish one. The option buyers buy a call on a bullish signal and a put on a bearish one, and the gold futures strategy goes long or short.

Will the same strategy run in live trading?

That is the design: strategies only return the positions they want, so the same code can run against a live broker with the data and order executor swapped. Paper and live trading are coming soon.

Backtest a strategy on your own settings

Create an account with a verified email and phone number, pick a strategy and a market, and see every fill, fee and day of P&L.

Create account
esc
↑↓Move↵Open