Platinum Customer
Joined: 3/19/2008 Posts: 64
|
Hello Bruce / All,
I posted this question in the Realcode thread but it appears that forum is less active than the one here so I am reposting.
Essentially, the question is this:
1.) I have a boolean condition that plots on a weekly timeframe, while looking at a daily chart.
On a weekly candle, the question is --> price.close > price.maxclose(1,1) and volume.value > volume.value(1) ;
To do this I call the weekly timeframe using the methods in this post from Bruce.
Next,
2.) I plot based on
If weekly condition = true then plot = weekly value low
I make the plot shape a line and this plots a horizontal line at one value, the low over the weekly range that the weekly condition passes, but because it is on a daily chart, it actually produces 5 values, all over the course of the week, plotted at that week's low.
3.) This works perfectly, without the use of realtime data. This is because in hindsight, the algo can always find the lowest ultimate low in a given pass week.
4.) When realtime data is introduced, not only can I not get the contiguous five bar plot at the same lowest low value (ie the lowest weekly low on a pass week), but the code doesn't know how cancel prior values in exchange for new ones:
Suppose Monday is a pass for the weekly condition that week. The plot will go under Monday's low, as that is the weekly low on a pass week.
Now, Tuesday is still a pass for the weekly condition, however, the low is lower than monday's low. The plot SHOULD replot under both Monday and Tuesday using Tuesday's low, effectively canceling and replacing Monday's output. But instead keeps the plot on Monday under Monday's low, and under Tuesday's low for Tuesday.
Now suppose Wednesday is a sharp move down, such that it cancels the weekly pass. Also, by chance, price makes a new low over Monday and Tuesday. It should now cancel the entire plot since the weekly pass is not true, deleting the plot under Monday and Tuesday. IE, it cancels it based on new data. What actually happens, is it will correctly plot nothing for Wednesday, but won't cancel the pass for Monday and Tuesday.
Now, let's say Thursday makes a recover, such that on Thursday, the weekly condition is once again a pass. It should now plot Wednesday's low (the lowest value on a weekly timeframe for the weekly pass) under Monday, Tuesday, Wednesday, and Thursday.
Assuming Friday is no change, the week is still a pass week, then Wednesday's low will now plot under Friday as well.
Do you have any suggestions on how I can implement this?
Thanks again Bruce for your tireless (and often valiant) efforts to help us SF users.
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Maybe something similar to the following RealCode Indicator? Make sure you plot it using the Shape Plot Style.
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Hindsight Example
'|******************************************************************
Static PrevClose As Single
Static WeekLow As Single
Static WeekVol(1) As Single
Static WeekStart As Integer
If isFirstBar Then
PrevClose = Single.NaN
WeekLow = Single.NaN
WeekVol(0) = Single.NaN
WeekVol(1) = Single.NaN
Else If Price.DateValue.DayOfWeek < Price.DateValue(1).DayOfWeek Then
PrevClose = Price.Last(1)
WeekLow = Price.Low
WeekVol(1) = Volume(0)
WeekVol(0) = Volume.Value
WeekStart = CurrentIndex
Else
WeekLow = System.Math.Min(WeekLow, Price.Low)
WeekVol(0) += Volume.Value
End If
Plot = Single.NaN
If isLastBar OrElse _
Price.DateValue.DayOfWeek > Price.DateValue(-1).DayOfWeek Then
If Price.Last > PrevClose AndAlso _
Volume(0) > Volume(1) Then
For i As Integer = WeekStart To CurrentIndex
AddToOutput(Price.Bar.DateValue(i), WeekLow)
Next
End If
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
Platinum Customer
Joined: 3/19/2008 Posts: 64
|
That worked perfectly, thank you Bruce.
|