Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 10/14/2007 Posts: 56
|
I had to give up on a very simple problem after two hours of trying.
I very simply want to assign a value to an indicator if it is equal to or less than zero then plot its value if above zero and assign zero as the value if it is negative..
The indicator is a Price For Symbol so I can change it simply and it will act as a global change which will effect the displays that use the value. Here is the Code:
'# PfS = indicator.PriceforSymbol.2
Static LastPrice As Single
If isFirstBar Then
LastPrice = Single.NaN
Else If PfS.DateValue.Year <> PfS.DateValue(1).Year Then
LastPrice = PfS.Last(1)
End If
Plot = 100 * (PfS.Last / LastPrice - 1)
END OF Working Code
Now all I want to do is assign the value zero to the indicator (named Absolute Return) when the indicator (which is a year to date return) has a value that is zero or negative. I will later use that value to calculate a subsequent indicator.
Thanks very much
jpcharts
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
I modified your code a bit to avoid NANs
'# PfS = indicator.PriceforSymbol.2
const NoPriceYet as integer = -1
Static LastPrice As Single
If isFirstBar Then
LastPrice = NoPriceYet
Else If PfS.DateValue.Year <> PfS.DateValue(1).Year Then
LastPrice = PfS.Last(1)
End If
if LastPrice > NoPriceYet then
Plot = 100 * (PfS.Last / LastPrice - 1)
end if
Assumming the above code is AbsolutReturn then the following seperate indicator will plot the positive values or 0
'# ABSReturn = indicator.AbsoluteReturn
if ABSReturn.value > 0 then
plot = ABSReturn.value
else
plot = 0
end if
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
jpcharts,
I put the Single.NaN back into the code since it was there for a reason (it allows the Autosize Block to correctly calculate the minimum amount of data required to be valid).
'# PfS = indicator.PriceforSymbol.2
Static LastPrice As Single
If isFirstBar Then
LastPrice = Single.NaN
Else If PfS.DateValue.Year <> PfS.DateValue(1).Year Then
LastPrice = PfS.Last(1)
End If
If PfS.Last < LastPrice Then
Plot = 0
Else
Plot = 100 * (PfS.Last / LastPrice - 1)
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/15/2009 Posts: 3
|
How do I add (Vervoort )ATR to real code to then scan my watch list?
|
|
Registered User Joined: 10/15/2009 Posts: 3
|
I am currently running Stock Finder 4.0
Thanks
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
jcandela00,
It's in the June Traders Tips Shared Chart by Craig_S from 4/10/2009 12:28:13 PM.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |