Filtering on external symbol isn't working
Author: djmundus
Creation Date: 9/23/2018 7:46 PM
profile picture

djmundus

#1
I have a pretty straightforward strategy... If the Close of the stock is above its KAMA and the Nasdaq (.IXIC) is above its KAMA, then buy at a limit and sell at the open the next day.

When I look back on the trades during backtesting, I am seeing trades execute on days when the .IXIC is below its KAMA.

And yet... If I comment out both KAMA filters, I get 3,472 trades over the last year. If I add the filter for the Close of the stock being above its KAMA value, trades drop down to 3,104. And if I include the IXIC KAMA filter, it drops down to 2,976 trades.

So the IXIC filter is doing *something*, but it isn't actually preventing the system from trading on days when IXIC is below its KAMA.

What am I doing wrong here?

CODE:
Please log in to see this code.
profile picture

Eugene

#2
I think you're missing something, thinking that the external symbol's KAMA is above its Close when looking at the bar of entry (by this moment it may dip lower).

Anyway there's an inaccuracy in the code:
CODE:
Please log in to see this code.

Given that the code uses unstable indicator KAMA, this may produce incorrect results at the beginning of a backtest. For more detail see the WealthScript Programming Guide > Indicators > Stability of Indicators. Not sure where you learnt to start the trading loop from bar 0 but this would be safer:
CODE:
Please log in to see this code.
profile picture

Eugene

#3
Gosh, I fooled myself yesterday into duplicating my own answer which you probably have overlooked as you repeat the same error (see post #6):

How to compare entry date to current date in intraday chart

That's one of the perils with multiple discussions dedicated to what essentially is the same subject - like your strategy's code.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).