0bps

Strategy vault / Trend following

Heikin Ashi Trend

This script: Adds a Heikin-Ashi line to the chart (EMA-based). Provides alerts triggered when the color goes from green to red and vice versa. Just add the indicator to the chart, create an alert and select…

Author
ChaoZhang
Complexity
Starter · 42 lines
Parameters
3
Backtest bar
4h · intraday
Tested on
BTC/USDT · futures

This script: Adds a Heikin-Ashi line to the chart (EMA-based). Provides alerts triggered when the color goes from green to red and vice versa.

Just add the indicator to the chart, create an alert and select "Heikin-Ashi Trend Alert" from the dropdown. Profit.

backtest

IMG

Parameters

NameDefaultWhat it controls
v_input_int_177EMA
v_input_int_221EMA Smoothing
v_input_1false(?DEVELOPER)Show debug info

Source Pine Script

/*backtest
start: 2021-05-08 00:00:00
end: 2022-05-07 23:59:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © backslash-f
//
// This script:
// - Adds a Heikin-Ashi line to the chart (EMA-based).
// - Provides alerts triggered when the color goes from green to red and vice versa.

//@version=5
indicator("Heikin-Ashi Trend Alert", overlay=true)

// EMA
ema_input                   = input.int(title="EMA", defval=77, minval=1)
ema_smoothing               = input.int(title="EMA Smoothing", defval=21, minval=1)
ema_open                    = ta.ema(open, ema_input)
ema_close                   = ta.ema(close, ema_input)

// Developer
shouldShowDebugInfo         = input(title="Show debug info", group="DEVELOPER", defval=false, tooltip="Check this box to see the values of the main variables on the chart, below bars. This is for debugging purposes only.")

// Heikin-Ashi
heikinashi                  = ticker.heikinashi(syminfo.tickerid)
heikinashi_open             = request.security(heikinashi, timeframe.period, ema_open)
heikinashi_close            = request.security(heikinashi, timeframe.period, ema_close)
heikinashi_open_smooth      = ta.ema(heikinashi_open, ema_smoothing)
heikinashi_close_smooth     = ta.ema(heikinashi_close, ema_smoothing)

// Trend
var trend                   = false
var last_trend              = trend
trend                       := heikinashi_close_smooth >= heikinashi_open_smooth
if trend
    strategy.entry("Enter Long", strategy.long)
else
    strategy.entry("Enter Short", strategy.short)

Published by ChaoZhang on the FMZ strategy square · last modified 2022-05-09. 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/Heikin-Ashi-Trend.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