had to use a pyramiding value of 2 to actually get it to execute, USD base currency, and commission based on % of each trade
net profit $ 11,511.17, $5,778.47 max draw 43% ouch, 20 closing trades, 50% POP
strategy(title =“Moving Avg Crossover”, overlay = true, initial_capital = 2000, commission_type = strategy.commission.percent, commission_value = 0.2)
//date and time
fromDay = input(defval=1, title = “from Day”, minval = 1)
fromMonth = input(defval=1, title = “from Month”, minval = 1)
fromYear = input(defval=2014, title = “from Year”, minval = 1)
toDay = input(defval=1, title = “to Day”, minval = 1)
toMonth = input(defval=1, title = “to Month”, minval = 1)
toYear = input(defval=2025, title = “to Year”, minval = 1)
// definitions
short = sma(close,20) // 20 day simple moving avg of close price
long = sma(close,50) // 20 day simple moving avg of close price
// logic
timeinRange1 = time > timestamp(fromYear,fromMonth,fromDay,00,00) and time < timestamp(toYear,toMonth,toDay,23 , 59)
longSignal1 = crossover(short,long) and timeinRange1
shortSignal1 = crossover(long,short) and timeinRange1
// positions
strategy.entry(id = “longPosition”, long = true, when = longSignal1)
strategy.entry(id = “shortPosition”,long = false,when = shortSignal1)
// 2nd time range stretch it out 1 year, 6 months from inital from and to ranges
timeinRange2 = time > timestamp(fromYear,fromMonth-6,fromDay,00,00) and time < timestamp(toYear,toMonth+6,toDay,23 , 59)
longSignal2 = crossover(short,long) and timeinRange2
shortSignal2 = crossover(long,short) and timeinRange2
// positions
strategy.entry(id = “longPosition”, long = true, when = longSignal2)
strategy.entry(id = “shortPosition”,long = false,when = shortSignal2)