Porting 4.0 to 5.0
Author: reds
Creation Date: 9/16/2010 1:02 AM
profile picture

reds

#1
Robert or Eugene,

Big favor to ask of you. If either of you get any downtime I could really use your help porting the below 4.0 code to 5.0. I have put off the inevitable long enough and need to move to 5.0. This script covers all my 4.0 needs and if ported to 5.0 would allow me to build derivative systems using this as a template. If gbeltrame or ft were around I'd leave this "dirty" work to their expertise but the old crowd has moved on.


Thanks,

Mike

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

Eugene

#2
Some thoughts upon reviewing your chartscript:

1. Its readability would greatly benefit from turning repetitive spaghetti code to procedural, and even introducing a custom class to hold symbol data (such as x, ThresholdLong, ThresholdShort etc.)

2. The Combined ROC is crying to get implemented outside of a WealthScript Strategy - as an IndexDefintition (actually, there seem to be 3 distinct indices based on different data sets). You'd then use the Index Manager to create as many Combined ROC indices as you need based on existing DataSets and/or AronowSoftware's WatchLists, using the GUI dialog for configuring those multiples (i.e. Multiple[n])

Due to the complexity involved, sounds like a perfect candidate for our upcoming MarketPlace. Meanwhile, have you already tried Wealthscript Translator on this code?
profile picture

dansmo

#3
@ Eugene
"for our upcoming MarketPlace"
Can you give more info on that?
btw: when I visit the forums "Support" is highlighted on the upper menu on the page.
profile picture

reds

#4
Hi Eugene,

I do not think the Translator tool works with external series, at least not the last time I tried.

Your ideas about procedural, custom class, IndexDefinition etc...most likely what I need to streamline this from 4.0 to 5.0 but I am looking for this example to be ported and then use that port as a path to 5.0 with a script or code.

It is repetitive so it is not as long as the number of lines indicate.

What is MarketPlace? Outside of Robert, you and Dave do you know of any other 5.0 experts that could tackle this job?

Thanks,

Mike

profile picture

Eugene

#5
Dan/Mike,

The MarketPlace is a medium to connect customers (i.e. non-programmers) with contractors (programmers) willing to take the opportunity on a paid basis.

Mike,

As an example, this code would be pretty terrible.

To clarify my #1...

Here's what you're doing currently:

1. Determine current symbol
2. Set up the custom array of external symbols with custom weights
3. Set scale to weekly
4. Retrieve the OHLC of the corresponding external symbol
5. Based on the ext. symbol's data, actually calculate this value (I dropped the SMA(x),1 - no apparent reason for this):

value = ((((Open-Close[bar-1])/Close[bar-1] )*100)* Multiple);

6. Repeat previous step 8 times for no apparent reason

And here's what I'm proposing:

1. Program* an IndexDefinition with GUI inputs for multiples
2. Set up a DataSet or a Dave Aronow's WatchList with exactly those 8 symbols
3. Create and update the 3 indices: one for QQQQ or IWM), another for SPY and XLU, and the last one for all the rest.
4. SetScaleWeekly in your new Strategy
5. Just like the User Guide suggests in Index-Lab > Using Indexes, use the index symbols in the same way as other secondary symbols.

* I'm not suggesting you do this, of course, it's an above-average job involving a C# IDE (like Visual Studio) and a (currently) undocumented IndexDefinition interface.

The trading part of the script is less complicated. Thoughts?
profile picture

reds

#6
Hi Eugene,

Without your proposed #1 how would you get the multiples for each component of the index?

Could it be done in 5.0 with your #1 taking a simpler, more direct form?

Could you create a template on 5.0 for me to work with?

Thanks,

Mike
profile picture

Eugene

#7
Mike, I noticed you keep mentioning 5.0 and therefore suggest upgrading to 6.0 if you've not already done so (Index-Lab is built-in).

OK, the solution involving #1 would be elegant - maybe we return here at a later stage. Here's a quick rewrite of your code w/o the file dump part (I leave this up to you). Some nuances were omitted for clarity, they can be added later.

Notes:

1. I didn't test it thoroughly.
2. AllowSymbolSearch isn't supported in Wealth-Lab 6, so I left some code commented there in case you decide to specify certain DataSets/WatchLists.
3. Code requires Community Components installed from "Extensions" (and WLP restarted after the fact) for EnterAtPrice/ExitAtPrice to function. We don't have ExitAllAtPrice but your code is single position so it's not required.

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

reds

#8
Eugene,

Thank you very much!

Mike
profile picture

reds

#9
Hi Eugene,

As it is coded in 6.0 the plotted CombinedROC values change each time I change the starting date of the chart. If I start in 2002, I end up a tone value and if I start in 2008 I end at a different value. In WL 4.5, the ending value for CombinedROC always ends at the same calculated value regardless of start point.

The weekly closing value, the last value charted, should be the same from week to week and not build upon previous values.

Also, it seems to wait a day ti enter a new position if it is exiting an existing position. For example it will sell if below threshold on Monday but not take the short until Tuesday. In the 4.0 code, it would sell on Monday and go short on the same bar. I do not see a tab in 6.0 to allow same bar at close orders.

