<div dir="ltr"><div><span style="font-size:12.8px">Hello all,</span></div><div><span style="font-size:12.8px"><br></span></div><span style="font-size:12.8px">I'm fairly new to backtesting in R. I made a Bollinger Bands and R strategy to learn how to use quantstrat which works fine. After playing around with different Bollinger Bands and RSI variables, I am now trying to run a Bollinger Bands parameter analysis. I followed this: </span><a href="https://timtrice.github.io/backtesting-strategies/parameter-optimization.html" target="_blank" style="font-size:12.8px">https://timtrice.github.<wbr>io/backtesting-strategies/<wbr>parameter-optimization.html</a><span style="font-size:12.8px"> to add the distribution and run the param set. I got it to work but the results are the same for each parameter which is wrong even though it indicates it is using a different parameter value each time. There really isn't any error or debugging information I can use to figure this out but I believe the issue is with where/how I'm applying the indicators/signals which makes it stuck on a single parameter value. This also could be from the location of the added distribution in the code but I'm not sure. Does anyone have any guidance? </span><span style="font-size:12.8px">Below is the portion of interest and attached is the full code.</span><br><div><span style="font-size:12.8px"><br></span></div><div><div style="font-size:12.8px"><div>#DISTRIBUTIONS</div><div>sdb = c(1.5,1.75,2,2.25,2.5)</div><div>RSIhigh = 70</div><div>RSIlow = 30</div><div><br></div><div>add.distribution(<a href="http://strategy.st/" target="_blank">strategy.st</a>,</div><div>                 paramset.label = "BBands",</div><div>                 component.type = "indicator",</div><div>                 component.label = "BBands",</div><div>                 variable = list(n = sdb),</div><div>                 label = "RBBands")</div><span class="im"><div><br></div><div>#INDICATORS</div><div>add.indicator(strategy = <a href="http://strategy.st/" target="_blank">strategy.st</a>,</div><div>              name = "BBands",</div><div>              arguments = list(HLC = quote(HLC(mktdata)),</div></span><div>                               n = 20, maType = "SMA", "RBBands"),</div><span class="im"><div>              label = "BBands")</div><div><br></div><div>add.indicator(strategy = <a href="http://strategy.st/" target="_blank">strategy.st</a>,</div><div>              name = "RSI",</div></span><div>              arguments = list(price = quote(Cl(mktdata)), n = 14,</div><div>                               maType = "WMA"),</div><div>              label = "rsi")</div><div><br></div><div>applyIndicators(strategy = <a href="http://strategy.st/" target="_blank">strategy.st</a>, mktdata=OHLC(SPY))</div><div>colnames(mktdata) <- c("SPY.Open","SPY.High","SPY.<wbr>Low","SPY.Close","dn.BBands","<wbr>mavg.BBands","up.BBands","<wbr>pctB.BBands","rsi")</div><span class="im"><div><br></div><div><br></div><div>#SIGNALS</div><div>add.signal(strategy = <a href="http://strategy.st/" target="_blank">strategy.st</a>,</div><div>           name="sigFormula",</div></span><span class="im">           arguments = list(label = "Cl.gt.UpperBB.RSI",</span><div>           data = mktdata,</div><div>           formula = "(SPY.Close >= up.BBands & rsi >= RSIhigh)",</div><div>           cross = FALSE),</div><span class="im"><div>           label = "Cl.gt.UpperBB.RSI")</div><div><br></div><div>add.signal(strategy = <a href="http://strategy.st/" target="_blank">strategy.st</a>,</div><div>           name="sigFormula",</div></span><span class="im">           arguments = list(label = "Cl.lt.LowerBB.RSI",</span><div>           data = mktdata,</div><div>           formula = "(SPY.Close <= dn.BBands & rsi <= RSIlow)",</div><div>           cross = FALSE),</div><div>           label = "Cl.lt.LowerBB.RSI")</div><div><br></div><div>applySignals(strategy = <a href="http://strategy.st/" target="_blank">strategy.st</a>,  mktdata)</div><span class="im"><div><br></div><div><br></div><div>#RULES</div><div>add.rule(strategy = <a href="http://strategy.st/" target="_blank">strategy.st</a>,</div><div>         name = "ruleSignal",</div><div>         arguments = list(sigcol = "Cl.gt.UpperBB.RSI",</div><div>                          sigval = TRUE,</div><div>                          orderqty = "all",</div><div>                          ordertype = "market",</div><div>                          orderside = NULL, </div><div>                          threshold = NULL),</div><div>         type = "exit")</div><div><br></div><div>add.rule(strategy = <a href="http://strategy.st/" target="_blank">strategy.st</a>,</div><div>         name = "ruleSignal",</div><div>         arguments = list(sigcol = "Cl.lt.LowerBB.RSI",</div><div>                          sigval = TRUE,</div></span><div>                          orderqty = 500,</div><span class="im"><div>                          ordertype = "market",</div><div>                          orderside = NULL, </div><div>                          threshold = NULL),</div><div>         type = "enter")</div><div><br></div><div><br></div></span><div>#APPLY STRAT</div><div>cwd <- getwd()</div><div>results_file <- paste("results", <a href="http://strategy.st/" target="_blank">strategy.st</a>, "RData", sep = ".")</div><div>if( file.exists(results_file) ) {</div><div>  load(results_file)</div><div>} else {</div><div>  results <- apply.paramset(<a href="http://strategy.st/" target="_blank">strategy.st</a>,</div><div>                            paramset.label = "BBands",</div><div>                            <a href="http://portfolio.st/" target="_blank">portfolio.st</a> = <a href="http://portfolio.st/" target="_blank">portfolio.st</a>,</div><div>                            <a href="http://account.st/" target="_blank">account.st</a> = <a href="http://account.st/" target="_blank">account.st</a>, </div><div>                            nsamples = 5)</div><div>  if(checkBlotterUpdate(<a href="http://portfolio.st/" target="_blank">portfoli<wbr>o.st</a>, <a href="http://account.st/" target="_blank">account.st</a>, verbose = TRUE)) {</div><div>    save(list = "results", file = results_file)</div><div>    save.strategy(<a href="http://strategy.st/" target="_blank">strategy.st</a>)</div></div><div style="font-size:12.8px">    }</div><div style="font-size:12.8px">}</div><div style="font-size:12.8px">setwd(cwd)<br></div><div style="font-size:12.8px"><br><div><br></div><div><br></div><div><br></div><div>Thanks for your help,</div><div>Colton Smith</div></div></div></div>