Strategy · Pine Script v5 · On the chart

4h Bullish Buy 1h Bearish Sell Session

by JackZhao516· code credited to smrti

This strategy overlays a 90-period simple moving average from the one-hour and four-hour charts with a daily session VWAP on the price chart.

View on GitHub

Repaints

GitHub stars7on the repository
Pine versionv5runs as is
Lines of code68
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

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

4h_bullish_buy_1h_bearish_sell_session.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("4h_bullish_buy_1h_bearish_sell_session", 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(2021, 10, 28, 00, 00)            // backtest start  window
end = timestamp(2022, 8, 29, 00, 00)              // backtest end  window
window = time >= start and time <= end

// indicators

ma90 = ta.sma(close, 90)
ma90_4h = request.security(syminfo.tickerid, '240', ma90)
ma90_1h = request.security(syminfo.tickerid, '60', ma90)
vwap = ta.vwap(hlc3, timeframe.change('1D')) // session vwap

plot(ma90_4h, color=color.new(color.green, 20))
plot(vwap, color=color.new(color.blue, 20))
plot(ma90_1h, color=color.new(color.yellow, 20))

// conditional indicators
bull_4h = ta.crossover(vwap, ma90_4h)
bear_4h = ta.crossunder(vwap, ma90_4h)
bull_1h = ta.crossover(vwap, ma90_1h)
bear_1h = ta.crossunder(vwap, ma90_1h)

// 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 4h bull zone
if vwap >= ma90_4h and bull_1h and window
    long()
if vwap >= ma90_4h and bear_1h
    close_all()

// in 4h bear zone
if vwap <= ma90_4h and bear_1h and window
    short()
if vwap <= ma90_4h and bull_1h
    close_all()

// 4h bull
if bull_4h and window
    long()

// 4h bear
if bear_4h and window
    short()

Overview

4h Bullish Buy 1h Bearish Sell Session buys when VWAP is at or above the four-hour average and crosses above the one-hour average, and sells short in the opposite zone. A four-hour VWAP cross also reverses the position, while an opposing one-hour cross closes it. Size is the full equity and there is no stop loss. Calculation on every tick can change the live-bar signal, and entries are limited to a fixed date window.

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

Crypto

Timeframes

M15-H1, 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