Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 10/14/2007 Posts: 56
|
I am trying to build an accumulation oscillator in Real Code,. The daily accumulation doesn't have to go back to the beginning of the data stream unless the data array is short (less than 200 days). If I can create an accumulation of a product of two daily data items that go back 500 days that would be adequate. I want to use the accumulation as an oscillator which can oscillate above and below zero or another number. Can you help me understand how to build an array and how to specify that it go back to the beginning of the data stream or 500 days (500 is arbitrary as long as all items in a watchlist use the same oscillator terms). If you have any examples of real code that maintains an accumulation on a daily basis, that could be very helpful.
Many thanks.
jpcharts
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
If you can provide an unambiguous objective description of what you want to do I may be able to help you (or possibly not as I am not a programmer), but I do not understand your request as presented.
The following RealCode Indicator is just designed to demonstrate the creation of a Cumulative Indicator and is not designed to reflect any particular definition of accumulation (it's actually just OBV).
'# Cumulative
Static Sum As Single
If isFirstBar Then
Sum = 0
Else If Price.Last > Price.Last(1) Then
Sum += Volume.Value
Else If Price.Last < Price.Last(1) Then
Sum -= Volume.Value
End If
Plot = Sum
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/14/2007 Posts: 56
|
Looking at an earlier posting, I may be trying to build a cash flow accumulation in Stockfinder. What I am trying to do is to multiply a symbol's closing price by the days volume in the symbol. If the stock is up, I want to add the product to the previous day. If it is down (or negative) I want to subtract the product from the accumulation which will potentially provide an oscillator of the accumulated cash flow into and out of a symbol. In addition I would like to have the ability to change the length of the summation potentially to experiment with the output to determine an adequate accumulation without making it too long. This is not as important as getting the oscillator working. I can potentially add a means to change the parameter which varies the length of the array.
Many thanks.
jpcharts
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Accumulation Oscillator
'|******************************************************************
'# Cumulative
'# Period = UserInput.Integer = 200
Static Sum As Single
If isFirstBar Then
Sum = 0
Else If Price.Last > Price.Last(1) Then
Sum += Volume.Value * Price.Last
Else If Price.Last < Price.Last(1) Then
Sum -= Volume.Value * Price.Last
End If
If CurrentIndex > Period Then
If Price.Last(Period) > Price.Last(Period + 1) Then
Sum -= Volume.Value(Period) * Price.Last(Period)
Else If Price.Last(Period) < Price.Last(Period + 1) Then
Sum += Volume.Value(Period) * Price.Last(Period)
End If
End If
Plot = Sum
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/14/2007 Posts: 56
|
Thank you. This is a great help. I am very anxious to try it.
Best regard,
jpcharts
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/14/2007 Posts: 56
|
Tested it. It works great but the amazing thing is that I see what you did and how you did it and I know I would not have accomplished this in a month of trying.
Thanks very much. In two projects you are batting a 1000 getting the result in minimum time and you have saved me numerous hours.
jpcharts
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
The important thing is that you see the what and how and I am happy to read that you do.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
Bruce based on your previous comments the cumulative directive could be removed if the code was changed as below. Granted the first "Period" bars would not plot the sum, but the performance for watchlist columns would be optimal.
With the added capability of dynamic lookback for watchlist column calculation, the use of
'# cumulative
unnecessary, if the code is properly written to plot single.NAN for the first "period" bars.
Correct?
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Accumulation Oscillator
'|******************************************************************
'# Period = UserInput.Integer = 200
Static Sum As Single
If isFirstBar Then
Sum = 0
Else If Price.Last > Price.Last(1) Then
Sum += Volume.Value * Price.Last
Else If Price.Last < Price.Last(1) Then
Sum -= Volume.Value * Price.Last
End If
If CurrentIndex > Period Then
If Price.Last(Period) > Price.Last(Period + 1) Then
Sum -= Volume.Value(Period) * Price.Last(Period)
Else If Price.Last(Period) < Price.Last(Period + 1) Then
Sum += Volume.Value(Period) * Price.Last(Period)
End If
Plot = Sum
else
plot = single.NAN
End If
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Yes, you could definitely eliminate the '# Cumulative line if you did it that way.
The reason I didn't is because jpcharts indicated, "The daily accumulation doesn't have to go back to the beginning of the data stream unless the data array is short (less than 200 days)."
To me, this meant a Plot was desired even when there was less than Period Bars of data available. I could be misinterpreting this remark however.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |