Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Bruce Take a look at these two realcodes below please.
The first one is the Since Max that counts the number of bars since last 63 day high and the 2nd one counts the number Acc/Dis days since the same 63 day high.
Since Max
'# Period = UserInput.Integer = 62
'# Cumulative
Static Count As Single
Static Valid As Boolean
If isFirstBar Then
Count = 500
Valid = False
End If
If Valid = True Then Count += 1
If CurrentIndex >= Period AndAlso _
Price.High > Price.MaxHigh(Period, 1) * 1.005 Then
Count = 0
Valid = True
End If
Plot = Count
Acc/Dis since high
'# AFA = condition.AccumulationATRw/AvgVolume
'# DFA = condition.DistributionATRw/AvgVolume
Static Count(2) As Single
If isFirstBar Then
Count(0) = Single.NaN
Count(1) = Single.NaN
Count(2) = Single.NaN
Else If CurrentIndex >= 64 AndAlso _
Price.High(1) > Price.MaxHigh(62, 2) * 1.005 Then
Count(0) = 0
Count(1) = 0
Count(2) = 0
End If
If AFA.Value = True Then Count(0) += 1
If DFA.Value = True Then Count(1) += 1
Count(2) += 1
Plot = 100 * ((Count(0) - Count(1)) / Count(2))
In the 2nd realcode Count(2) should be the same value as the 1st formula but for some reason its a day off.
Change the last line in the 2nd realcode to Plot = Count(2) and you will see how Since Max plots 0 when price makes a new high but the 2nd realcode adds a day to the previous value which is incorrect.
I need to have the Count(2) count the days the same way Since Max does.
I changed the 2nd realcode to below and its still a day off since on the day of the new high it plots 1 not 0
'# AFA = condition.AccumulationATRw/AvgVolume
'# DFA = condition.DistributionATRw/AvgVolume
Static Count(2) As Single
Static Valid As Boolean
If isFirstBar Then
Count(0) = Single.NaN
Count(1) = Single.NaN
Count(2) = Single.NaN
Valid = False
End If
If CurrentIndex >= 63 AndAlso _
Price.High > Price.MaxHigh(62, 1) * 1.005 Then
Count(0) = 0
Count(1) = 0
Count(2) = 0
Valid = True
End If
If AFA.Value = True Then Count(0) += 1
If DFA.Value = True Then Count(1) += 1
If Valid = True Then Count(2) += 1
Plot = Count(2)
If today is the NH it should not count in any of the Counts.
I've been playing with this for hours and I can't get it to work right.
This is my ACC and DIS realcodes if you need to test this and you can look at ADTN from 9/4/2003 to 10/3/2003. The pull back is 20 days in length. 9/4 should not count in any of the counts and all count should go to 0 on 10/3 since we are at the high.
ACC
'# Cumulative
Static ATR As Single
Static TR As Single
Static sumWeight As Single
Static termRatio As Single = 13 / 14
Static AvgV As Single
If isFirstBar Then
sumWeight = 1
TR = Price.High - Price.Low
AvgV = 0
Else
TR = System.Math.Max(Price.High, Price.Last(1)) - _
System.Math.Min(Price.Low, Price.Last(1))
AvgV += Volume.value(1) / 30
End If
If CurrentIndex >= 31 Then AvgV -= Volume.value(31) / 30
Dim Weight As Single = 1 / sumWeight
ATR = ATR * (1 - Weight) + Weight * TR
sumWeight = sumWeight * termRatio + 1
If Volume.value > AvgV AndAlso _
Price.Last - Price.Last(1) >= ATR Then Pass
Dis
'# Cumulative
Static ATR As Single
Static TR As Single
Static sumWeight As Single
Static termRatio As Single = 13 / 14
Static AvgV As Single
If isFirstBar Then
sumWeight = 1
TR = Price.High - Price.Low
AvgV = 0
Else
TR = System.Math.Max(Price.High, Price.Last(1)) - _
System.Math.Min(Price.Low, Price.Last(1))
AvgV += Volume.value(1) / 30
End If
If CurrentIndex >= 31 Then AvgV -= Volume.value(31) / 30
Dim Weight As Single = 1 / sumWeight
ATR = ATR * (1 - Weight) + Weight * TR
sumWeight = sumWeight * termRatio + 1
If Volume.value > AvgV AndAlso _
Price.Last(1) - Price.Last >= ATR Then Pass
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
QUOTE (thnkbigr) In the 2nd realcode Count(2) should be the same value as the 1st formula but for some reason its a day off.
Change the last line in the 2nd realcode to Plot = Count(2) and you will see how Since Max plots 0 when price makes a new high but the 2nd realcode adds a day to the previous value which is incorrect.
I need to have the Count(2) count the days the same way Since Max does.
In the first RealCode it sets the Count to 0 and doesn't start adding to it until the next Bar. In the second RealCode, it sets the Count to 0 and starts adding to it before anything is output. There is a very good reason it does this however. You can't divide things by zero.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Why can't you divide by 0.
When you divide a number by 0 shouldn't the outcome be 0. So on the day of NH the A/D should plot 0
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
No, dividing something by zero does not result in zero. Think about it this way:
100 / 10 = 10
100 / 5 = 20
100 / 2 = 50
100 / 1 = 100
100 / .5 = 200
100 / .2 = 500
100 / .1 = 1000
As the denominator gets smaller, the result gets bigger, not smaller. Dividing something by zero is meaningless, but as the denominator approaches zero, the result doesn't approach zero, the result approaches infinity.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Bruce,
I totally understand what you are saying but in this case we are always dividing the smaller # by the bigger one. It is impossible for the difference between the Acc and Dis days to be more than the total number of days in a period.
The numerator is always the smaller number and we will never have fractions in this realcode either.
On the day of the new high all Counts, Count(0), Count(1) and Count(2) should all be at 0. They start counting only from the day after which the denominator will be 1 and this day can either be an Acc or Dis day or neither of them so it's either 0/1 or 1/1.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
It doesn't matter. 0 divided by 0 is still absolutely meaningless in normal (real number based) arithmetic (the result is not a number). You could argue that it is 1, 0 or infinity with logic that might seem to make sense (but all three answers would be equally valid in that they are all incorrect).
It's pretty easy to make all of the Counts equal zero when there is a New High:
'# AFA = condition.AccumulationATRw/AvgVolume
'# DFA = condition.DistributionATRw/AvgVolume
Static Count(2) As Single
If isFirstBar Then
Count(0) = Single.NaN
Count(1) = Single.NaN
Count(2) = Single.NaN
Else If CurrentIndex >= 64 AndAlso _
Price.High > Price.MaxHigh(62, 1) * 1.005 Then
Count(0) = 0
Count(1) = 0
Count(2) = 0
Else
If AFA.Value = True Then Count(0) += 1
If DFA.Value = True Then Count(1) += 1
Count(2) += 1
End If
Plot = 100 * ((Count(0) - Count(1)) / Count(2))
It will even Plot, but only because of the built in error trapping. If you Plot it using the Shape Plot Style, there won't be any Plots where there is a new High because the computer knows dividing zero by zero doesn't produce a numeric result.
You can force the Indicator to Plot zero when there is a New High if you want, but it is not because 0 divided by 0 equals 0 (it doesn't) but because we can just arbitrarily Plot it instead of doing the math:
'# AFA = condition.AccumulationATRw/AvgVolume
'# DFA = condition.DistributionATRw/AvgVolume
Static Count(2) As Single
If isFirstBar Then
Count(0) = Single.NaN
Count(1) = Single.NaN
Count(2) = Single.NaN
Plot = Single.NaN
Else If CurrentIndex >= 64 AndAlso _
Price.High > Price.MaxHigh(62, 1) * 1.005 Then
Count(0) = 0
Count(1) = 0
Count(2) = 0
Plot = 0
Else
If AFA.Value = True Then Count(0) += 1
If DFA.Value = True Then Count(1) += 1
Count(2) += 1
Plot = 100 * ((Count(0) - Count(1)) / Count(2))
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Thanks
I understand what you are saying but in the case I had to force it to plot 0 on the NH.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Bruce,
Where am i going wrong in here?
You wrote the real code below earlier this year that plots the difference in % between the count of Acc and Dis days in the last 20 days. All Acc and Dis days have the same power of 1 in the counts.
'# AFA = condition.AccATRW/VolumeYesterday
'# DFA = condition.DisATRW/VolumeYesterday
'# OfBars = UserInput.Integer = 20
Static Count(1) As Integer
If isFirstBar Then
Count(0) = 0
Count(1) = 0
End If
If AFA.Value = True Then Count(0) += 1
If DFA.Value = True Then Count(1) += 1
If CurrentIndex >= OfBars Then
If AFA.Value(OfBars) = True Then
Count(0) -= 1
End If
If DFA.Value(OfBars) = True Then
Count(1) -= 1
End If
If Count(0) + Count(1) > 0 Then
Plot = 100 * (Count(0) - Count(1)) / (Count(0) + Count(1))
Else
Plot = 0
End If
Else
Plot = Single.NaN
End If
What I tried to do below is to give the Acc and Dis days depending on their size a different power. I have gone over this 10 times to see why its not plotting right. Can you see what I am missing please.
The indicators that their given name start with A are Acc and those with D are Dis. Count(0) is suppose to count Acc and Count(1) is suppose to count Dis.
'# AA5 = condition.Acc1/2ATR
'# AA1 = condition.AccumulationATRw/AvgVolume
'# AA2 = condition.AW/AvgV2*ATR
'# AY5 = condition.Acc1/2ATRYesVol
'# AY1 = condition.AccumulationATR
'# AY2 = condition.AYesV2*ATR
'# DA5 = condition.Dis1/2ATR
'# DA1 = condition.DistributionATRw/AvgVolume
'# DA2 = condition.DW/AvgV2*ATR
'# DY5 = condition.Dis1/2ATRYesVol
'# DY1 = condition.DistributionATR
'# DY2 = condition.DYesV2*ATR
'# OfBars = UserInput.Integer = 20
Static Count(1) As Integer
If isFirstBar Then
Count(0) = 0
Count(1) = 0
End If
If AA5.Value = True Then Count(0) += 0.5
If AA1.Value = True Then Count(0) += 1
If AA2.Value = True Then Count(0) += 2
If AY5.Value = True Then Count(0) += 0.5
If AY1.Value = True Then Count(0) += 1
If AY2.Value = True Then Count(0) += 2
If DA5.Value = True Then Count(1) += 0.5
If DA1.Value = True Then Count(1) += 1
If DA2.Value = True Then Count(1) += 2
If DY5.Value = True Then Count(1) += 0.5
If DY1.Value = True Then Count(1) += 1
If DY2.Value = True Then Count(1) += 2
If CurrentIndex >= OfBars Then
If AA5.Value(OfBars) = True Then
Count(0) -= 0.5
End If
If AA1.Value(OfBars) = True Then
Count(0) -= 1
End If
If AA2.Value(OfBars) = True Then
Count(0) -= 2
End If
If AY5.Value(OfBars) = True Then
Count(0) -= 0.5
End If
If AY1.Value(OfBars) = True Then
Count(0) -= 1
End If
If AY2.Value(OfBars) = True Then
Count(0) -= 2
End If
If DA5.Value(OfBars) = True Then
Count(1) -= 0.5
End If
If DA1.Value(OfBars) = True Then
Count(1) -= 1
End If
If DA2.Value(OfBars) = True Then
Count(1) -= 2
End If
If DY5.Value(OfBars) = True Then
Count(1) -= 0.5
End If
If DY1.Value(OfBars) = True Then
Count(1) -= 1
End If
If DY2.Value(OfBars) = True Then
Count(1) -= 2
End If
If Count(0) + Count(1) > 0 Then
Plot = Count(0) - Count(1)
Else
Plot = 0
End If
Else
Plot = Single.NaN
End If
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
Approach 1:
Why not sticjk in some debug output lines
log.info("Count(0)= " & count(0) & " Count(1)= " & count(1))
Along with
Log.info("AA5 =" & AA5.value)
Log.info("AA1 =" & AA1.value)
Log.info("AA2 =" & AA2.value)
etc.
etc
In conjunction with setting the number of bars to a small number, like 50.
Approach 2:
Add Try-Catch code
Try
...
.. your code.
...
Catch ex as system.exception
log.info("Exception: " & ex.message)
Finally
End Try
My quess would be the the condition values are delayed and you are getting leading edge exceptions due to array bounds problems.. Due to the number of indicators, 12, the exception total of 50 is easy to reach causing the process to stop.
Have you looked at the debug log to see if StckFinder is announcing and problem?
I expect "Calculation stopped, too many errso" or some such.
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
jas0501,
I don't know much about debug log.
I just took the way Bruce wrote the formula with two indicators and used it to write mine.
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
QUOTE (thnkbigr)
jas0501,
I don't know much about debug log.
I just took the way Bruce wrote the formula with two indicators and used it to write mine.
If you are going to learn about and use debug.log, it is equivalent to having a flashlight not learning about it, and walking around in the dark!
The only way you can get an understanding of what your code is doing as it proceeeds is by using the debugging aids. log.info being the simplest along in conjunction with debug log window.
Still didn't answer my question, What does the debug log say when you currently run your code?
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
which debug are you talking about?
The one under the settings/Options or the help?
I have zero exprince with this part of the software
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
QUOTE (thnkbigr)
which debug are you talking about?
The one under the settings/Options or the help? Yes
I have zero exprince with this part of the software So get some!
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
I have the one from the Help up and it doesn't tell me anything about the indicator. I habe no idea what this is.
How is it that this works but not the indicator that is just suppose to look at the last 20 days?
Below is plotting the degree of Acc/Dis from the bottom to the top using the same 12 indicators and its accurate. The earlier one I posted is suppose to plot the same thing but over the last 20 days.
'# PPO = indicator.MyPPO
'# AA5 = condition.Acc1/2ATR
'# AA1 = condition.AccumulationATRw/AvgVolume
'# AA2 = condition.AW/AvgV2*ATR
'# AY5 = condition.Acc1/2ATRYesVol
'# AY1 = condition.AccumulationATR
'# AY2 = condition.AYesV2*ATR
'# DA5 = condition.Dis1/2ATR
'# DA1 = condition.DistributionATRw/AvgVolume
'# DA2 = condition.DW/AvgV2*ATR
'# DY5 = condition.Dis1/2ATRYesVol
'# DY1 = condition.DistributionATR
'# DY2 = condition.DYesV2*ATR
Static Min As Single
Static Count(3) As Single
Static MinBar As Single
Static AccDis As Single
Static Triggered As Boolean
If isFirstBar Then
Min = Price.Low
Count(0) = 0
Count(1) = 0
Count(2) = 0
Count(3) = 0
MinBar = Single.NaN
AccDis = Single.NaN
Triggered = False
End If
If PPO.Value >= -1 Then
Count(0) = Single.NaN
Else If PPO.Value < -1 AndAlso _
PPO.Value(1) >= -1 Then
Count(0) = 1
Else
Count(0) += 1
End If
If PPO.Value >= -4 Then
Count(1) = Single.NaN
Else If PPO.Value < -4 AndAlso _
PPO.Value(1) >= -4 Then
Count(1) = 1
Else
Count(1) += 1
End If
If Count(0) > 10 OrElse _
Count(1) > 5 Then
If Price.Low(1) <= Min Then
Min = Price.Low(1)
MinBar = CurrentIndex - 1
End If
Else If Count(0) = 10 OrElse _
Count(1) = 5 Then
Min = Price.MinLow(21, 1)
For i As Integer = 1 To 21
If Price.Low(i) = Min Then
MinBar = CurrentIndex - i
Triggered = True
Exit For
End If
Next
Else If CurrentIndex >= 1 AndAlso _
Triggered = False AndAlso _
Price.Low(1) <= Min Then
Min = Price.Low(1)
MinBar = CurrentIndex - 1
End If
If Price.High > Price.MaxHigh(62, 1) * 1.005 Then
AccDis = 0
Count(2) = 0
Count(3) = 0
For i As Integer = 0 To CurrentIndex - MinBar - 1
If AA5.Value(i) = True Then Count(2) += 0.5
If AA1.Value(i) = True Then Count(2) += 1
If AA2.Value(i) = True Then Count(2) += 2
If AY5.Value(i) = True Then Count(2) += 0.5
If AY1.Value(i) = True Then Count(2) += 1
If AY2.Value(i) = True Then Count(2) += 2
If DA5.Value(i) = True Then Count(3) += 0.5
If DA1.Value(i) = True Then Count(3) += 1
If DA2.Value(i) = True Then Count(3) += 2
If DY5.Value(i) = True Then Count(3) += 0.5
If DY1.Value(i) = True Then Count(3) += 1
If DY2.Value(i) = True Then Count(3) += 2
Next
AccDis = Count(2) - Count(3)
End If
plot = AccDis
|
|
Worden Staff
Joined: 10/7/2004 Posts: 218
|
You can see the Debug Log by clicking Help in StockFinder
|
|
Registered User Joined: 10/26/2009 Posts: 2
|
i did
thx
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Bruce,
Please take look at the indicator i posted on Sunday, October 25, 2009 2:35:20 PM and let me know why it does not plot right.
I use the same 12 indicators in the indicator I posted on Monday, October 26, 2009 3:20:24 PM and that seems to be working just fine.
thx
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
thnkbigr,
I don't have a Layout with all of your Indicators for which I can run a test, but you might want to try something similar to the following (I added a Start variable for when it should be safe to start subtracting - not sure if it will work or not):
'# AA5 = condition.Acc1/2ATR
'# AA1 = condition.AccumulationATRw/AvgVolume
'# AA2 = condition.AW/AvgV2*ATR
'# AY5 = condition.Acc1/2ATRYesVol
'# AY1 = condition.AccumulationATR
'# AY2 = condition.AYesV2*ATR
'# DA5 = condition.Dis1/2ATR
'# DA1 = condition.DistributionATRw/AvgVolume
'# DA2 = condition.DW/AvgV2*ATR
'# DY5 = condition.Dis1/2ATRYesVol
'# DY1 = condition.DistributionATR
'# DY2 = condition.DYesV2*ATR
'# OfBars = UserInput.Integer = 20
Static Count(1) As Integer
Static Start As Integer
If isFirstBar Then
Count(0) = 0
Count(1) = 0
Start = CurrentIndex + OfBars
End If
If AA5.Value = True Then Count(0) += 0.5
If AA1.Value = True Then Count(0) += 1
If AA2.Value = True Then Count(0) += 2
If AY5.Value = True Then Count(0) += 0.5
If AY1.Value = True Then Count(0) += 1
If AY2.Value = True Then Count(0) += 2
If DA5.Value = True Then Count(1) += 0.5
If DA1.Value = True Then Count(1) += 1
If DA2.Value = True Then Count(1) += 2
If DY5.Value = True Then Count(1) += 0.5
If DY1.Value = True Then Count(1) += 1
If DY2.Value = True Then Count(1) += 2
If CurrentIndex >= Start Then
If AA5.Value(OfBars) = True Then
Count(0) -= 0.5
End If
If AA1.Value(OfBars) = True Then
Count(0) -= 1
End If
If AA2.Value(OfBars) = True Then
Count(0) -= 2
End If
If AY5.Value(OfBars) = True Then
Count(0) -= 0.5
End If
If AY1.Value(OfBars) = True Then
Count(0) -= 1
End If
If AY2.Value(OfBars) = True Then
Count(0) -= 2
End If
If DA5.Value(OfBars) = True Then
Count(1) -= 0.5
End If
If DA1.Value(OfBars) = True Then
Count(1) -= 1
End If
If DA2.Value(OfBars) = True Then
Count(1) -= 2
End If
If DY5.Value(OfBars) = True Then
Count(1) -= 0.5
End If
If DY1.Value(OfBars) = True Then
Count(1) -= 1
End If
If DY2.Value(OfBars) = True Then
Count(1) -= 2
End If
If Count(0) + Count(1) > 0 Then
Plot = Count(0) - Count(1)
Else
Plot = 0
End If
Else
Plot = Single.NaN
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
I get Start is not declared
Do I have to add Static Start As Single at the begining?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You would want Static Start as Integer.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Bruce,
I have no idea how my shared chart will come through. I hope it comes up they way I shared it. I just shared it under AD.
If not just ignore the top price pane and look at the 2nd price pane and the 3 panes below it.
The A/D Last Days 20 in Red is the indicator I originaly posted and the green one is yours with the Start thing you added and they are both the same.
Take a look at LVS as an example please. In the 2nd price pane there are 2 indicators that label the total Acc and Dis in the Wave up (Green) and the Retracement (Yellow) using the same 12 Rules and they are both accurate.
For example from the lows of 3/9 to the peak of 5/5 LVS had 14.5 points of Acc and only 1.5 points of distribution in the retracement that followed from the peak of 5/5 to the lows of 7/8. This is accurate.
Now what I am trying to do is just to measure the last 20 days regardless of the wave pattern and it is not coming out right. From today count the Acc and Dis over the last 20 days.
You wrote the indicator below earlier this year to do this but just using 2 of the Acc and Dis rules and they all have a power of 1 in the count. So I used this to write the one in Red that gives the Acc/Dis days different power.
'# AFA = condition.AccATRW/VolumeYesterday
'# DFA = condition.DisATRW/VolumeYesterday
'# OfBars = UserInput.Integer = 20
Static Count(1) As Integer
If isFirstBar Then
Count(0) = 0
Count(1) = 0
End If
If AFA.Value = True Then Count(0) += 1
If DFA.Value = True Then Count(1) += 1
If CurrentIndex >= OfBars Then
If AFA.Value(OfBars) = True Then
Count(0) -= 1
End If
If DFA.Value(OfBars) = True Then
Count(1) -= 1
End If
If Count(0) + Count(1) > 0 Then
Plot = 100 * (Count(0) - Count(1)) / (Count(0) + Count(1))
Else
Plot = 0
End If
Else
Plot = Single.NaN
End If
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Bruce I made this chart a lot easier to understand and I have played with thsi indicator for hours and I can't get it to work right.
I just shared this chart under AD2. Please ignore all the Black rules.
I have no idea why the realcode works when we only put in 2 rules but it does not work when yu put in the 12 rules.
This works fine when you measure the Acc and Dis in the entire wave and the retracement but when you try to just measure the last 20 days it doesn't. If you look at the last 2 indicators Total A/D in the Wave and Total A/D in Retrace they both use these 12 rules and they are accurate.
The Green rules are Acc with a 1 power.
The Red rules are Dis with a 1 power.
The Aqua rules are Acc with a .5 power.
The Purple rules are Dis with a .5 power
The Yellow rules are Acc with a 2 power
The dark Blue rules are Dis with a 2 power
Bring up the chart WYNN and make the last day 7/7/2009 please. In the last 20 bars (back to 6/8/2009) you have 2.5 points of distribution and no Acc but the indicator is at 0.
If you look at the top pane you have 3 purple bars during those 20 days and they each count as .5 plus you have 2 bars with .5 labeled in yellow underneath them so the total Dis is 2.5. how is it that the A/D indicator last 20 days sits at 0.
I am sorry for all the trouble but I just can't get this to work right.
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
ok no worries
I'll play with t a little more and if it doesn't work I'll just igonore it.
I know it's time consuming and I am not the only one you need to help.
Thanks anyway you have been more than supportive.
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Solved
The problem is the .5 and I have no idea why
Change the 0.5's to 1, 1's to 2 and 2's to 4 and it works fine.
For some reason it doesn't add and subtract 0.5.
My appologies for the trouble
Thanks
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
QUOTE (Bruce_L) thnkbigr,
I don't have a Layout with all of your Indicators for which I can run a test, but you might want to try something similar to the following (I added a Start variable for when it should be safe to start subtracting - not sure if it will work or not):
'# AA5 = condition.Acc1/2ATR
'# AA1 = condition.AccumulationATRw/AvgVolume
'# AA2 = condition.AW/AvgV2*ATR
'# AY5 = condition.Acc1/2ATRYesVol
'# AY1 = condition.AccumulationATR
'# AY2 = condition.AYesV2*ATR
'# DA5 = condition.Dis1/2ATR
'# DA1 = condition.DistributionATRw/AvgVolume
'# DA2 = condition.DW/AvgV2*ATR
'# DY5 = condition.Dis1/2ATRYesVol
'# DY1 = condition.DistributionATR
'# DY2 = condition.DYesV2*ATR
'# OfBars = UserInput.Integer = 20
Static Count(1) As Integer
Static Start As Integer
If isFirstBar Then
Count(0) = 0
Count(1) = 0
Start = CurrentIndex + OfBars
End If
If AA5.Value = True Then Count(0) += 0.5
If AA1.Value = True Then Count(0) += 1
If AA2.Value = True Then Count(0) += 2
If AY5.Value = True Then Count(0) += 0.5
If AY1.Value = True Then Count(0) += 1
If AY2.Value = True Then Count(0) += 2
If DA5.Value = True Then Count(1) += 0.5
If DA1.Value = True Then Count(1) += 1
If DA2.Value = True Then Count(1) += 2
If DY5.Value = True Then Count(1) += 0.5
If DY1.Value = True Then Count(1) += 1
If DY2.Value = True Then Count(1) += 2
If CurrentIndex >= Start Then
If AA5.Value(OfBars) = True Then
Count(0) -= 0.5
End If
If AA1.Value(OfBars) = True Then
Count(0) -= 1
End If
If AA2.Value(OfBars) = True Then
Count(0) -= 2
End If
If AY5.Value(OfBars) = True Then
Count(0) -= 0.5
End If
If AY1.Value(OfBars) = True Then
Count(0) -= 1
End If
If AY2.Value(OfBars) = True Then
Count(0) -= 2
End If
If DA5.Value(OfBars) = True Then
Count(1) -= 0.5
End If
If DA1.Value(OfBars) = True Then
Count(1) -= 1
End If
If DA2.Value(OfBars) = True Then
Count(1) -= 2
End If
If DY5.Value(OfBars) = True Then
Count(1) -= 0.5
End If
If DY1.Value(OfBars) = True Then
Count(1) -= 1
End If
If DY2.Value(OfBars) = True Then
Count(1) -= 2
End If
If Count(0) + Count(1) > 0 Then
Plot = Count(0) - Count(1)
Else
Plot = 0
End If
Else
Plot = Single.NaN
End If
The issue is that count is an Integer and you can't add a decimal to an integer and get onything but a rounnded result.
An allternate to your solution is to change the declaration of Count() to Single and the code would work as well.
Now you know why.
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
jas0501,
Count() to Single does it.
I must have spent 10 hours on this before I realized its not adding and subtracting .5's.
Thanks
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Where am i going wrong in here?
Rather than Adding and Subtracting 1 I am trying to have it add and subtract the net change of price.
I changed the Count(1) As Integer to Single but neither one work correctly.
I even tried to have it plot just Count(0) or Count(1) just to see where the problem is and it seems that it doesn't subtract the value when AFA.Value(OfBars) is true.
'# AFA = condition.Ac
'# DFA = condition.Dis
'# OfBars = UserInput.Integer = 20
Static Count(1) As Single
If isFirstBar Then
Count(0) = 0
Count(1) = 0
End If
If AFA.Value = True Then Count(0) += Price.Close - Price.Close(1)
If DFA.Value = True Then Count(1) += System.Math.ABS(Price.Close - Price.Close(1))
If CurrentIndex >= OfBars Then
If AFA.Value(OfBars) = True Then
Count(0) -= Price.Close - Price.Close(1)
End If
If DFA.Value(OfBars) = True Then
Count(1) -= System.Math.ABS(Price.Close - Price.Close(1))
End If
If Count(0) + Count(1) > 0 Then
Plot = Count(0) - Count(1)
Else
Plot = 0
End If
Else
Plot = Single.NaN
End If
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Shouldn't:
Count(0) -= Price.Close - Price.Close(1)
Be:
Count(0) -= Price.Close(OfBars) - Price.Close(OfBars+1)
And:
Count(1) -= System.Math.ABS(Price.Close - Price.Close(1))
Be:
Count(1) -= System.Math.ABS(Price.Close(OfBars) - Price.Close(OfBars+1))
I don't see Rules called Ac or Dis in the Shared Charts from you I've looked at, but when I replace them with Rules that are there, Count(0) seems to go both up and down.
'# AFA = condition.AccumulationATRw/AvgVolume
'# DFA = condition.DistributionATRw/AvgVolume
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
They are the same rules I just created a new Test chart just to see what was wrong with this so I recreated those to rules in the test chart under Ac and Dis.
I have the rules as Acc and Dis pated in the 1st comment of this topic on Friday, October 16, 2009 4:33:16 PM
That does it Thanks
'# AFA = condition.Ac
'# DFA = condition.Dis
'# OfBars = UserInput.Integer = 20
Static Count(1) As Single
If isFirstBar Then
Count(0) = 0
Count(1) = 0
End If
If AFA.Value = True Then Count(0) += Price.Close - Price.Close(1)
If DFA.Value = True Then Count(1) += System.Math.ABS(Price.Close - Price.Close(1))
If CurrentIndex >= OfBars Then
If AFA.Value(OfBars) = True Then
Count(0) -= Price.Close(OfBars) - Price.Close(OfBars + 1)
End If
If DFA.Value(OfBars) = True Then
Count(1) -= System.Math.ABS(Price.Close(OfBars) - Price.Close(OfBars + 1))
End If
If Count(0) + Count(1) > 0 Then
Plot = Count(0) - Count(1)
Else
Plot = 0
End If
Else
Plot = Single.NaN
End If
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Bruce ,
Are you using Wilder smoothing in ATR in the realcode below and the realcode for My Volatility Stop or since Wilder smoothing is resource intensive you are just using simple?
I am just curious to know.
thx
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
'# Cumulative
Static ATR As Single
Static TR As Single
Static sumWeight As Single
Static termRatio As Single = 13 / 14
Static AvgV As Single
If isFirstBar Then
sumWeight = 1
TR = Price.High - Price.Low
AvgV = 0
Else
TR = System.Math.Max(Price.High, Price.Last(1)) - _
System.Math.Min(Price.Low, Price.Last(1))
AvgV += Volume.value(1) / 30
End If
If CurrentIndex >= 31 Then AvgV -= Volume.value(31) / 30
Dim Weight As Single = 1 / sumWeight
ATR = ATR * (1 - Weight) + Weight * TR
sumWeight = sumWeight * termRatio + 1
If Volume.value > AvgV AndAlso _
Price.Last - Price.Last(1) >= ATR Then Pass
this is code I meant
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
It is Wilder's Smoothed. Wilder's Smoothing isn't in and of itself resource intensive. It becomes resource intensive if you are changing the Period. Also, since it is a cumulative Indicator, it will usually require more data than a similar Simple Smoothing if you are Dragging and Dropping it to the Watchlist.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
kk thanks
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Bruce
Do you see anythikng wrong with this?
This is accurate
'# PPO = indicator.MyPPO
'# AAV = condition.AAvgV>.5ATR
'# DAV = condition.DW/AvgV>.5ATR
Static Min As Single
Static Count(3) As Single
Static MinBar As Single
Static AccDis As Single
Static Triggered As Boolean
If isFirstBar Then
Min = Price.Low
Count(0) = 0
Count(1) = 0
Count(2) = 0
Count(3) = 0
MinBar = Single.NaN
AccDis = Single.NaN
Triggered = False
End If
If PPO.Value >= -1 Then
Count(0) = Single.NaN
Else If PPO.Value < -1 AndAlso _
PPO.Value(1) >= -1 Then
Count(0) = 1
Else
Count(0) += 1
End If
If PPO.Value >= -4 Then
Count(1) = Single.NaN
Else If PPO.Value < -4 AndAlso _
PPO.Value(1) >= -4 Then
Count(1) = 1
Else
Count(1) += 1
End If
If Count(0) > 10 OrElse _
Count(1) > 5 Then
If Price.Low(1) <= Min Then
Min = Price.Low(1)
MinBar = CurrentIndex - 1
End If
Else If Count(0) = 10 OrElse _
Count(1) = 5 Then
Min = Price.MinLow(21, 1)
For i As Integer = 1 To 21
If Price.Low(i) = Min Then
MinBar = CurrentIndex - i
Triggered = True
Exit For
End If
Next
Else If CurrentIndex >= 1 AndAlso _
Triggered = False AndAlso _
Price.Low(1) <= Min Then
Min = Price.Low(1)
MinBar = CurrentIndex - 1
End If
If Price.High > Price.MaxHigh(62, 1) * 1.005 Then
AccDis = 0
Count(2) = 0
Count(3) = 0
For i As Integer = 0 To CurrentIndex - MinBar - 1
If AAV.Value(i) = True Then Count(2) += 1
If DAV.Value(i) = True Then Count(3) += 1
Next
AccDis = Count(2) - Count(3)
End If
plot = AccDis
This is not and all I am changing is in Red
'# PPO = indicator.MyPPO
'# AAV = condition.AAvgV>.5ATR
'# DAV = condition.DW/AvgV>.5ATR
Static Min As Single
Static Count(3) As Single
Static MinBar As Single
Static AccDis As Single
Static Triggered As Boolean
If isFirstBar Then
Min = Price.Low
Count(0) = 0
Count(1) = 0
Count(2) = 0
Count(3) = 0
MinBar = Single.NaN
AccDis = Single.NaN
Triggered = False
End If
If PPO.Value >= -1 Then
Count(0) = Single.NaN
Else If PPO.Value < -1 AndAlso _
PPO.Value(1) >= -1 Then
Count(0) = 1
Else
Count(0) += 1
End If
If PPO.Value >= -4 Then
Count(1) = Single.NaN
Else If PPO.Value < -4 AndAlso _
PPO.Value(1) >= -4 Then
Count(1) = 1
Else
Count(1) += 1
End If
If Count(0) > 10 OrElse _
Count(1) > 5 Then
If Price.Low(1) <= Min Then
Min = Price.Low(1)
MinBar = CurrentIndex - 1
End If
Else If Count(0) = 10 OrElse _
Count(1) = 5 Then
Min = Price.MinLow(21, 1)
For i As Integer = 1 To 21
If Price.Low(i) = Min Then
MinBar = CurrentIndex - i
Triggered = True
Exit For
End If
Next
Else If CurrentIndex >= 1 AndAlso _
Triggered = False AndAlso _
Price.Low(1) <= Min Then
Min = Price.Low(1)
MinBar = CurrentIndex - 1
End If
If Price.High > Price.MaxHigh(62, 1) * 1.005 Then
AccDis = 0
Count(2) = 0
Count(3) = 0
For i As Integer = 0 To CurrentIndex - MinBar - 1
If AAV.Value(i) = True Then Count(2) += Price.Close - Price.Close(1)
If DAV.Value(i) = True Then Count(3) += System.Math.ABS(Price.Close - Price.Close(1))
Next
AccDis = Count(2) - Count(3)
End If
plot = AccDis
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I haven't tested it, but you might want to try the following instead:
If AAV.Value(i) = True Then Count(2) += Price.Close(i) - Price.Close(i+1)
If DAV.Value(i) = True Then Count(3) += System.Math.ABS(Price.Close(i) - Price.Close(i+1))
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
that's it
thanks
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |