Strategy · Pine Script v5 · On the chart

Stochastic and CMF Strategy

by jawauntb

This strategy combines the Stochastic Oscillator with Chaikin Money Flow (CMF) to generate trading signals on the price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code38
Settings4inputs
LicenceGPL-3.0
Last update2 years ago22 May 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

38 lines of Pine Script v5 from stochastic-and-chaikin-money-flow-strat.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

stochastic-and-chaikin-money-flow-strat.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jawauntb

//@version=5
strategy("Stochastic and CMF Strategy", overlay=true)

// Stochastic Indicator
periodK = input.int(20, " %K Length", minval=1)
smoothK = input.int(1, "%K Smoothing", minval=1)
periodD = input.int(3, "%D Smoothing", minval=1)
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)

// Chaikin Money Flow Indicator
length = input.int(10, "Length", minval=1)
ad = close == high and close == low or high == low ? 0 : ((2 * close - low - high) / (high - low)) * volume

sumAd = 0.0
sumVolume = 0.0
for i = 0 to length - 1
    sumAd := sumAd + ad[i]
    sumVolume := sumVolume + volume[i]

mf = sumAd / sumVolume

// Define conditions for entering a long or short position
enterLong = ta.crossover(k, d) and mf > 0.1
enterShort = ta.crossunder(k, d) and mf < 0.08

// Define conditions for exiting a position
exitLong = ta.crossunder(k, d) and mf < -0.1
exitShort = ta.crossover(k, d) and mf > 0.06

// Execute trades based on the conditions
strategy.entry("Long", strategy.long, when=enterLong)
strategy.close("Long", when=exitLong)
strategy.entry("Short", strategy.short, when=enterShort)
strategy.close("Short", when=exitShort)

Overview

Stochastic and CMF Strategy enters long positions when the Stochastic %K line crosses above the %D line while CMF is above 0.1, and enters short positions on a downward crossover when CMF is below 0.08. Positions are closed based on inverse Stochastic crossovers filtered by specific CMF threshold values. Inputs allow customization of Stochastic period parameters and CMF length. The strategy relies entirely on signal condition exits and does not include a stop loss.

Details

Published by

jawauntb on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Volume

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
%K Lengthint20periodK
%K Smoothingint1smoothK
%D Smoothingint3periodD
Lengthint10length
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

106 stars

This strategy enters long on an outside bar when the candle is bullish, the Klinger Volume Oscillator is positive, and price is above a Hull moving average. It enters short on an inside bar when the candle is bearish, the oscillator is negative, and price is b

Strategy v4 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of Advanced OutSide Forex strategy
105 stars

This overlay strategy looks for gold scalps from break of structure and change of character. It enters long when a bullish break, a bullish character change, and an optional volume filter align, and short on the opposite set. Optional RSI levels can block trad

Strategy v6 SMC / ICT / price actionOscillators & momentum Repaints

CombinedBinHAndClucV8

by viktors1982
36 stars

This strategy trades on the price chart using multiple indicators. It enters long positions when price dips meet conditions on Bollinger Bands 40 and 20, RSI, MFI, volume and other thresholds. It exits at custom ROI profit levels based on RSI or after timeout

Strategy v4 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · None stated GitHub repository of CombinedBinHAndClucV8
13 stars

The Ruckard Cuneyt OBVRSI A002 strategy combines On-Balance Volume (OBV) and Relative Strength Index (RSI) thresholds to generate trade entries, DCA rebuys, and exits. Built primarily for crypto automation via Zignaly webhooks, it opens positions when OBV RSI

Strategy v5 Oscillators & momentumVolume
Updated 1 year ago · None stated GitHub repository of Ruckard Cuneyt OBVRSI A002
12 stars

This strategy plots on the price chart and looks for three-candle fair value gaps and inverse gaps on Bitcoin. It enters long when a wide enough bullish gap appears in an uptrend with RSI above 30 and volume above its average, and short on the opposite bearish

Strategy v6 SMC / ICT / price actionTrend Repaints
Updated 4 months ago · None stated GitHub repository of BTC 4h FVG/iFVG Strategy

Combined Strategy

by Dropio12
7 stars

This strategy plots buy and sell markers on the price chart by combining a fast and slow ALMA crossover with a simple close-to-close momentum check. A long marker appears when the fast ALMA crosses above the slow ALMA and momentum is positive. A short marker a

Strategy v5 TrendOscillators & momentum
Updated 2 years ago · None stated GitHub repository of Combined Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers