Strategy · Pine Script v5 · On the chart

Buy/Sell Strat

by hasnocool

This strategy plots a fast and a slow exponential moving average on the price chart and trades their crossovers.

View on GitHub

Repaints

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code30
Settings4inputs
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

30 lines of Pine Script v5 from Buy-Sell Strat.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Buy-Sell Strat.pine
//@version=5
//Author: shuby1569
strategy("Buy/Sell Strat", overlay = true, default_qty_value=100, default_qty_type=strategy.fixed)
fastSourceInput = input(close, "Fast EMA Source")
fastLengthInput = input(9, "Fast EMA Length")
slowSourceInput = input(close, "Slow EMA Source")
slowLengthInput = input(21, "Slow EMA Length")
a = ta.ema(fastSourceInput, fastLengthInput)
b = ta.ema(slowSourceInput, slowLengthInput)
crossUp = ta.crossover(a, b)
crossDown = ta.crossunder(a, b)
close_condition_long = close < a
close_condition_short = close > a
float volAvg = 0
for i = 1 to 5
    volAvg := volAvg + volume[i]
volAvg := volAvg / 5
if (crossUp)
    strategy.entry("long", strategy.long, when = ((volume * 0.85) > volAvg and close > a))
    
if (crossDown)
    strategy.entry("short", strategy.short, when = ((volume * 0.85) > volAvg and close < a))
    
if (close_condition_long)
    strategy.close("long")
if (close_condition_short)
    strategy.close("short")
plot(a, title = "Fast EMA", color = color.green)
plot(b, title = "Slow EMA", color = color.blue)
Expand (36 lines)

Overview

Buy/Sell Strat enters long when the fast average crosses above the slow average, volume is above 85 percent of the prior five-bar average, and price is above the fast average. It enters short on the opposite cross with the same volume filter. It closes a long when price falls below the fast average and closes a short when price rises above it. Order size is a fixed quantity of 100. There is no stop loss, and signals can change on the live bar.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Volume

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
Fast EMA SourcesourceclosefastSourceInput
Fast EMA Lengthint9fastLengthInput
Slow EMA SourcesourcecloseslowSourceInput
Slow EMA Lengthint21slowLengthInput
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

218 stars

This strategy enters long when a faster moving average crosses above a slower one and short when it crosses below, unless long-only mode is on. An optional volume filter requires volume above a 20-bar average times a multiplier. Exits use a percentage stop los

Strategy v6 TrendMoving averages
Updated 3 months ago · None stated GitHub repository of MA Cross Strategy Template

This strategy enters long or short when eight conditions align over the last two bars. It requires EMA 10 and EMA 55 alignment on the one-hour, four-hour and daily charts, a positive ADX slope, matching monitor direction, and price relative to a 400-bar point

Strategy v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard ABCBitcoin TradingLatino B002
12 stars

This strategy enters long when a fast EMA crosses above a slow EMA and RSI, ADX, and volume all clear their thresholds. It sizes the order from a percentage of equity and an ATR stop distance, then sets a partial profit target at a multiple of that risk. After

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of BTC 4H Institutional Trend
8 stars

This overlay strategy combines three distinct SuperTrend levels with multiple moving averages and volume profile analytics on the main price chart. It calculates trend directions using three configurable ATR periods and multipliers alongside SMA, EMA, and HMA

Strategy v5 TrendVolatility & bands
Updated 4 years ago · None stated GitHub repository of ATR 3Lvls VP Strategy

This strategy calculates trade signals by evaluating a daily session Volume Weighted Average Price relative to 90-period Exponential Moving Averages requested from 1-day and 4-hour higher timeframes. Long and short entries occur when VWAP crosses over or under

Strategy v5 Moving averagesTrend Repaints
Updated 3 years ago · MIT GitHub repository of 1D Bullish Buy 4H Bearish Sell Session EMA

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