TradingView
JayRogers
May 31, 2016 5:52 PM

Strategy Code Example 2 - Time Limiting 

Euro Fx/British PoundFXCM

Description

*** THIS IS JUST AN EXAMPLE OF STRATEGY TIME LIMITING CODE IMPLEMENTATION ***

This is a follow up to my example for risk management implementation here:

tradingview.com/script/zgn9pUcQ-Strategy-Code-Example-Risk-Management/

Code remains mostly unchanged, but now includes a time limiting implementation.

Relevant code blocks for the time factor are preceded with a comment stating:
  • *** FOCUS OF EXAMPLE ***


Cheers!
Comments
Cookedaburra
anyway to make it close a trade after a certain expiry time?

eg for binary options 5mins expiry
TheYangGuizi
Would it be possible to make a strategy only run during a certain time? Like between 9:00 to 10:00 for example.
JayRogers
Yes it should be entirely possible. Have a look at this script in the public library uk-www.tradingview.com/v/KmSvV5zH/
worthy7
@JayRogers, How do we filter by day of the week? Only want to execute trades on tue+wed but I can't see any documentation about how to get these values. The link is broken (at least for me)
Objredline
@worthy7, Link is broken. Did you ever figure out how to filter the backtest on a period in the past? Especially if that period is outside of Tradingview's ~8000 bar hard cap?
worthy7
@Objredline, I took a quick look at some of my old code, found this line:
`tradingallowed = (not na(k) and not na(d) and (dayofweek==3 or dayofweek==4 or dayofweek==5)) and (getTakeProfitInTicks(tradedirection)/10 > MinimumPredictedProfitPerTrade)`
Objredline
@worthy7, Thank you! is tradingallowed a TV built in function? Thanks again.
worthy7
@Objredline, no just part of my code, the important point is dayofweek==3, which I think is a Tuesday.
ivanovich
Dear Jay.
How can I change EMA to HullMA
ZA8365
Hi Jay.
Thanks
More