In Trading View

Advancing from our previous article in which we built the simplest strategy we can possibly back test, I now want to be able to specify a specific date range for my strategy to run between.

Since I am new to the Trading View strategy back tester myself, I’m not sure if this is the best or only way to set this but it’s what I understand right now so I hope it helps : )

Source code can be found here: Link

Here are the following steps we will take to add a time frame to our previous strategy:

  1. Set Beginning and End Time frames with the timestamp() function
  2. Set “IF” condition above
1 – Set begging and ending period

(Official timestamp documentation)

First lets create two timestamps that we can later use in our Long/Short conditions. The timestamp function takes in several parameters. timestamp(year, month, day, hour, minute).

2 – Set “IF” condtion

Now above our long and short conditions we can add a condition that first checks if we are within the beginning and end period, if so then run our strategy. Be sure to indent your code under the if condition. Our close conditions DO NOT need an if condition.

Make sure you are using version=2 and above or you will get an error running your condition this way. You can specify your version at the top of your code by adding //@version=2.

Her is the full code along with a link:

https://www.tradingview.com/script/4Oc0Ac79-Setting-Strategy-Time-Frame/

Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.