Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

RealCode help Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
jpcharts
Posted : Wednesday, June 16, 2010 5:19:43 PM
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
jas0501
Posted : Wednesday, June 16, 2010 5:40:15 PM
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

Bruce_L
Posted : Saturday, June 19, 2010 1:35:25 PM


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
jcandela00
Posted : Monday, June 21, 2010 9:35:52 PM
Registered User
Joined: 10/15/2009
Posts: 3
How do I add (Vervoort )ATR to real code to then scan my watch list?
jcandela00
Posted : Monday, June 21, 2010 9:37:16 PM
Registered User
Joined: 10/15/2009
Posts: 3
I am currently running Stock Finder 4.0

Thanks
Bruce_L
Posted : Tuesday, June 22, 2010 10:32:53 AM


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
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.