How to add CandleCode exit to my Strategy?
Author: rhino
Creation Date: 1/24/2009 12:55 PM
profile picture

rhino

#1
Strategy runs as written. Exits on profit or stop loss
target. Entry on CC trigger. Would like to exit on
existing targets or allow CC trigger to supercede.


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

Eugene

#2
What does it mean to "supersede"? If this is not something you were looking for, you'll need to explain it in detail:
CODE:
Please log in to see this code.
profile picture

rhino

#3
Thank you very much for the reply. Without understanding why, I notice that substituting Avg for 20 results in a 50% decrease in profit
in my test watchlist.
Except for that, you've captured it perfectly.
Cudos
Thanks Much

rhino
profile picture

Eugene

#4
QUOTE:
Without understanding why, I notice that substituting Avg for 20 results in a 50% decrease in profit
in my test watchlist.
I will stick with 20 for the time being.


You should set your trading loop's starting point based on the technical indicators that you're using.

Arbitrary numbers, like "20", can't be picked to start the trading loop - of course, if your intention is to avoid pipe dreams and produce robust results.

Since your SMA is 33-day and can potentially have a 50-day lookback, in this case you should start the loop at the "Avg" value.

Make sure you've also read the WealthScript Guide on "Stability of Indicators", although its warning doesn't apply to this system.

P.S. If some system's results can be reduced in half by starting the loop at bar 33 instead of a voluntarily picked bar 20 - well, you should really consider taking another look at Fidelity's disclaimer that they put at the bottom of the Performance tab. ;)
profile picture

rhino

#5
My understanding of what I've done is less than abysmal.
In the context of hourly vs. daily charts, and given that I've
concluded that 33 hours is optimal for all ticker symbols and won't be ratcheted henceforth,
is there value in pursuing this strategy?

A very humble
rhino
profile picture

Eugene

#6
Re: hours vs. days. A correction: I should have said "bar" instead of where I put "day", of course.

If I was to experience a dramatic performance cutback due to a change in backtest's starting date, it would make me rush to the first trades in order to find an outlier trade among them that caused it...
profile picture

rhino

#7
I have recompiled successfully and I believe it is still profitable enough to continue. I implemented the Avg lookback and evaluated,
before adding the remainder (the additional bracketed exit). When done together, the drop off is acceptable. I am Very Pleased
with the result!

rhino
profile picture

rhino

#8
Eugene,

If I observe that profit seems to correlate to SMA(UpperShadow, 20)less than(entry bar-1) to a 0.25 degree,

what code might I incorporate to improve results? And why does the visualizer series analysis select a lookback of 20?

rhino
profile picture

Eugene

#9
QUOTE:
what code might I incorporate to improve results?


It's up to you. ;)

QUOTE:
And why does the visualizer series analysis select a lookback of 20?


From the technical standpoint, the visualizer is all about grabbing the series of data stored in the so called Bars.Cache property. This cache holds all the created indicators, even those you won't normally see because they weren't created by you. The CandleCode system uses the CandleCode indicator which, in its turn, uses a lot of 20-bar BBandUpper and BBandLower in its internal calculation. You can make sure of that by looking into the source code available in our Wiki.

The indicator created by you can be found at the bottom of the list - and it's SMA(CandleCode(),33). Apart from it and the CandleCode series itself (cc), all these series you're observing are the CandleCode's internals. It's just the way Bars.Cache work.

For now, we have a tip: assign a meaningful description to your own series --
CODE:
Please log in to see this code.

This way they can be distinguished from the rest of the series filling the dropdown list because the .Description will be printed on the graph plot's title.
profile picture

rhino

#10
Am I then to assume that my creation of the variable lookback should be fixed at smaCC = SMA.Series (cc, 20);
for the Visualizer series analysis to be valid? You warned in your first post against mismatched lookback periods.
Or, am I somehow to edit the CandleCode indicator whose source is in your Wiki? And will my Wealth-Lab.net user ID suffice for the Wiki login process?
Of course none of this is germane if I cannot construct a bracketed entry/exit based upon SMA(UpperShadow,20) less than (entrybar-1), nicht wahr?

rhino
profile picture

Eugene

#11
Hold on your horses: no need for anybody to edit any source code. ;)

QUOTE:
You warned in your first post against mismatched lookback periods.

What I was saying is: the main loop should be started at a reasonable point in time. Not arbitrary. This reasonable value typically equals to indicator's first valid value.

So why did we pick this indicator to determine the start of the main loop - and not the CandleCode, for instance? Because it takes more historical data to build it. Your choice is 33 bars but it can go back as far as bar 50:
CODE:
Please log in to see this code.

That's because your lookback varies from 5 to 50. (Should you use an "unstable" indicator like EMA or RSI, you would need to multiply that value by 3 or 4. It's all explained in the WealthScript Programming Guide.)

Hope it's clear. That's all it takes:
CODE:
Please log in to see this code.

Set it and forget it. Your lookback should not be fixed for the Visualizer to be valid.
profile picture

rhino

#12
Eugene,

The whole concept of variability of the MA's was an homage to a strategist named Glitch, who wrote some self-tuners that I have been

unable to succefully translate to the .net format. I am willing to forgo the variability in this instance.

I wish to utilize the Visualizer series analysis to it's maximum benefit. For argument's sake, I set the Avg to 20 and ran the series again.

It achieved a 0.65 correlation to the UpperShadow series. That is significant correlation, no?

So my guess is that on the position not active side of things, I should add a bracket along the lines of

CODE:
Please log in to see this code.


<snicker> Am I close?

rhino


profile picture

Eugene

#13
A +0.65 correlation is significant.

CODE:
Please log in to see this code.

I'm not familiar with the indicator. If your "less than" chart shows some improvement to be made after filtering, then condition your entry with this line to find out the outcome.

A couple of things to care:

1) First and foremost, read the tutorial that tells why you should be careful not to pick a histogram bin that looks like a sharp spike as the filter value.
2) Make sure you're dealing with a number of samples (i.e. trades) valid from statistical standpoint.
3) Outlier trades. The upper graph makes it easy to find them.
profile picture

rhino

#14
Eugene,

I visited the tutorial and will embrace the syntax I found there as to using <, not needing an else if the UpperShadow returns a no, and of course no

capital outlay until requisite statistical data exists. I am curious that you included a "+" when you opined on the significance of my

finding of a 0.65 correlation. Would the sign of the correlation matter?

Yours in ignorance,

rhino
profile picture

Eugene

#15
QUOTE:
I am curious that you included a "+" when you opined on the significance of my

finding of a 0.65 correlation. Would the sign of the correlation matter?

Yes. What is a positive negative correlation?
profile picture

rhino

#16
QUOTE:
Yes. What is a positive negative correlation?


Just a guess: 'a reason not to go long, a reason to short?'

The visualizer found a correlation with a seemingly high absolute value. The sign was negative. I was drawn to it-

as a moth to a flame.

WS doesn't like my using SMA(UpperShadow,20) as a "variable" when it is a "type".

Can I 'B-slap' it?

Do I define a dataseries? The term was derived from the visualizer analysis series dropdown.

Does (bar-1) suffice or must the concept UpperShadow be introduced there?

r
profile picture

Eugene

#17
QUOTE:
WS doesn't like my using SMA(UpperShadow,20) as a "variable" when it is a "type".

Remember, there are no such series in your code. They're internally used to build CandleCode. Define a new series like WealthScript Guide tells to.

QUOTE:
Does (bar-1) suffice or must the concept UpperShadow be introduced there?

Could you rephrase it please?
profile picture

rhino

#18
Given that a new series is defined (e.g. dataseries sma US = SMA.Series(UpperShadowcc,20)),

