Defining multiple criteria for a buy
Author: Tobey
Creation Date: 12/28/2009 10:47 AM
profile picture

Tobey

#1

This strategy runs but it doen't find the buy points I see on the chart.

I think it says:

if Close is less than the 13week High plus 1%
and Close is greater than the 13week high minus 5%
and the last bar close is greater than the close of the bar before
and the volume for the last 26 bars is 150% of the volume for the last 1300 bars

put in a limit order at no more than 4% above the 13week high.



But I sure you'll say there's another fine mess you've gotten your self into.

Thanks for the help
Tobey

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

Eugene

#2
#1 It's unclear to me why are you shifting the 1690-day High by 546 bars, but it is not in your rules.
#2 "Sum.Series(Volume, 26) / 26" = SMA.Series( Volume,26)
CODE:
Please log in to see this code.

#3 "if Close is less than the 13week High plus 1%" - I suggest taking a look in the WealthScript Programming Guide > Multi-Time Frame Analysis > Intraday/Daily.

Here's your reworked code:
CODE:
Please log in to see this code.
profile picture

Tobey

#3
Hi Eugene,

Thank You!

I'll look at Multi-Time Frame Analysis. I've been calculting the bars need to match the daily data for a given time period. Go ahead and laugh!

The shift in the 13 week high is equal to 4 weeks. The idea is to find stocks that have built a base and are just starting to brakout to new highs.

Thanks Again!
Tobey
profile picture

Tobey

#4
Hi Eugene,

I've been going over your reply and looking in the manual as you suggested. It looks like I could simplify things. here are a few questions that would help me understand what I'm doing before I go off and code myself into another night mirror.

Thanks
Tobey

1) Converting to daily data

If we are at 1pm and we convert intraday data to daily data is the day we get from 1pm today to 1pm yesterday? Or is yesterday considered 1 day and today’s data consider a half day?

2) “It's unclear to me why are you shifting the 1690-day High by 546 bars, but it is not in your rules.”

I’m looking for new highs after ad least 4 weeks of consolidation. On the chart I’m drawing a 13wk high line shifted by 4wks to visual see the high that I want to see broken.

To include this in my strategy it sounds like I’d be better off subtracting bars ie:

SetScaleWeekly();
DataSeries wh = Highest.Series( High[bars – 4 ],13 );
RestoreScale();

Is this correct?

3) I look at the Multi-Time Frame Analysis > Intraday/Daily.

If I understand it correctly
I should add SetScaleDaily (); to all the indicators on my basic daily chart. That way they would be plotted correctly when I switched to intraday data.

Is this correct?

4) Using SetScaleCompressed (); on Intraday data.

If I SetScaleCompressed (); on intraday data for the shortest time period It give me same results for an indicator on a longer time period ie:

SetScaleCompressed ( 15 ); will show me the same indicator on a 30 min chart and a 15 min chart.

And SetScaleCompressed ( 5 ); will show me the same indicator on a 30 min chart and a 15 min chart and a 5 min chart.

Is this correct?
profile picture

Eugene

#5
#1 - We get the data from today's open to 1pm today.
#2 - No. The correct way to shift is through using the shift (>>) operator in C#. Look up DataSeries in the QuickRef.
CODE:
Please log in to see this code.

#3 - No. You should not call SetScaleDaily() on daily scale. Only when switching to intraday data.
#4 - No. You can't SetScale* to a shorter time period (e.g. SetScaleCompressed(15) from the 30-minute bar scale), only longer.
profile picture

Tobey

#6
Hi Eugene,

Thanks!

Re #3 then I should have one chart/strategy for daily data and another copy of the chart/strategy using SetScaleDaily (); to show the same indicators with intraday data?

Thank you
Tobey
profile picture

Eugene

#7
#3

Please rephrase it and make it comprehensible to me. I don't understand the point of using "SetScaleDaily ();" if it is not in your rules which refer to weekly data all the way.

When you say e.g. 'if Close is less than the 13week High...', you didn't mean it's intraday data, but daily, right?
profile picture

Tobey

#8
Hi Eugene,

Ok. Lets talk about a chart with 10 Day moving average.

On a daily chart that would be
SMA MyIndicator = SMA.Series( Close,10 );

If I want to see the same indicator on a 30min Chart that would be
SMA MyIndicator = SMA.Series( Close,130 );

And if I want to see the same indicator on a 15min Chart that would be
SMA MyIndicator = SMA.Series( Close,260 );

This requires saving 3 charts.

