I am new, and not so very smart , 😊..
my algo uses consolidated 200 Resolution.Minute bars, and gives me over 200% profit over a 2 year back test. , and sharpie ratio over 1 .
but I find it strange is, I change minutes from 200 to 199, I get completely different result, I get a loss over the same period..
similarly if change 200 to 201, I get very different results…..
is this normal, for such a small change ? What am I doing wrong ?
that's my code below
STOCK = "QQQ"; BAR = 150; SL = -0.033; TP = 0.05; ATR = 1; MULT = 0.15;
# --------------------------------------------
class SuperTrendIndicator(QCAlgorithm):
def Initialize(self):
self.SetStartDate(DateTime(2000, 5, 17, 9, 30, 0))
self.SetEndDate(DateTime(2004, 6, 1, 16, 0, 0))
self.SetCash(200000)
res = Resolution.Minute
#ATR = int(self.GetParameter("ATR_A"))
#MULT = float(self.GetParameter("MULT_A"))
self.stock = self.AddEquity(STOCK, res, extendedMarketHours = True).Symbol
consolidator = TradeBarConsolidator(timedelta(minutes = BAR))
self.Consolidate(self.stock, timedelta(minutes = BAR), self.BarHandler)
self.st = SuperTrend(ATR, MULT, MovingAverageType.Wilders)
self.RegisterIndicator(self.stock, self.st, consolidator)
self.SetWarmUp(50*BAR*ATR, res)
def BarHandler(self, consolidated):
if self.IsWarmingUp: return
if not self.st.IsReady: return
self.Plot(STOCK, "Price", self.Securities[self.stock].Price)
self.Plot(STOCK, "Super Trend", self.st.Current.Value)
pnl = self.Securities[self.stock].Holdings.UnrealizedProfitPercent
if self.Securities[self.stock].High > self.st.Current.Value and self.Securities[self.stock].Open < self.Securities[self.stock].High: # trend is bullish
self.SetHoldings(self.stock, 1, True, "Buy Signal")
elif self.Securities[self.stock].Low < self.st.Current.Value and self.Securities[self.stock].Open > self.Securities[self.stock].Low:
self.SetHoldings(self.stock, -1, True, "Sell Signal")
#self.Liquidate(self.stock, "Sell Signal")
if self.Portfolio[self.stock].Invested:
if pnl < SL:
self.Liquidate(self.stock, "Stop Loss")
elif pnl > TP:
self.Liquidate(self.stock, "Take Profit")
Vladimir
Zimman
Can you share a backtest?
Zimman
Hi Vladimir
The attached backtest gives me -24% loss on 201 minutes bars, the 200 minutes bars returns -12% loss.
I was also wondering if you can help me on this please man, am struggling to have multiple timeframes on one indicator.
For example, to buy QQQ if 201 minutes bar and 30 minutes bar and 1 minutes bar all have a Buy Super Trend Signal.
Thank you
Vladimir
Zimman
I see some problems in your code.
Your algorithm log has 7 pages of Insufficient buying power to complete order.
Try this
Vladimir
Zimman
Here is the code snippet of the above attached backtest.
Zimman
Hi ..
I am.just wondering why Drawdwon drops so low, even when fees and losses are negligible.
This strategy is supposed to liquidate a position once the signal changes direction. I have seen drawdwon dropping to -30%, and I can't seem to understand what that happens. I understand there could be slippages, but the long position should still liquidate on the next sell signal, or the sell signal after that…
For example lets say i enter a long position at $100, and price drops straight away (slippage) to say $98…. and it then goes up to 99.50 and drops again …In this case if would expext the long position to liquidate at 99.50 sell signal… unfortunately if the price keeps a downward trend with several buy and sell signals until it reaches $50 , my $100 long position still remains open with the drawdown getting worse….
How can i avoid this using only the buy sell signal triggers, avoiding an arbitrary stop loss level?
Vladimir
Zimman
I am.just wondering why Drawdwon drops so low, even when fees and losses are negligible.
Did you have a chance to try what I recommended?
Compounding Annual Return 37.337%
Drawdown 12.200%
Zimman
Hi Vladimir , first off, thank you for your help. I did indeed implement your edits and I went on to improve it further and I was now getting over 50% compounding returns with 13% DD, sharpie 2.3 for the same test period 2020 -6 -10 to 22-6-10.
Unfortunately the strategies is not usable because if I change the test period to 2010 6 10 - 22-6-10 , for both your edited version and my newest version that's when results get very ugly.
My version compounding returns is now 3.5%, DD is 44% and, sharpie 0.27
Your edited version above gives , compounding -11.142% , DD is 78% and sharpie -0.7
Manav Trivedi , thank you .
Louis Szeto
Hi All
I just want to point out one more thing: if you change a hyperparameter very slightly and it produces a completely different result. The “good” backtest is very prone to overfitting and drawing conclusions in the wrong flow, rather than a hypothesis → testing → conclusion. I would say that would probably not transfer its success to future trading since no hypothesis was proven to be working.
Best
Louis
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Zimman
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!