Running into issues y’all!
So, I’m fairly certain I got the right code:
// @version=3
strategy(title = "MA Cross", overlay=true, initial_capital=2000, commission_type="strategy.commission.percent", commission_value=0.2)
// DATE AND TIME
fromMonth = input(defval=5, title = "From month", minval=1)
fromDay = input(defval=15, title = "From day", minval=1)
fromYear = input(defval=2018, title = "From year", minval=2014)
toMonth = input(defval=8, title = "To month", minval=1)
toDay = input(defval=15, title = "To day", minval=1)
toYear = input(defval=2018, title = "To year", minval=2014)
// VARS
shortMA = sma(close, 20)
longMA = sma(close, 50)
// LOGIC
timeInRange = (time > timestamp(fromYear, fromMonth, fromDay, 00, 00)) and (time < timestamp(toYear, toMonth, toYear, 23, 59))
longSignal = crossover(shortMA, longMA) and timeInRange
shortSignal = crossover(longMA, shortMA) and timeInRange
// POSITIONS
strategy.entry(id="longPosition", long=true,qty=0.1, when=longSignal)
strategy.entry(id="shortPosition", long=false, qty=0.1, when=shortSignal)
When I “Add to Chart” I can see it, BUT, I only get 19 trades total and it runs until now-ish (2021).
Clearly something is not right, so what am I doing wrong?