Strategy · Pine Script v4 · Own pane

Stochastic

by hasnocool· code credited to slymnturkoglu

This strategy combines a smoothed stochastic oscillator with three exponential moving averages.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code29
Settings0inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 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

29 lines of Pine Script v4 from 4-Hour Stochastic EMA Trend.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

4-Hour Stochastic EMA Trend.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © slymnturkoglu
//@version=4
strategy("Stochastic")
//study(title="Stochastic", shorttitle="Stoch", format=format.price, precision=2, resolution="")
period1 = 5
period2 = 15
period3 = 50
ma1 = ema(close, period1)
ma2 = ema(close, period2)
ma3 = ema(close, period3)
periodK=13
periodD=15
smoothK=5
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)
buyCondition = crossover(k, d) and crossover(ma1, ma3) and crossover(ma2, ma3)
sellCondition = crossunder(k, d) and crossunder(ma1, ma3) and crossunder(ma2, ma3)
strategy.entry("long", strategy.long, 1000, alert_message="LongAlert", when=buyCondition)
strategy.close("long", alert_message="CloseAlert", when=sellCondition)
    
//study("Stochastic EMA Trend", overlay=false)
plot(close)
plot(ma1, color=color.blue, linewidth=3, title="EMA period 5")
plot(ma2, color=color.green,linewidth=3, title="EMA period 15")
plot(ma3, color=color.yellow,linewidth=3, title="EMA period 50")
plot(d, color=color.red,linewidth=3, title="d")
plot(k, color=color.blue,linewidth=3, title="k")
Expand (42 lines)

Overview

Stochastic opens a long position of 1000 units when the stochastic K line crosses above D and the 5-period and 15-period EMAs both cross above the 50-period EMA. It closes that long when K crosses below D and both faster EMAs cross below the slow EMA. Periods are fixed in the code, with no user inputs. It does not open shorts and has no stop loss or take profit. Plots of price, the three EMAs, K, and D appear in a separate pane.

Details

Published by

hasnocool on GitHub

Code credit

slymnturkoglu, as written in the script's header

Type

Strategy, Pine Script v4

Draws

Separate pane below the chart

Category

Trend, Oscillators & momentum, Moving averages

Markets

Any symbol

Timeframes

H4 and above

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

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

330 stars

MACD + Divergences [Alorse] is a momentum strategy that calculates the MACD oscillator and identifies regular and hidden divergences using pivot high and low points. It filters trade signals with dual Exponential Moving Averages (EMA 150 and 600) to ensure tra

Strategy v4 Oscillators & momentumDivergence Repaints
Updated 2 months ago · None stated GitHub repository of MACD + Divergences [Alorse]

MACD Crossover (tutorial)

by pineforge-4pass
193 stars

This strategy calculates the Moving Average Convergence Divergence indicator and plots the MACD line, signal line, and histogram in a separate pane. It enters long positions when the MACD line crosses above the signal line and enters short positions when it cr

Strategy v6 Oscillators & momentumMoving averages
Updated today · Apache-2.0 GitHub repository of MACD Crossover (tutorial)

EMA Ribbon MACD

by iamrichardD
57 stars

This strategy combines an EMA ribbon with MACD confirmation and plots in a separate pane. It enters when ribbon alignment, optional MACD zero or signal crosses, volume, smart-money, and multi-timeframe filters agree, then exits with percentage stop loss and ta

Strategy v6 TrendMoving averages
Updated 1 year ago · Apache-2.0 GitHub repository of EMA Ribbon MACD

This strategy evaluates the dynamic relationship between price and a chosen moving average across six diagnostic dimensions: trend, respect, extension, compression, acceleration, and exhaustion. It plots a normalized relationship oscillator bounded between -10

Strategy v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of Market–Average Relationship Engine [WavesUnchained]
7 stars

This strategy combines the Moving Average Convergence Divergence oscillator with an Exponential Moving Average trend filter. It enters long positions when the MACD histogram crosses above zero while price stays above the long-term EMA filter. Long trades close

Strategy v5 TrendOscillators & momentum
Updated 1 year ago · MPL-2.0 GitHub repository of MACD EMA Filter Strategy

MACD Signal Cross

by latentwill
4 stars

This strategy evaluates EMA momentum crossovers filtered by an RSI oscillator. It enters a long position when a fast EMA crosses above a slow EMA while RSI remains above 40. Conversely, it enters a short position when the fast EMA crosses below the slow EMA wh

Strategy v5 Moving averagesOscillators & momentum
Updated 6 days ago · None stated GitHub repository of MACD Signal Cross

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