0bps

Strategy vault / Mean reversion

Internal Bar Strength Indicator Reversion system

It looks like you're using Pine Script to set up a trading strategy with conditions based on the Internal Bar Strength (IBS) indicator. To explain the code: 1. Strategy Settings: The strategy defined here is named…

Pine ScriptMean reversion
Author
ChaoZhang
Complexity
Starter · 32 lines
Parameters
0
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

IMG It looks like you're using Pine Script to set up a trading strategy with conditions based on the Internal Bar Strength (IBS) indicator.

To explain the code:

  1. Strategy Settings: The strategy defined here is named "IBS", it has an initial capital of $10,000, no overlay, allows up to 5 entries in the same direction, and each trade consists of a quantity of 100 units.

  2. Calculation of IBS: The script calculates the IBS as a percentage of the current bar's range that's made up by the difference between the close and the low. Notice that the indicator ranges between 0 and 100%.

  3. Long Entry conditions: It enters a long trade when the IBS falls below 5.

  4. Short Entry conditions: It enters a short trade when the IBS rises above 99.

  5. Exit conditions: The trading strategy then exits either position after either a profit of 10% or a loss of 2%.

They have also included commented out codes (with '//') for direction.allowed for strategy risk and another shortCondition.

Note: This script indicates a mean reversion strategy. It assumes that the price will return to its mean and trades based on this assumption. However, please spend enough time testing this strategy to make sure it works well with your specific use case.

Source Pine Script

/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-07 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
// strategy("IBS", initial_capital=10000, overlay=false, pyramiding=5, default_qty_value=100, currency="USD")

//strategy.risk.allow_entry_in(strategy.direction.long)


src = close
ibs = (close - low) / (high - low) * 100

longCondition = ibs <5
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

//shortCondition = close > high[1]
shortCondition = ibs > 99
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)

p = close * 0.01 * 10
strategy.exit("exit", "My Long Entry Id",profit = 10, loss=2)
strategy.exit("exit", "My Short Entry Id",profit = 10, loss=2)


Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-08. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Internal-Bar-Strength-Indicator-Reversion-system.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open