Ready-to-use ChipaFlow trading strategies for various market conditions
Buy when RSI crosses up out of oversold, sell when it crosses down out of overbought
#! RSI mean reversion.
let rsi = Rsi(14);
func main(candle: Candle, ctx: Context) -> TradeAction {
if ctx.position() != 0.0 { return Hold; };
if rsi >^ 30.0 { Buy }
else if rsi <^ 70.0 { Sell }
else { Hold }
}Classic trend following: golden cross opens long, death cross opens short
#! SMA crossover with a position guard.
let fast = Sma(9);
let slow = Sma(21);
func main(candle: Candle, ctx: Context) -> TradeAction {
# One open position at a time.
if ctx.position() != 0.0 { return Hold; };
if fast >^ slow { Buy }
else if fast <^ slow { Sell }
else { Hold }
}Buy at the lower band, sell at the upper band
#! Fade the bands.
let bb = Bb(20, 2.0);
func main(candle: Candle, ctx: Context) -> TradeAction {
if ctx.position() != 0.0 { return Hold; };
if candle.close < bb.lower { Buy }
else if candle.close > bb.upper { Sell }
else { Hold }
}Only fade a band touch when RSI agrees the move is stretched
#! Band touch plus RSI agreement.
let bb = Bb(20, 2.0);
let rsi = Rsi(14);
func main(candle: Candle, ctx: Context) -> TradeAction {
if ctx.position() != 0.0 { return Hold; };
let stretched_down = candle.close < bb.lower && rsi < 30.0;
let stretched_up = candle.close > bb.upper && rsi > 70.0;
if stretched_down { Buy }
else if stretched_up { Sell }
else { Hold }
}Enter with strong rate-of-change, in the direction of the MACD histogram
#! Momentum with MACD direction filter.
let roc = Roc(10);
let macd = Macd(12, 26, 9);
func main(candle: Candle, ctx: Context) -> TradeAction {
if ctx.position() != 0.0 { return Hold; };
if roc > 1.5 && macd.histogram > 0.0 { Buy }
else if roc < -1.5 && macd.histogram < 0.0 { Sell }
else { Hold }
}SuperTrend entries; a @trade handler brackets each trade and cuts stale losers
#! SuperTrend entries, managed per-trade.
let st = SuperTrend(3.0, 10);
func main(candle: Candle, ctx: Context) -> TradeAction {
if ctx.position() != 0.0 { return Hold; };
if st.up { Buy } else { Sell }
}
@trade func manage(trade: TradeContext, c: Candle) -> TradeCommand {
if trade.stop_loss() == 0.0 {
# 0 means "unchanged", so this brackets the trade exactly once.
TradeCommand.Update {
stop_loss = trade.entry() * 0.97,
take_profit = trade.entry() * 1.05,
}
} else if trade.bars() > 12 && trade.profit() < 0.0 {
TradeCommand.Close
} else {
TradeCommand.Hold
}
}Use our AI-powered compiler to generate custom strategies or modify these examples
Try AI Compiler