Strategy · Pine Script v4 · On the chart

Greeffer's Long Strategy

by modster

Plots Donchian Channels and identifies trading setups based on price testing the channel extremes during high volume spikes.

View on GitHub

GitHub stars3on the repository
Pine versionv4older, still runs
Lines of code91
Settings7inputs
LicenceCC0-1.0
Last update4 years ago16 Mar 2022

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

91 lines of Pine Script v4 from leobot/strategy.pine, published under CC0-1.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// Greeffer's Long Strategy
// Tuned for the 5 minute time frame
// 40x leverage using 10% of equity per trade by default
// @version=4
// @Greeffer

// S T U D Y
// study(shorttitle="Long Study", title="Greeffer's Long Study", overlay=true)

// S T R A T E G Y 
strategy(
     "Greeffer's Long Strategy",
     "Long Strategy",
     overlay=true, 
     pyramiding=10,
     default_qty_type=strategy.percent_of_equity,
     default_qty_value=400,
     initial_capital=50,
     commission_type=strategy.commission.percent,
     commission_value=0.01,
     margin_long=1./40*50, 
     margin_short=1./40*50
     )

// I N P U T S
//sma = input(title="sma", type=input.integer, defval=250)
longOrShort = input(title="Long", type=input.bool, defval=true, tooltip="Uncheck to Short")
amount = input(title="amount", type=input.float, defval=0.001, step=0.001)
volumeMA = input(title="volume ma period", type=input.integer, defval=200)
volMultiplyer = input(title="volume multiplyer", type=input.integer, defval=3)
donchianupper = input(title="upper donchian channel period", type=input.integer, defval=1440)
donchianlower = input(title="lower donchian channel period", type=input.integer, defval=1440)
stops = input(title="stops", type=input.float, defval=500.00, step=0.01)

// V A R S
symbol = "BTCUSDT"
short = false
long = false
stopshort = close + stops
stoplong = close - stops

// to do:
//symbol = syminfo.ticker

// D O N C H I A N   C H A N N E L S
lower = lowest(donchianlower)
upper = highest(donchianupper)
middle= (upper-lower)/2+lower
plot(middle, title='Middle', color=color.green, linewidth=1)
plot(upper, title='Upper', color=color.orange, linewidth=1)
plot(lower, title='Lower', color=color.orange, linewidth=1)

// S M A
//plot(sma(close,sma))

// V O L U M E
volMA = sma(volume, 200)
//upperVol = highest(volume, 200)
upperVol = volMA*volMultiplyer

// E N T R Y / E X I T   C o n d i t i o n s 
// S h o r t
if high>=upper and volume>upperVol
    short:=true
else 
    short:=false

// L o n g :
if low<=lower and volume>upperVol
    long:=true
else
    long:=false

// O R D E R S :
// L o n g
if long==true and longOrShort==true
    //alert(message='{"side":"limitBuy","limit":"'+tostring(lower)+'","stopPrice":"'+tostring(stoplong)+'","symbol":"'+symbol+'","close":"'+tostring(close)+'","amount":"'+tostring(amount)+'"}', freq=alert.freq_once_per_bar_close)
    strategy.order("long", long=true, limit=lower, oca_name="order", stop=stoplong, comment="long", when=long)

if short==true and longOrShort==true
    //alert(message='{"side":"closeLong","stopPrice":"'+tostring(upper[3])+'","symbol":"'+symbol+'","close":"'+tostring(close)+'","amount":"'+tostring(amount)+'"}', freq=alert.freq_once_per_bar_close)
    strategy.close("long", comment="close-long", qty_percent=100, when=short)

// S h o r t
if short==true and longOrShort==false
    //alert(message='{"side":"limitSell","limit":"'+tostring(upper)+'","stopPrice":"'+tostring(stopshort)+'","symbol":"'+symbol+'","close":"'+tostring(close)+'","amount":"'+tostring(amount)+'"}', freq=alert.freq_once_per_bar_close)
    strategy.order("short", long=false, limit=upper, oca_name="order", stop=stopshort, comment="short", when=short)

if long==true and longOrShort==false
    //alert(message='{"side":"closeShort","stopPrice":"'+tostring(lower[3])+'","symbol":"'+symbol+'","close":"'+tostring(close)+'","amount":"'+tostring(amount)+'"}', freq=alert.freq_once_per_bar_close)
    strategy.close("short", comment="close-short", qty_percent=100, when=long)

Overview

In long mode, it places limit buy orders when the low touches the lower Donchian band with volume exceeding a volume moving average multiple, and closes positions when price reaches the upper band. Inputs allow toggling between long and short modes, configuring channel periods, and setting volume multiplier thresholds. Drawn directly on the price chart.

Details

Published by

modster on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Markets

Crypto

Timeframes

M1-M5

Risk Notes

  • The strategy can add several entries in the same direction
  • 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
LongbooltruelongOrShort
amountfloat0.001amount
volume ma periodint200volumeMA
volume multiplyerint3volMultiplyer
upper donchian channel periodint1440donchianupper
lower donchian channel periodint1440donchianlower
stopsfloat500.00stops
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

This strategy plots Bollinger Bands on the price chart using an EMA or SMA basis and a matching standard-deviation calculation. It enters long when price crosses back above the lower band and short when price crosses back below the upper band. An optional Intr

Strategy v4 Volatility & bandsMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of Bollinger Bands Strategy with Intraday Intensity Index
13 stars

This strategy runs on the price chart to identify trade entries using volume sequences, specifically tracking consecutive declining volume candles followed by a volume surge at lower price levels. It provides webhook execution support for Zignaly copy trading

Strategy v5 VolumeVolatility & bands
Updated 1 year ago · None stated GitHub repository of Ruckard Voladder A002
1 stars

This overlay strategy requires sequential confluence before it enters. A hybrid detector blends selected oscillators, including RSI, CCI, MFI, Bollinger percent B and Keltner percent K, and treats extreme overbought or oversold readings as the market regime. V

Strategy v6 Oscillators & momentumVolatility & bands
Updated 10 months ago · None stated GitHub repository of Stratégie Confluence Hybride-VMCB

Alpy Vix

by avatar-lavventura
2 stars

This strategy calculates a rolling volume-weighted average price and Chris Moody's Williams Vix Fix to detect market bottoms and oversold volatility spikes. It plots in a separate pane and colors chart bars based on filtered exhaustion criteria and price actio

Strategy v5 Volatility & bandsMean reversion Repaints
Updated 7 months ago · None stated GitHub repository of Alpy Vix

More Mean reversion scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers