Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

How to Define a Variable Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
cdurso
Posted : Monday, June 25, 2012 7:20:48 PM
Gold Customer Gold Customer

Joined: 12/30/2004
Posts: 29

How do I define a variable in RealCode that I can apply the AVG function to without getting the error " 'avg' is not a member of single"? I want to be able to calculate different averages for a ratio of values. if i have symbol xyz and abc i want to calculate xyz/abc and then perform different calculations on this ratio.

Bruce_L
Posted : Tuesday, June 26, 2012 11:00:47 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

I do not know of a way to define a variable to which you can apply the AVG function.

You would need to manually calculate the Moving Average or create an external indicator to import so you can apply the AVG function to the imported indicator.

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Symbol Ratio Average
'|******************************************************************
'# Period = UserInput.Integer = 10
'# NumSymbol = UserInput.String = "IBM"
'# DenSymbol = UserInput.String = "GOOG"
Static Num As PriceScripting 
Static Den As PriceScripting
Static Ratio As New List (Of Double)
Static Sum As Single
If isFirstBar Then
	Num = PriceData(NumSymbol)
	Den = PriceData(DenSymbol)
	Ratio.Clear
	Sum = 0
End If
Dim Check As Single = Num.Value / Den.Value
If Single.IsNaN(Check) = False Then
	Ratio.Add(Check)
	Sum += Check
End If
If Ratio.Count = Period Then
	Plot = Sum / Period
	Sum -= Ratio(0)
	Ratio.RemoveAt(0)
Else
	Plot = Single.NaN
End If
If isLastBar Then
	Ratio.Clear
End If


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
nuggets12
Posted : Wednesday, October 31, 2012 1:38:55 PM
Registered User
Joined: 5/10/2010
Posts: 45

Bruce,

               I just got into Stockfinder 5 as suggested.  I see that one can create a new hybrid symbol, utilizing multiple ETF’s.  I would like to create the symbol,  “SRMind” where:

SRMind  =  ((XLF+XLY)-(XLE+XLP+XLU))

Can you assist?  It has been a several years since I did any basic programming and am not familiar with this language.
 

Thanks,

 

Bruce_L
Posted : Wednesday, October 31, 2012 3:21:14 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

You definitely found a related topic in which to ask your question. The technique used is the PriceData Method, which is one of several techniques which could be used to create your indicator. Note that the result is not a new symbol, but an indicator which can be plotted on the chart. I do not know of a way to actually create an artificial symbol in any of your products.

RealCode for Real People: Indicators

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:ETF Hybrid
'|******************************************************************
Static XLF As PriceScripting
Static XLY As PriceScripting
Static XLE As PriceScripting
Static XLP As PriceScripting
Static XLU As PriceScripting
If isFirstBar Then
	XLF = PriceData("XLF")
	XLY = PriceData("XLY")
	XLE = PriceData("XLE")
	XLP = PriceData("XLP")
	XLU = PriceData("XLU")
End If
Plot = XLF.Value + XLY.Value - XLE.Value - XLP.Value - XLU.Value


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
cdurso
Posted : Wednesday, October 31, 2012 3:26:07 PM
Gold Customer Gold Customer

Joined: 12/30/2004
Posts: 29

Is it possible to create a candlestick chart of that indicator for weekly or monthly timeframes?

Bruce_L
Posted : Wednesday, October 31, 2012 3:41:38 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Not really, but kind of. The highs and lows of XLF, XLY, XLE, XLP and XLU are probably not going to coincide to the same time. In addition, just performing the same math on the open, high and low as we have done for the close is not necessarily going to ensure that the open and close are within the range of the high and low. We would need to manually force this to happen in the RealCode.

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:ETF Hybrid
'|******************************************************************
Static XLF As PriceScripting
Static XLY As PriceScripting
Static XLE As PriceScripting
Static XLP As PriceScripting
Static XLU As PriceScripting
If isFirstBar Then
	XLF = PriceData("XLF")
	XLY = PriceData("XLY")
	XLE = PriceData("XLE")
	XLP = PriceData("XLP")
	XLU = PriceData("XLU")
End If
Dim Close As Single = XLF.Value + XLY.Value - XLE.Value - XLP.Value - XLU.Value
OpenValue = XLF.Open + XLY.Open - XLE.Open - XLP.Open - XLU.Open
HighValue = System.Math.Max(XLF.High + XLY.High - XLE.High - XLP.High - XLU.High, _
	System.Math.Max(Close, OpenValue))
LowValue = System.Math.Min(XLF.Low + XLY.Low - XLE.Low - XLP.Low - XLU.Low, _
	System.Math.Min(Close, OpenValue))
Plot = Close


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
cdurso
Posted : Wednesday, October 31, 2012 3:44:24 PM
Gold Customer Gold Customer

Joined: 12/30/2004
Posts: 29

thanks. but this only plots the close, right? how can we capture that as a candlestick chart?

Bruce_L
Posted : Wednesday, October 31, 2012 3:48:02 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

You need to right-click on the Indicator and select Edit to change Plot Style of the RealCode Indicator to Candlestick, HLC Bar, OHLC Bar or PointAndFigure (P&F is not going to be what you expect, it is just a Plot Style and doesn't actually create P&F charts) for the chart to display more than just the closing information.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
nuggets12
Posted : Thursday, November 1, 2012 10:00:37 AM
Registered User
Joined: 5/10/2010
Posts: 45

Bruce,

      Thanks for the code writing.  I thought I could take it from and make minor changes but I got a code error. What I am trying to write is:

SRMind = ((XLF + XLY)/2) - (XLE + XLP + XLU)/3)

Thanks,

 

Bruce_L
Posted : Thursday, November 1, 2012 10:09:40 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Please try the following RealCode Indicator:

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:ETF Hybrid
'|******************************************************************
Static XLF As PriceScripting
Static XLY As PriceScripting
Static XLE As PriceScripting
Static XLP As PriceScripting
Static XLU As PriceScripting
If isFirstBar Then
	XLF = PriceData("XLF")
	XLY = PriceData("XLY")
	XLE = PriceData("XLE")
	XLP = PriceData("XLP")
	XLU = PriceData("XLU")
End If
Dim Close As Single = (XLF.Value + XLY.Value) / 2 - (XLE.Value + XLP.Value + XLU.Value) / 3
OpenValue = (XLF.Open + XLY.Open) / 2 - (XLE.Open + XLP.Open + XLU.Open) / 3
HighValue = System.Math.Max((XLF.High + XLY.High) / 2 - (XLE.High + XLP.High + XLU.High) / 3, _
	System.Math.Max(Close, OpenValue))
LowValue = System.Math.Min((XLF.Low + XLY.Low) / 2 - (XLE.Low + XLP.Low + XLU.Low) / 3, _
	System.Math.Min(Close, OpenValue))
Plot = Close


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
nuggets12
Posted : Thursday, November 1, 2012 2:37:14 PM
Registered User
Joined: 5/10/2010
Posts: 45

Thanks...

cdurso
Posted : Wednesday, November 21, 2012 4:51:20 PM
Gold Customer Gold Customer

Joined: 12/30/2004
Posts: 29

Is it possible to set up this code in a way that allows the user to enter multiple custom symbols from the chart?

Bruce_L
Posted : Wednesday, November 21, 2012 5:34:27 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Yes, the example given in my Tuesday, June 26, 2012 11:00:47 AM ET post includes user inputs for two symbols. The process would be the same if you wanted to use more symbols.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
cdurso
Posted : Wednesday, November 21, 2012 6:08:10 PM
Gold Customer Gold Customer

Joined: 12/30/2004
Posts: 29

thanks. how do i find that specific post?

cdurso
Posted : Wednesday, November 21, 2012 6:09:52 PM
Gold Customer Gold Customer

Joined: 12/30/2004
Posts: 29

sorry, disregard that last post.

Bruce_L
Posted : Friday, November 23, 2012 8:37:16 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

I am happy to read you were able to figure it out on your own. The post is near the top of this very topic.



-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.