On intraday data, if I use
SetScaleDaily();
SMA MyIndicator = SMA.Series( Close,10 );
RestoreScale();
I would need only one intra day chart to see the 10 day moving average correctly.

But I would also need a daily chart with
SMA MyIndicator = SMA.Series( Close,10 );
To see the 10 day moving average on a daily chart.

This would only require 2 charts

What I am wondering is can I do it with 1 chart, by coding the 10 moving average
SetScaleDaily();
SMA MyIndicator = SMA.Series( Close,10 );
RestoreScale();
On my daily chart.
I know it is not needed on the daily chart.
But if it works, it would allow me to use one chart that see the 10 day moving average correctly on a daily chart, a 30min chart and 15min chart.

It would be a one chart fits all solution.

Thanks again! I hope this makes it clear
Tobey
profile picture

Eugene

#9
Yes, you can have a simple solution by noticing your Bars scale and acting accordingly. There are several helpers to determine in which time frame your chart is: BarInterval, DataScale, Scale and IsIntraday. Look them up in the QuickRef, code the "if ... else" logic, and you'll have just 1 strategy for all periods.
profile picture

Tobey

#10
Hi Eugene,

Thanks! that would be get. I'll check it out

Tobey
profile picture

Tobey

#11
Hi Eugene,
I used
SetScaleDaily();
SMA MyIndicator = SMA.Series( Close,10 );
RestoreScale();
And it allowed me to switch nicely between Daily 30min and 15min charts displaying the correct number for the 10 day Moving average. However the graph you get displays the aveerage in a daily stair step pattern instead of a moving line.

In the quick ref it said BarInterval would return 0 for weekly data 30 for 30 min data etc.
So it sounded like i could use it in a series of if else statements to convert the 10 day mov to correct number of bars for the time period.

CODE:
Please log in to see this code.


However it's not as simple as it sounds. It gives an error
Cannot implicitly convert type "int" to "bool" and a search for the error doesn't find anything I can understand.

Thanks again for the help. I'm sure I'm driving you to drink! Good thing it's New Years Eve! Have a good one!
Tobey



profile picture

Eugene

#12
QUOTE:
And it allowed me to switch nicely between Daily 30min and 15min charts displaying the correct number for the 10 day Moving average. However the graph you get displays the aveerage in a daily stair step pattern instead of a moving line.

What's wrong with that? Nothing: this is how it meant to be. Correctly scaled data series should have a daily stair-stepped look on intraday charts.

I feel like not completely following you after having correctly helped you with the initial request. What you're doing, at this time, does not seem to ring a bell for me. We are used to work with multiple time frames the way it's described in the Programming Guide chapter pointed above. Let's stop and think first:

a) why are you trying to match the indicator periods of different time frames in the manner of your last code snippet), and
b) why aren't you following the Programming Guide patterns?
profile picture

Tobey

#13
Hi Eugene,

There is nothing wrong with the stair step pattern.

I'm just use to seeing moving averages a snaking pattern.

If I have a 10 week moving average on a weekly chart, I match it with a 50 day nmoving average on a daily chart and they both have a snake look.

So in my twisted thinking a 10 day moving average on a daily chart would be equal to a 130 bar moving average on a 30 min chart and they would both snake across the chart.

So that's why I was trying to write the code the way I did.

Thanks again
Tobey
profile picture

Tobey

#14
Hi Eugene,

I've been thinking about the problem.

Even if I used the stair step moving averages, If I want one chart that will work daily and intraday data sets I'm going to need an if else statement based on BarInterval to not graph some things like a 200 day moving average on a 15 min chart. For example, when I graph the 200 day moving from my daily chart on the 15 min chart it compresses the intraday data to a small portion of the top of the chart.

Thanks again for your help. I've very happy with the results of the stragegy you help get running the other day!
Tobey
profile picture

Eugene

#15
QUOTE:
If I have a 10 week moving average on a weekly chart, I match it with a 50 day nmoving average on a daily chart and they both have a snake look.

We're talking about different things. A 50-day moving average is not necessarily equal to a 10-week moving average. What about a trading halt? Market holiday? There could be less days in 10 weeks than 50. Any series from the higher time frame should have a stair step look, that's the way it is.

Anyway, here's one more code snippet to help you:
CODE:
Please log in to see this code.
profile picture

Tobey

#16
Hi Eugene,

Yes your right! Even with a perfect match of days the resulting number is not exactly the same.
Now I've got someting to think.

Thanks for the code. That will give me something to work with.

Have a great weekend!
Happy New Year
Tobey
profile picture

Eugene

#17
Happy New Year to you too, Tobey.
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).