Troubleshooting TSF/KAMA based strategy
Author: Eugene
Creation Date: 11/26/2013 2:26 AM
profile picture

Eugene

#1
Kiran,

As your question has deviated far enough from the original subject ("Automated trade execution on the Ghost Bar OR scanning multiple timeframes simultaneously?") into troubleshooting your code, I've moved the conversation to a new thread.

kbellare asked:

I didn't have source code/formula access to TSF or KAMA (which would make it easy to evaluate the "partial bar" indicator value using the code you've mentioned below), I tried a different approach to evaluate the partial bar indicator value in the HighInterval scale (see my code below). However, i get an error, because i'm trying to set a series value for "HighInterval Bar+1" in teh HighInterval scale - "Runtime Error: Index was out of range. Must be non-negative and less than size of collection".

How do i get around this to define the partial bar value to the indicator series? Can i somehow reference TSF.Value or KAMA.Value function to define the last value in the Low Interval bar scale?


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

Eugene

#2
Using "bar+1" will inevitably cause a bounds violation when accessing Open[bar+1] at bar == Bars.Count-1. Please carefully reread my previous reply dated 11/22/2013 3:29 AM for the proper direction and see the linked Wiki KB articles:

Automated trade execution on the Ghost Bar OR scanning multiple timeframes simultaneously?

P.S. For the sake of completeness, some indicators (but not TSF) might implement the PartialValue property in Streaming strategies (QuickRef for more details). However, note that PartialValue is not fully supported and there were concerns expressed about correctness of its implementation in most all standard indicators (including KAMA). This is not supported.
profile picture

Eugene

#3
kbellare replied:

Please help - in my TSF crossing WMA(TSF) strategy, I tried following the suggested method (code below) of building the TSF and WMA "hybrid" indicators using formulas (I'm using WAMA instead of KAMA as its formula is known and easy) and running it on 15min or 10min bars - but run into 2 strange issues (can't figure out where the bug is)

1) TSF(compressed price bars) displays as 0 in the price chart after i've restored the scale, whereas WMA(TSF(compressed price bars)) displays correctly and tracks the price - even WMA should fail if TSF is failing.

2) I've used this TSF formula (below) to build the Hybrid-TSF indicator as it was listed as an easier alternative in the community source code (file attached), but not sure if LinearReg.Series and LinearRegSlopeSeries will be found in the libraries.

tsf[bar] = LinearReg.Series(partialPr, TSFPeriod.ValueInt)[bar] + (LinearRegSlope.Series(partialPr, TSFPeriod.ValueInt)[bar] * 0);

3) Please check if my logic for building the hybrid-TSF and hybrid-WMA indicators - it was quite complicated to pull data-points from 2 different series, but difficult to validate.


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

Eugene

#4
QUOTE:
1) TSF(compressed price bars) displays as 0 in the price chart after i've restored the scale, whereas WMA(TSF(compressed price bars)) displays correctly and tracks the price - even WMA should fail if TSF is failing.


The problem is caused by this line:
CODE:
Please log in to see this code.

Edit it like this and the TSF should appear on the chart:
CODE:
Please log in to see this code.


By the way, to properly debug the partialPr, change the code everywhere:
CODE:
Please log in to see this code.


I leave checking the strategy's logic up to you.
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).