← Back to list

Indicator Strategy Based on the Chaikin Money Flow (CMF)

CASHISKING | CASHISKING CMF, EMA, SMA

Sword Red · 2024-07-25 05:19 · 0 claps · 4.0 min read
#chaikin-money-flow #indicator-strategy #cryptocurrency #fmz-quant #source-code
Open on Medium ↗
Wiki topics: CRY · Crypto & Web3 ECO · Economy · General

Indicator Strategy Based on the Chaikin Money Flow (CMF)

CASHISKING | CASHISKING CMF, EMA, SMA

Overview

The strategy generates trading signals based on the Chaikin Money Flow (CMF) indicator and the exponential moving average (EMA). First, the CMF value within the specified period is calculated, and then the CMF data is smoothed using two EMAs of different periods. A buy signal is generated when the fast EMA crosses above the slow EMA, and vice versa, a sell signal is generated. The strategy also sets stop loss and take profit conditions to control risk and lock in profits.

Strategy Principle

  1. Calculates the Chaikin Money Flow (CMF) value for a specified period. The CMF indicator combines price and volume data to measure the strength of money inflows and outflows.
  2. The CMF data is smoothed using two exponential moving averages (EMA) of different periods, a fast EMA to capture short-term trends and a slow EMA to determine long-term trends.
  3. When the fast EMA crosses above the slow EMA, a buy signal is generated; when the fast EMA crosses below the slow EMA, a sell signal is generated.
  4. After generating a trading signal, the strategy will wait for two candlestick confirmations to avoid false signals.
  5. Set stop loss and take profit conditions. The stop loss price is a certain percentage of the opening price, and the take profit price is a certain percentage of the opening price.

Advantage Analysis

  1. Combining price and volume data: The CMF indicator comprehensively considers price and volume data, which can more comprehensively reflect the market capital flow and provide more reliable trading signals.
  2. Trend tracking: By using EMAs of different periods, the strategy is able to capture both short-term and long-term trends and adapt to different market environments.
  3. Signal confirmation: After generating a trading signal, the strategy will wait for confirmation from two K-lines, effectively filtering out some false signals and increasing the success rate of the transaction.
  4. Risk control: Setting stop-loss and take-profit conditions can effectively control the risk of a single transaction and lock in the profits already made.

Risk Analysis

  1. Parameter optimization: The performance of the strategy depends on the period selection of CMF and EMA. Different market environments may require different parameter settings, so parameter optimization is required regularly.
  2. Trend identification: In a volatile market or at a trend turning point, the strategy may generate more false signals, leading to frequent trading and capital losses.
  3. Slippage and transaction costs: Frequent trading may increase slippage and transaction costs, affecting the overall return of the strategy.

Optimization Direction

  1. Dynamically adjust parameters: According to changes in the market environment, dynamically adjust the cycle parameters of CMF and EMA to adapt to different market conditions.
  2. Introduce other indicators: Combine with other technical indicators, such as the relative strength index (RSI), average true range (ATR), etc. to improve the accuracy of trend identification and the reliability of signals.
  3. Optimize stop loss and take profit: Dynamically adjust the stop loss and take profit percentages according to market volatility and risk appetite to better control risks and lock in profits.
  4. Add position management: dynamically adjust the position size according to market trends and signal strength, increase the position when the trend is clear, and reduce the position when it is uncertain.

Summary

This strategy uses the Chaikin money flow indicator and exponential moving average, combined with price and volume data, with trend tracking as the main idea, and sets stop loss and take profit conditions to control risks. The advantage of the strategy is that it can comprehensively consider multiple factors and capture trends on different time scales, but there is still room for optimization in parameter setting and trend identification. In the future, the stability and profitability of the strategy can be further improved by dynamically adjusting parameters, introducing other indicators, optimizing stop loss and take profit, and adding position management.

Strategy source code

/*backtest
start: 2023-06-01 00:00:00
end: 2024-06-06 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("CASHISKING", overlay=false)

// Kullanıcı girişleri ile parametreler
cmfPeriod = input.int(200, "CMF Periyodu", minval=1)
emaFastPeriod = input.int(80, "Hızlı EMA Periyodu", minval=1)
emaSlowPeriod = input.int(160, "Yavaş EMA Periyodu", minval=1)
stopLossPercent = input.float(3, "Stop Loss Yüzdesi", minval=0.1) / 100
stopGainPercent = input.float(5, "Stop Gain Yüzdesi", minval=0.1) / 100

// CMF hesaplama fonksiyonu
cmfFunc(close, high, low, volume, length) =>
    clv = ((close - low) - (high - close)) / (high - low)
    valid = not na(clv) and not na(volume) and (high != low)
    clv_volume = valid ? clv * volume : na
    sum_clv_volume = ta.sma(clv_volume, length)
    sum_volume = ta.sma(volume, length)
    cmf = sum_volume != 0 ? sum_clv_volume / sum_volume : na
    cmf

// CMF değerlerini hesaplama
cmf = cmfFunc(close, high, low, volume, cmfPeriod)

// EMA hesaplamaları
emaFast = ta.ema(cmf, emaFastPeriod)
emaSlow = ta.ema(cmf, emaSlowPeriod)

// Göstergeleri çiz
plot(emaFast, color=color.blue, title="EMA 23")
plot(emaSlow, color=color.orange, title="EMA 50")

// Alım ve Satım Sinyalleri
crossOverHappened = ta.crossover(emaFast, emaSlow)
crossUnderHappened = ta.crossunder(emaFast, emaSlow)

// Kesişme sonrası bekleme sayacı
var int crossOverCount = na
var int crossUnderCount = na

if (crossOverHappened)
    crossOverCount := 0

if (crossUnderHappened)
    crossUnderCount := 0

if (not na(crossOverCount))
    crossOverCount += 1

if (not na(crossUnderCount))
    crossUnderCount += 1

// Alım ve Satım işlemleri
if (crossOverCount == 2)
    strategy.entry("Buy", strategy.long)
    crossOverCount := na  // Sayaç sıfırlanır

if (crossUnderCount == 2)
    strategy.entry("Sell", strategy.short)
    crossUnderCount := na  // Sayaç sıfırlanır

// Stop Loss ve Stop Gain hesaplama
longStopPrice = strategy.position_avg_price * (1 - stopLossPercent)
shortStopPrice = strategy.position_avg_price * (1 + stopLossPercent)
longTakeProfitPrice = strategy.position_avg_price * (1 + stopGainPercent)
shortTakeProfitPrice = strategy.position_avg_price * (1 - stopGainPercent)

// Stop Loss ve Stop Gain'i uygula
if (strategy.position_size > 0 and strategy.position_avg_price > 0)
    strategy.exit("Stop", "Buy", stop=longStopPrice, limit=longTakeProfitPrice)
else if (strategy.position_size < 0 and strategy.position_avg_price > 0)
    strategy.exit("Stop", "Sell", stop=shortStopPrice, limit=shortTakeProfitPrice)

Strategy parameters

The original address: FMZ — FMZ QUANT Trading Platform


메타데이터
post_id
7bb3efb979eb
slug
indicator-strategy-based-on-the-chaikin-money-flow-cmf-7bb3efb979eb
url
https://medium.com/@redsword_23261/indicator-strategy-based-on-the-chaikin-money-flow-cmf-7bb3efb979eb
canonical_url
https://medium.com/@redsword_23261/indicator-strategy-based-on-the-chaikin-money-flow-cmf-7bb3efb979eb
author_url
https://medium.com/@redsword_23261
status
ok
fetched_at
2026-08-07 12:54:38