Lastly,although it compiled and ran, a few errors generated. The g=first was "runtime error:index was out if range. must be non-negative and less the size of the collection". There were a few others as well and they might stem from this first error but I cannot seem to copy the list of errors from the lower pane.

Thanks,

Mike
profile picture

Eugene

#10
Hi Mike,
QUOTE:
The weekly closing value, the last value charted, should be the same from week to week and not build upon previous values.

My bad. I was using the new "old" method GetExternalSeries and didn't ensure proper synchronization afterwards. Either copy the updated code above or just replace these lines:
CODE:
Please log in to see this code.

With this fixed code:
CODE:
Please log in to see this code.

Hope the issue goes away.
QUOTE:
The g=first was "runtime error:index was out if range. must be non-negative and less the size of the collection".

Ensure that all the hard-coded symbols exist in your DataSets.
QUOTE:
but I cannot seem to copy the list of errors from the lower pane.

Right, and I guess the developers had a good reason for making it impossible.
QUOTE:
Also, it seems to wait a day ti enter a new position if it is exiting an existing position.

The implementation of trading rules was nothing but a quick approximation, as my main focus was on getting the complex part done i.e. rewrite the CombinedROC spaghetti code and make it as comprehensible and manageable as possible. I leave the trading rules job up to you to learn and to practice.
profile picture

reds

#11
Eugene,

QUOTE:
Right, and I guess the developers had a good reason for making it impossible.
Ha Ha!!


I am working with the C# code and will say it is not that far off from the 4.0 code.

Well done..thank you!

Thanks again,

Mike
profile picture

reds

#12
Hi Eugene,

Error is still there..."Index out if Range" followed by other descriptions.

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

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

the error goes away but the number of trades decreases considerably. If you have any ideas let me know & I will continue to work on the trade logic.

I also cannot find the synchronization tab in the Tools section that was there in 4.0. Visually, I like to to see the Chart CombinedROC indicator plotted with Option #2, "Compressed bar available on first bar of period". can this be set in 6.0?

Thanks,

Mike
profile picture

Eugene

#13
QUOTE:
If you have any ideas let me know & I will continue to work on the trade logic.

I guess it takes...
CODE:
Please log in to see this code.

QUOTE:
I also cannot find the synchronization tab in the Tools section that was there in 4.0. Visually, I like to to see the Chart CombinedROC indicator plotted with Option #2, "Compressed bar available on first bar of period". can this be set in 6.0?

For simplification, this option was removed. Visit the Wealth-Lab Wiki to learn the WL6 way of doing things: Compressed price series alignment.
profile picture

reds

#14
Eugene,

I am making progress and have it pretty much matching trades in 4.0 :-)

I'd like to add a condition to Buy the Close must be greater than the 20 day SMA of the Close.
CODE:
Please log in to see this code.


but it generates an error that you cannot use ">" cannot be applied to operands of type double and Wealthlab.Indicators.SMA

Thanks,

Mike
profile picture

Eugene

#15
Sounds great. :)

You're just missing a "[bar]" after SMA.Series... -- make sure you checked out DataSeries > Accessing a Single Value from a DataSeries in the WealthScript Programming Guide.
profile picture

reds

#16
Eugene,

I can't find the autostops, except for an auto-trailing stop. Are they gone or can you point me to them?

Also, Lead Bars, can that be set in 6.0? In 4.0 I set it to 0, began a CS with date equal to 1/1/2008 and trades were generated the second week of January. In 6.0, I cannot seem to set Lead Bars and when I set the start date to 1/1/2008, the first trades are not until August 2008 and then line up with 4.0 from that point forward.

Thanks,

Mike
profile picture

Eugene

#17
Re: AutoStops - they were removed in 5.0, but thanks to Dave Aronow, Community Components have them again as a set of methods: AutoStops. However I suggest to not use autostops and program your stops manually, it's not that complicated.

Re: lead bars - see Wealth-Lab Wiki FAQ | "Missing" features > Where did the Lead Bars go? I heard Fidelity would offer a Lead Bars replacement feature as soon as in 6.1.
profile picture

reds

#18
Continuing to look around 6.0 and effects of changing parameters.

I noticed if I set the date range from 1/1/2008 to present the code trades correctly. If I set it to all data it generates an error message, "Cannot plot a dataseries that contains infinity" and a few other follow-up errors.

What would cause this? Is it because of the external series do not have identical history and the overlap is not from the same starting point? In 4.0 it would run and include the input as it started trading.

BTW, I agree with AutoStops and only used them to quickly test a variety of stop methods but final version of code will always have them hardcoded. I already hardcoded the stops - very straightforward!

Mike
profile picture

Eugene

#19
Hi Mike,

QUOTE:
I noticed if I set the date range from 1/1/2008 to present the code trades correctly. If I set it to all data it generates an error message, "Cannot plot a dataseries that contains infinity" and a few other follow-up errors.

Good catch. Replace this code line;
CODE:
Please log in to see this code.

With this block:
CODE:
Please log in to see this code.

Code above updated.
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).