will
QUOTE:
if( SMA(UpperShadow,20) < (lessthan?) (bar-1)
have the syntactical elegance

necessary to invoke the 'compilation gods' in their full and awesome Aspect?

your nearsighted pachyderm,

rhino

p.s.

Why is the visualizer granted privileges that an erstwhile author is not (invoking the series with which I wish to filter)?
profile picture

Eugene

#19
QUOTE:
Why is the visualizer granted privileges that an erstwhile author is not (invoking the series with which I wish to filter)?


I believe this is already explained. The visualizer does not invoke anything by itself. It was made in a way that it can only access the series already created. In your case, serving the CandleCode indicator requires to build (internally) a number of data series you won't typically see. [See Bars.Cache entry in the QuickRef for an insight.] The visualizer will not attempt to hide any internally built series. To rule them out, leaving only those created by you, it would have to analyze your strategy code. Where it doesn't have access.

In WL4 things worked differently: you would specifically define a data series and name it for it to appear on the Analysis Series view. Initially I thought of such implementation for WL5, but remember, that visualizer is a "plugin" - an external entity bound to implement an interface, and it doesn't have access to your code. There is no WealthScript command like "AnalyzeSeries" any more, so the design must have been different.

QUOTE:
Given that a new series is defined (e.g. dataseries sma US = SMA.Series(UpperShadowcc,20)),

At first, you have to create an instance of UpperShadow.
profile picture

rhino

#20
Eugene,

I'm almost there.

If I can make
CODE:
Please log in to see this code.


into a valid expression ( change the < into a valid operator ),

I think it will compile.

r
profile picture

Eugene

#21
QUOTE:
into a valid expression ( change the < into a valid operator ),

I think it will compile.


It will not compile. There is no "US" (UpperShadow) at user level. This data series were not created by you, it's just become visible by chance - since it's internally available in Bars.Cache. Please take a look at CandleCode.cs from the TASCIndicators library source code to see how this temporary function is contructed, if for some reason you want to replicate it [in your code].
profile picture

rhino

#22
CODE:
Please log in to see this code.


Did I correctly use FindNamedSeries? I found it in Bars.Cache and thought I'd hit one outa the park.

The compilation doesn't have issues with US. Operator '<' cannot be applied to operands of type 'double' and

'WealthLab.Series' is its castratory rejoinder. I gave a thought to an offset and divide process, izzat what it wants? But the result

would still need to be sorted as to greater than or less than 1 for a decision to go or abort.
profile picture

Eugene

#23
Good try. Unfortunately, FindNamedSeries serves a different task of finding the so called "named series" -- registered (i.e. "attached" to) with a Bars object when physically creating a DataSet. Like those extra data fields in imported ASCII files that contain adjusted/unadjusted close series for a futures contract that you may or may not import.

Although the code compiles, because it's valid for the compiler, in run-time it will produce an error.
profile picture

rhino

#24
Eugene,

My visit to Wiki produced zips of source and bin. Unzipped, source contained .suo and .snl files. I'm unlikely to have a native app that will produce readable

text from which to build a 'US' dataseries. I could, but have hesitated to, unzip the bin into the main WL5 directory. Will this yield desired result, access to

elusive dataseries "UpperShadow" ? I fear I've been stymied. And even should I succeed at that, the question of replicating the arduous mathematics of '<' would remain.

I will revert to the unanalyzed product and offer my gratitude for your expertise and patience.

As ever,

rhino

profile picture

Eugene

#25
Forget the source code. Here's a compensation for your FindNamedSeries attempt:

CODE:
Please log in to see this code.

profile picture

rhino

#26
Eugene,

I gotta catch my breath!

Bless you. It will take me awhile to assimilate.

Will I be CrossUndering in a bracketed entry? You already have the gist of it, but here's where it stands now.

You've been consistently 3 steps ahead of me. I must sheepishly admit to having created the EMA version

and it was a horrible disaster! I did think to use larger lookback, but chose double instead of

three to fourfold.

CODE:
Please log in to see this code.


profile picture

rhino

#27
Eugene,

(retrieved from cross post in Forum: General)

<cringe>

In Visualizer Trades V2, what is represented in column Priority ?

On the CC strategy, I successfully mimiced your 'new series smaUS' to create new series 'US' upper shadow [ bars.cache.containskey ("UpperShadow")] at instant, and it compiled,

but when I entry bracket for crossover or under one of the other, it filters trades to zero. Where is my logic flaw, please?

rhino
profile picture

Eugene

#28
rhino

QUOTE:
In Visualizer Trades V2, what is represented in column Priority ?

A position's Priority property:
Trades-v2
Take a look into its entry in the QuickRef for more details about the concept.

QUOTE:
but when I entry bracket for crossover or under one of the other, it filters trades to zero. Where is my logic flaw, please?

I'm not familiar with CandleCode. "UpperShadow" is a component of the CandleCode series. In other words, CandleCode is a derivative of UpperShadow and some other series. Do you have a sound reason to believe that there is a correlation between an internally calculated data series and profit percentage?
profile picture

rhino

#29
Eugene,

I enlisted your aid in creating smaUS based upon series analysis of strategy against data set of WL4 variety. It's validity is in question and

under investigation in Forum: General

Pending that, the series analysis would suggest that a criterium of position entry would be that smaUS(20) at (bar-1) be less than the instant value of UpperShadow at (bar-1).

At the time I last viewed the series analysis (WL4 data) the correlation was on the level of -0.65. Ergo, I tried creating the sma-less US series and requested a CrossUnder

of the moving average below the instant.

While this approach compiled okay, it effectively precluded Trading (i.e. this condition never,in 1000 hourly bars, occurred).

I have just discovered your video tutorials, and they are bomb <grin>. If you haven't already done so, would you construct a video tutorial

with forum posting as its subject matter? Esp use of 'LINK' and 'CODE' etc.


Yours in nebulosity,

rhino

profile picture

Eugene

#30
rhino

Thank you for all the good words.

QUOTE:
While this approach compiled okay, it effectively precluded Trading (i.e. this condition never,in 1000 hourly bars, occurred).

What I shown to you are nothing but data series. Their usage is entirely up to you (and I haven't seen an example of what your usage did look like).

QUOTE:
would you construct a video tutorial with forum posting as its subject matter? Esp use of 'LINK' and 'CODE' etc.

The usage of tags is pretty straightforward, just like on many other forums. In short:

Place a web link right inside the tag to get it done quick & dirty. On the other hand, if you want it to have a custom title, place the web link inside the first tag i.e. LINK=here_goes_your_link..., then put your title, and leave the closing tag as is. You're done.

The CODE tag is dead simple. Paste your code snippet inside, nowhere else, the forum software does the rest. ;)
profile picture

rhino

#31
Eugene,

Practice 'LINK'

Here's Eugene's Videos

The correlation's significance has dropped since swapping out WL4 data sets and I have put the project "back-burnerside".

Next stupid interrogatory: having viewed the rules based video, how difficult to include a time-based exit from rules into an extant script based (e.g CandleCode)

strategy? This is a general question as I presume constructing scripting for a time-based exit is not beyond my monkey see capabilities.

Forever indebted,

rhino

profile picture

Eugene

#32
QUOTE:
how difficult to include a time-based exit from rules into an extant script based (e.g CandleCode) strategy? This is a general question as I presume constructing scripting for a time-based exit is not beyond my monkey see capabilities.

A TB exit can be found both in Rule-based Wizard and among the QuickRef examples.
It's a matter of simply comparing integer values:
CODE:
Please log in to see this code.

Note that the addition of "1" is to compensate for WL5's pessimistic outlook (e.g. buy at close today + sell at market tomorrow = gives you 2 bars held already). It's cool if you're into being realistic about market exposure.
profile picture

rhino

#33
Eugene,

Hey, I built a "Link"... annnn its puuuurty.

So...I can't invoke a Rules wizard to trick out a Scripted Strat?

a credibly dense

rhino
profile picture

Eugene

#34
QUOTE:
So...I can't invoke a Rules wizard to trick out a Scripted Strat?

Your understanding is correct: No.
profile picture

rhino

#35

<eyes downcast,bashful foot shuffling>

Oh-kay
profile picture

rhino

#36
Eugene,

Dude, I crashed it big time. Can't start it up w/out unhandled exception. Can't open a blank strategy w/out Index was out of range error.

QUOTE:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


Gulp! Help!
profile picture

Eugene

#37
This should help:
Errors | Strategy
No WLP shutdown/restart required.

If it doesn't, then please create a support ticket for this issue. Thank you.
profile picture

rhino

#38
Eugene,

Thanks for the quick turnaround. I was freakin'!

I bookmarked the linked page you sent. Fer next time. This time I availed myself of Apple's vaunted 'Time Machine' feature

to rebuild my .pvm Virtual Machine.

thanks again!,

rhino
profile picture

Eugene

#39
rhino

I'm interested what did you do before the problem came up?
profile picture

rhino

#40
Eugene,

I was copying and pasting a voluminous script from the Fora here.

Maybe a tutorial there?
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).