Strategy · Pine Script v4 · On the chart

Buurmans Tutorial

by hasnocool· code credited to Je_Buurman September 1st 2020

This educational strategy executes trades based on specific days of the week, entering long on a chosen weekday (Monday, Tuesday, or Wednesday) and closing or reversing to short on Friday.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code47
Settings9inputs
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

47 lines of Pine Script v4 from Buurmans Tutorial.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Buurmans Tutorial.pine
// © Je_Buurman September 1st 2020
// PhaseIII-b update Oct. 3rd 2020
//@version=4
strategy("Buurmans Tutorial", overlay=true, initial_capital=1000, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_value=0.2)
// Some initial inputs, these are needed in case the strategy returns an error of "too many trades; > 3000" 
Year        = input(defval = 2020, title = "From Year", minval = 2010)
Month       = input(defval = 1, title = "From Month", minval = 1, maxval=12)
Day         = input(defval = 1, title = "From Day", minval = 1, maxval=31)
LongOnly    = input(true, title="Only go Long?")
// Phase I - the initial "Strategy" - buy Monday, sell Friday
entryday_input  = input(title="Enter on which day?", defval="Monday", options=["Monday", "Tuesday", "Wetnessday"])
entryday        = if (entryday_input=="Monday")
    dayofweek.monday
else if (entryday_input=="Tuesday")
    dayofweek.tuesday
else if (entryday_input=="Wetnessday")
    dayofweek.wednesday
longCondition   = dayofweek==entryday and (time > timestamp(Year, Month, Day, 00, 00, 00))
shortCondition  = dayofweek==dayofweek.friday and (time > timestamp(Year, Month, Day, 23, 59, 59))
// Phase II - some rudimentary "risk-management" e.g. stoploss
Use_stoploss    = input(true, title="Use stoploss ?")
stoploss_input  = input(2.9, title="Stoploss in $", step=0.1)
Stoploss        = Use_stoploss ? strategy.position_size>0 ? iff(strategy.position_size>0,strategy.position_avg_price - stoploss_input, na) : strategy.position_size<0 ? iff(strategy.position_size<0,strategy.position_avg_price + stoploss_input, na) : na : na
plot(Use_stoploss and strategy.position_size!=0 ? Stoploss : na, color=iff(Stoploss!=na,color.silver, color.red),style=plot.style_linebr)
// Phase III - make it more profitable by trying to filter conditions
// only buy on odd Mondays ? only buy on full moon Mondays ? something else entirely ? Maybe change the days ?
// Phase III-b
// make a Take Profit entry, note how this is basically the same as a stoploss, just opposite
Use_takeprofit  = input(true, title="Take Profit ?")
takeprofit_input= input(5.9, title="Stoploss in $", step=0.1)
TakeProfit      = Use_takeprofit ? strategy.position_size>0 ? iff(strategy.position_size>0,strategy.position_avg_price + takeprofit_input, na) : strategy.position_size<0 ? iff(strategy.position_size<0,strategy.position_avg_price - takeprofit_input, na) : na : na
plot(Use_takeprofit and strategy.position_size!=0 ? TakeProfit : na, color=iff(TakeProfit!=na,color.silver, color.green),style=plot.style_linebr)
// The actual trades, going Long, close Long, going Short and Stoploss
if (longCondition)
    strategy.entry("Buy on Monday", strategy.long)
    
if (shortCondition and LongOnly==false)
    strategy.entry("Short on Friday", strategy.short)
if (shortCondition and LongOnly)
    strategy.close("Buy on Monday", comment="Sell on Friday")
if (Use_takeprofit and high > TakeProfit)
    strategy.close("Buy on Monday", comment="Long Took Profit on some day")
if (low < Stoploss)
    strategy.close("Buy on Monday", comment="Long Stopped on some day")
if (high > Stoploss)
    strategy.close("Short on Friday", comment="Short Stopped on some day")
Expand (66 lines)

Overview

Buurmans Tutorial plots dynamic stop loss and take profit price levels directly on the main chart. Exits occur at the end of the week or when price breaches the fixed dollar stop loss or take profit thresholds. Key settings adjust the entry day, date filter, long-only mode, and dollar-based risk limits.

Details

Published by

hasnocool on GitHub

Code credit

Je_Buurman September 1st 2020, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Sessions & time

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • 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
From Yearint2020Year
From Monthint1Month
From Dayint1Day
Only go Long?booltrueLongOnly
Enter on which day?stringMondayentryday_input
Use stoploss ?booltrueUse_stoploss
Stoploss in $float2.9stoploss_input
Take Profit ?booltrueUse_takeprofit
Stoploss in $float5.9takeprofit_input
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

361 stars

Forven S01512 — Monday Drift is a calendar-based long trading strategy designed to exploit time-based recurring market patterns. It tracks UTC calendar days and hours to enter a long position at a specified day and hour, holding it for a fixed duration until a

Strategy v6 Sessions & time
Updated today · AGPL-3.0 GitHub repository of Forven S01512 - Monday Drift

This overlay strategy offers two selectable entry modes: a Bollinger squeeze on typical price and a simple moving-average cross. It filters trades by weekday, session, date range, and an optional news window, and can restrict direction or invert the side. Risk

Strategy v5 Volatility & bandsMoving averages
Updated today · None stated GitHub repository of Boilerplate Configurable Strategy [Yosiet]
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

Daily Bias + FVG Strategy

by TradersPost
218 stars

This overlay strategy plots previous-day high and low, the daily open, and fair value gap zones on the price chart. It takes entries on a selectable timeframe when the FVG requirement and an optional session window allow them, then uses an ATR or fixed pip sto

Strategy v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Daily Bias + FVG Strategy
53 stars

This strategy enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low. A tim

Strategy v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of BTCUSD 5M Optimized Strategy

ATOM 1m scalp HK

by dearvn
43 stars

This overlay strategy targets one-minute ATOM scalps. It tracks pivot highs and lows as resistance and support, compares a three-period EMA with a multi-stage smoothed close, and flags long or short when price crosses that curve in the matching direction. Dail

Strategy v5 ScalpingSupport & resistance Repaints
Updated 2 years ago · None stated GitHub repository of ATOM 1m scalp HK

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