776 1 116
A basic Buy and Hold strategy, which is useful for comparing against your other strategies. You have to specify when you want the strategy to exit in the code, because the built in 'barstate.islast' and 'barstate.isrealtime' functions don't seem to work properly.

Remove from Favorite Scripts Add to Favorite Scripts
//Author: smith26
//This strategy is a simple buy and hold, which will enter Long at the beginning of price data, and exit at date specified below.  Useful for comparing against other strategies.

strategy("Buy&Hold", overlay=true)

//Set the following to desired END of your your Buy and Hold period.
yr =  year == 2016
mo = month == 09 //September
wk = weekofyear == 36 //36th week of the year
day = dayofmonth == 07 //in order for the 4hr and 1D charts to trigger, this must be at least TWO trading days ago.
lastwk = (weekofyear == 35) and yr //For Weekly charts to Close poition, set this to ONE week PRIOR to current week.
lastmo = (month == 07) and yr  //For Monthly charts to Close posotion, set this to TWO MONTHS PRIOR to current month.
today = yr and mo and day
thisweek = yr and wk
thismonth = yr and mo

longCondition = barstate.isfirst

sell1 = isintraday and today
sell2 = isdaily and today
sell3 = isweekly and lastwk
sell4 = ismonthly and lastmo

sellCondition = sell1 or sell2 or sell3 or sell4

if (longCondition)
    strategy.entry("long1", strategy.long)

if (sellCondition)
Good news! Tradingview has now incorporated a Buy&Hold comparison into their backtester, so this should not be needed any longer :)
EN English
EN English (UK)
EN English (IN)
DE Deutsch
FR Français
ES Español
IT Italiano
PL Polski
SV Svenska
TR Türkçe
RU Русский
PT Português
ID Bahasa Indonesia
MS Bahasa Melayu
TH ภาษาไทย
VI Tiếng Việt
JA 日本語
KO 한국어
ZH 简体中文
ZH 繁體中文
AR العربية
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing My Support Tickets Contact Support Ideas Published Followers Following Private Messages Chat Sign Out