Im trying to create a simple indicator that just has an SMA and a 2 Standard deviation of the SMA above and below, not sure how to write the standard deviation part yet. Any examples would be much appreciated.
Below is my half hack attempt.
CODE:
Please log in to see this code.
Size:
Color:
CODE:
Please log in to see this code.
See
StdDev indicator description.
CODE:
Please log in to see this code.
Size:
Color:
Size:
Color:
You hit the nail on the head, but I was confused by this: "a 2 Standard deviation of the SMA above and below". For Bollinger Bands, one would pass the Close as the parameter.
Size:
Color:
Thanks Guys, I figured out what I was trying to do. I want to use longer term STD Deviations on the intra day MA. Next Question how would one apply STDDev.Series of Daily to an intra day chart?
Size:
Color:
Take a look at Multi-Time Frame Analysis in the WealthScript Guide.
Size:
Color:
Thanks Eugene, I think I got most of it, it compiles ok, but comes back with a runtime error.
Is the problem in the DataSeriesSTDEV.. calculations??
CODE:
Please log in to see this code.
Size:
Color:
QUOTE:
but comes back with a runtime error
Because there's a bug :(
I'll get back to you shortly.
Size:
Color:
Ok, thanks Eugene
Size:
Color:
And the bug is: any series of a series (be it SMA, StdDev... etc.) in any combination produces a runtime error when external series are involved.
Size:
Color:
Ok, I think I get it. In this case the Daily data is an external series, even though its the same symbol?
Size:
Color:
No, the bug affects trying to create a 2nd order derivative of an external series - namely
closeDaily1 and
closeDaily2.
CODE:
Please log in to see this code.
Size:
Color:
And the workaround, as usual with those synch bugs, is to create the series manually by filling in the values in the loop:
CODE:
Please log in to see this code.
Size:
Color:
Eugene, Finally got this up and running, There still seems to be a problem with the way its calculation the Standard Deviation Bands. They just appear to be tracking the moving average. I am running it on 5 minute ACII data. Do I need the daily files in there as well? I would post an image, but not sure how to....
CODE:
Please log in to see this code.
Size:
Color:
QUOTE:
They just appear to be tracking the moving average.
They
are tracking the moving averages, that's how they are coded:
CODE:
Please log in to see this code.
So, what's wrong with this?
Size:
Color:
Sorry, maybe tracking isnt the right word. Right now both the upper and lower band return the same value as the moving average. I only see the close price and one line on my chart. The one line is actually the MA, upper and lower standard deviations as they split into 3 lines on the last bar.
Size:
Color:
Still not able to get this up and running correctly...
The problem seems to lie with the
CODE:
Please log in to see this code.
part of this calculation
If I change it to a fixed value such as 1, the bands appear above and below.
If I plot the smaSTD seperately it shows up with the expected value, however when part of the following calculation, it returns the same value as just ActualSpreadSMA, leaving me without any bands.
Hope that makes sense
CODE:
Please log in to see this code.
Size:
Color:
I also just tried PrintDebug to see what values I was getting,
CODE:
Please log in to see this code.
but it returned TestWealthLab.Indicators.SMA, not the actual value... whats the correct way to get this to return the actual value in the debug window?
I tried
CODE:
Please log in to see this code.
but that returned an error on compile
Size:
Color:
I don't understand the problem. Got a set of 2 bands plotted nicely:
CODE:
Please log in to see this code.
Size:
Color:
QUOTE:
whats the correct way to get this to return the actual value in the debug window?
It doesn't have to do with Debug window. Please read the WealthScript Programming Guide > DataSeries, the part that deals with accessing individual values of DataSeries.
QUOTE:
but that returned an error on compile
Right syntax, wrong place. Outside the loop? "An error" that you didn't specify tells you that "bar" is missing in this context?
Size:
Color:
Ok, Ill go back and follow through the instructions again.. Sure its something Ive messed up here....
Size:
Color:
Eugene, I believe I have found the error... If I use a straight number such as 1.5, (as you did), the bands come up ok. However, if I replace it with a parameter ( I was trying to optimize it), such as
CODE:
Please log in to see this code.
I get the problem as described above.
Size:
Color:
ok, Ive tried adding another multiplier a ratio of a short and lond Daily based STD, Ive tried charting it to see if its working, but its not coming back as expected. It returnes a value, around the close/open but returns zero for the rest of the intraday. I would expect it to look like a daily MA on an intraday chart. Changing values slightly once a day....
The new Dataseries are LongSTD and Short STD
CODE:
Please log in to see this code.
Size:
Color:
QUOTE:
The error I receive is error CS0103, here is how I have positioned it in the code
Please carefully re-read my reply above:
QUOTE:
Right syntax, wrong place. Outside the loop? "An error" that you didn't specify tells you that "bar" is missing in this context?
Right syntax but wrong place. Move the statement inside a loop by Bars.
QUOTE:
Eugene, I believe I have found the error... If I use a straight number such as 1.5, (as you did), the bands come up ok. However, if I replace it with a parameter ( I was trying to optimize it), such as
CODE:
Please log in to see this code.
I get the problem as described above.
Sometimes I wish I have some telepathic abilities, but no - I have not. Taking a look at your posting @ 1/11/2010 6:59 AM shows that the code you run and the code you post are two different animals. :)
Anyway, please see
Programming Trading Strategies > Strategy Parameters in the WealthScript Programming Guide. Sounds like you're defining a variable/parameter incorrectly somewhere. How are the
Band1 variable and the associated StrategyParameter defined?
Size:
Color:
Eugene, thanks for the replies. I get your point too. Apologies for the sloppy work and erratic questions.
The PrintDebug now works fine but Im not sure about the the Paramater. I replaced it with another paramter that works ok, but still getting the same problem.
I tested it as follows and recieved the value I expected
CODE:
Please log in to see this code.
However, when I used the following
CODE:
Please log in to see this code.
or
CODE:
Please log in to see this code.
it returns the same value as ActualSpreadSMA, so that means Band1/10 is returning zero?
Size:
Color:
Eugene, I was looking through some other posts and came across this example. Made the adjustments, and the code above works fine now. Took me a while.......
CODE:
Please log in to see this code.
Size:
Color:
A couple of corrections:
CODE:
Please log in to see this code.
Size:
Color:
Thanks for confirming that Eugene. I have one more thing I would like to have a go at here. I've made a couple of changes and would like to add a short Std Dev and a Long Std Dev, to create a volatility ratio of sorts.
Ive tried to add it as follows, I've created a new pane for the 2 Std Dev's, and they return a value at the open of the day and then drops to zero. The idea is for it to act as a multiplier, so I want it to keep its value throughout the day.....
the DataSeries in Question are ShortSTD and LongSTD
Probably easiest if I posted a screenshot, but not sure how to.
CODE:
Please log in to see this code.
Size:
Color:
I had a fresh look at this today, ran the 2 StdDev.series, LongSTD and ShortSTD in PrintDebug on 15minute data and they only returned their actual values 1 bar a day. The rest of the day they returned zero. ActualSpreadDaily returned its correct value for every bar. I know Ive changed the name of the DataSeries, but Im pretty sure Ive followed it as you outlined it earlier. Any advice?
CODE:
Please log in to see this code.
Size:
Color:
Sorry guys, Im still not getting anywhere with this.
Any ideas?
Size:
Color:
You're assigning SD upper and lower indicators to "Close*0". Is there reason to expect these series to return values other than zero?
Size:
Color:
Cone, please refer to the post above which includes a bit more of the code. This is actually the fix Eugene gave me earlier. The bands work fine if I replace the following code with anything else.
CODE:
Please log in to see this code.
I have made the above code its own indicator and the problem definately lies in this part. Applied to an intraday chart, it returns a value on the open of the first bar of the day, but then goes to '0' for the rest of the day. the dataseries 'ActualSpreadDaily' holds its value for the whole day. Im sure a screenshot would make it very clear, Im jsut not sure how to post it.
Size:
Color:
here we go, first attempt at a screenshot here.
Ive changed the bands just to be +/- a fixed number. They work fine.
The ActualSpread Daily returns fine as seen in the top Pane, changing once a day and holding its value throughout the day. The problem lies in the 2nd pane, this is the STD Dev data series.
Ive probably incorrectly typed something somewhere, but havent been able to figure it out....
Size:
Color:
When, like me, you have a dozen of projects in development and a recurring deadline, it's hard to keep track with those script variations which materialize again after apparently helping with the last variation for the final time.
However, your once little project has grown to pretty involving - from a pair trading script, you're building a solution with deviation bands, intraday time frame, an index on-the-fly with custom weights... where it stops?
So, when you have over 50 support tickets open, helping with another "couple of changes" is not nearly as easy as you think it sounds. Help me to help you - explain what you want in great detail, stressing the use of intraday time frame (that appeared only lately) and present the complete code as is - not the incomplete one posted above, to save time on filling in the missing variables. Thank you.
Size:
Color:
Eugene, yes, fully understood. I have apparently underestimated the complexity of this. I was trying to keep things short and easy, which was making things worse not easier.
Let me start again with the problem I am having. As the strategy stands now, I am trying to create an intraday Pairs trading system that uses a set of bands based on Daily Standard Deviations. (with your help so far) I have the intraday Spread with a set of bands. the problem I am having now, is the ShortSTD and LongSTD DataSeries.
CODE:
Please log in to see this code.
It returns a value for the first bar of the intraday, but returns nothing for the rest of the day. This is visible in the screenshot posted above.
To check that the problem lies with this DataSeries, I also plotted the ActualSpreadDaily DataSeries and this returns the value exactly as it should. The Bars also plot fine if I replace the ShortSTD/LongSTD DataSeries with something else.
So, I would like to figure out how to display these LongSTD and ShortSTD DataSeries correctly. The above screenshot should help make my problem clearer.
Thanks, and apologies for not making it easier to understand from the beginning.
Thanks.
Here is the code in full (excluding the buy/Sell signals)
CODE:
Please log in to see this code.
Size:
Color:
Thank you for the detailed explanation, much appreciated. I see the "problem" with the ShortSTD/LongSTD, but it does not look like a problem to me. The period (10/30) is too tight for intraday bars, and the (synched to daily data) ActualSpreadDaily series are static (i.e., have the same value throughout the day), explaining what you see.
Switch the scale to, say, 60-minute. Drop a 10..30 period moving average on to the ActualSpreadDaily. You'll see the same behavior.
Size:
Color:
Eugene, thank you for the reply, you have helped me see the error. An error in my understanding rather than an error in the coding.
I would like to Synch the ShortSTD/LongSTD Dataseries to Daily data as well so they too would show as static throughout the day. so the 10 and 30 actually represent 10 days and 30 days even on an intraday chart.
Is it as simple as moving the data series up to the SetScaleDaily section? (Which I will try while I wait for a reply)
Thank you again
Size:
Color:
tried moving the DataSeries up to Set Scale Daily Section but no luck...
CODE:
Please log in to see this code.
Size:
Color:
QUOTE:
I would like to Synch the ShortSTD/LongSTD Dataseries to Daily data as well so they too would show as static throughout the day.
Wrap them in a SetScaleDaily/RestoreScale block.
Size:
Color:
Sorry to keep bugging you on this Eugene, I thought I understood what you meant, and tried the following. HOwever it came back with a runtime error. DataSeries do not have equal number of values for mathematical operation.
Here is what I thought you meant
CODE:
Please log in to see this code.
And here is the full code just in case
CODE:
Please log in to see this code.
Size:
Color:
You got it right. Your code runs on my test symbols fine.
QUOTE:
DataSeries do not have equal number of values for mathematical operation.
Could you post the full error message text (i.e. what's there below this line)?
Size:
Color:
Apoliges, there was a mistake in the code, it was referencing the wrong spread. I'm trying to get the 30 day Standard Deviation of the ActualSpreadDaily Using the code as below, still doesnt get the ShortSTD and LongSTD to hold its value throughout the intraday.
CODE:
Please log in to see this code.
CODE:
Please log in to see this code.
Size:
Color:
Still havent figured out this problem yet. The Daily STD Dev values, still dont hold their values on an intraday chart apart outside of the first open of theday. Would really like to figure this out
Size:
Color:
This in unrelated, but still, there's a mistake here:
CODE:
Please log in to see this code.
Obviously, both
closeDaily1 and
closeDaily2 point to the same symbol.
SetContext should precede, but I'd suggest rewriting the snippet w/o using
SetContext this way:
CODE:
Please log in to see this code.
(btw, is the shifting the series purposeful?)
Re: LongSTD, ShortSTD -- I'm puzzled too as I couldn't find a clear explanation for this phenomenon, but am noticing that it occurs a) on high-granularity data (e.g. 5-minute, not on 60-minute bars), and b) just for StdDev/StdError series (e.g. not with SMA).
Robert? Any idea is welcome.
Size:
Color:
I'm not following the thread (too long to start with now), but if you boil it down to a simple example, then sure I'll take a look.
Size:
Color:
Sure. What we want here is to persist the daily StdDev series through the whole intraday session like the SMA (uncomment to feel the difference):
CODE:
Please log in to see this code.
Size:
Color:
We'll have to call a bug a "bug" until proven otherwise. The problem seems to be re-scaling
ActualSpreadDaily in the Daily time frame for the second time after having Synchronized it in the base time frame. Re-ordering the operations, these [equivalent] solutions appear to work properly -
Solution #1
CODE:
Please log in to see this code.
Solution #2 - just do it in the same SetScaleDaily operation.
CODE:
Please log in to see this code.
Size:
Color:
QUOTE:
Solution #2 - just do it in the same SetScaleDaily operation.
*facepalm* Thank you :)
Size:
Color:
Guys, Just applied Solution 2 that Cone supplied, seems to be working exactly as expected now. Charts showing fine and entries look right. Thanks a lot guys for sticking this one out.
Size:
Color: