smith26

Buy&Hold

262
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.

Skript med en öppen källkod

I sann TradingView-anda har författaren publicerat detta skript med öppen källkod så att andra handlare kan förstå och verifiera det. Hatten av för författaren! Du kan använda det gratis men återanvändning av den här koden i en publikation regleras av våra ordningsregler. Du kan ange den som favorit för att använda den i ett diagram.

Frånsägelse av ansvar

Informationen och publikationerna är inte avsedda att vara, och utgör inte heller finansiella, investerings-, handels- eller andra typer av råd eller rekommendationer som tillhandahålls eller stöds av TradingView. Läs mer i Användarvillkoren.

Vill du använda det här skriptet i ett diagram?
//@version=2
//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)
    strategy.close("long1")