Strategy · Pine Script v5 · On the chart

1W Bullish Buy 1D Bearish Sell Session EMA

by JackZhao516· code credited to smrti

This strategy plots a 90-period exponential moving average from the weekly and daily charts plus a daily session VWAP on the price chart.

View on GitHub

Repaints

GitHub stars7on the repository
Pine versionv5runs as is
Lines of code70
Settings0inputs
LicenceMIT
Last update3 years ago10 Jul 2023

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

70 lines of Pine Script v5 from 1w_bullish_buy_1d_bearish_sell_session_ema.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

1w_bullish_buy_1d_bearish_sell_session_ema.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © smrti

//@version=5
//initial capital 10000USDT
strategy("1w_bullish_buy_1d_bearish_sell_session_ema", overlay=true, calc_on_every_tick=true, 
 default_qty_type=strategy.percent_of_equity, default_qty_value = 100, 
 initial_capital = 10000, currency = currency.USDT, process_orders_on_close=true, 
 use_bar_magnifier = true, precision=7)
 
// timewindow
start = timestamp(2019, 1, 1, 00, 00)            // backtest start  window
end = timestamp(2022, 9, 8, 00, 00)              // backtest end  window
// start1 = timestamp(2020, 3, 11, 00, 00)            // backtest start  window
// end1 = timestamp(2020, 3, 13, 00, 00)              // backtest end  window
window = time >= start

// indicators

ma90 = ta.ema(close, 90)
ma90_1w = request.security(syminfo.tickerid, '1W', ma90)
ma90_1d = request.security(syminfo.tickerid, '1D', ma90)
vwap = ta.vwap(hlc3, timeframe.change('1D')) // session vwap

plot(ma90_1w, color=color.new(color.green, 20))
plot(vwap, color=color.new(color.blue, 20))
plot(ma90_1d, color=color.new(color.yellow, 20))

// conditional indicators
bull_1w = ta.crossover(vwap, ma90_1w)
bear_1w = ta.crossunder(vwap, ma90_1w)
bull_1d = ta.crossover(vwap, ma90_1d)
bear_1d = ta.crossunder(vwap, ma90_1d)
    
// func close_all()
close_all() =>
    if strategy.position_size > 0
        strategy.close("long", qty_percent = 100)
    if strategy.position_size < 0
        strategy.close("short", qty_percent = 100)
        
// func long()
long() =>
    close_all()
    strategy.entry("long", strategy.long)

// func short()
short() =>
    close_all()
    strategy.entry("short",  strategy.short)
        
// in 1w bull zone
if vwap >= ma90_1w and bull_1d and window
    long()
if vwap >= ma90_1w and bear_1d 
    close_all()
        
// in 1w bear zone
if vwap <= ma90_1w and bear_1d and window
    short()
if vwap <= ma90_1w and bull_1d 
    close_all()
    
// 1w bull
if bull_1w and window
    long()
    
// 1w bear
if bear_1w and window
    short()

Overview

1W Bullish Buy 1D Bearish Sell Session EMA enters long when the weekly VWAP is above the weekly average and the daily VWAP crosses above the daily average, and enters short in the opposite weekly zone on a daily crossunder. A weekly cross of VWAP through the weekly average also opens a long or short. It closes the position on the opposing daily cross. Position size is the full equity. There is no stop loss, and signals can update on the live bar.

Details

Published by

JackZhao516 on GitHub

Code credit

smrti, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Sessions & time

Markets

Any symbol

Timeframes

H4 and above

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy enters trades without a stop loss
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

257 stars

Donald - Test Logic Futures is an overlay strategy designed for intraday futures trading. It combines kernel regression functions with exponential moving averages to evaluate price retracements and entry timing. Trades are filtered by session execution windows

Strategy v5 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald - Test Logic Futures

Andean Scalping

by hasnocool
106 stars

Andean Scalping is a Pine Script v5 strategy template designed for backtesting trading signals. It features session and date-range filtering, directional trade toggles for long and short entries, and optional trend filtering tools including higher-timeframe EM

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of Andean Scalping
4 stars

This strategy trades directional momentum breakouts for crude oil on the price chart. It enters long or short positions when a fast exponential moving average crosses a slow exponential moving average, provided that current Average True Range exceeds its movin

Strategy v6 TrendMoving averages
Updated 2 months ago · MIT GitHub repository of CL Crude Oil Momentum [trugurpala]
4 stars

This strategy executes trades on 5-minute index futures using Exponential Moving Averages, RSI, ADX, and volume filters across multiple timeframes. It supports trend pullback and VWAP reversion regimes with entry confirmation on breakout of prior high or low p

Strategy v6 TrendMean reversion
Updated yesterday · None stated GitHub repository of Lucid 100K Prop Bot (MES 5m)

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