Click here to Login





                                                   How do I refer to the close price of another symbol in a formula?

  0

0
Stefan Kroscen
2010-07-19 22:23:38


I am trying to write a formula that uses another symbol as a reference. I am not sure how to look up the close price of that other symbol.
Is there a method that does that?

My specific problem is that I would like to revise the chande_trendscore to take a symbol as an arguement.

result = cFunctions.CompileFormula("a = iff(close>=Ref(close,11),1,-1)+iff(close>=Ref(close,12),1,-1)+iff(close>=Ref(close,13),1,-1)+iff(close>=Ref(close,14),1,-1)+iff(close>=Ref(close,15),1,-1)+iff(close>=Ref(close,16),1,-1)+iff(close>=Ref(close,17),1,-1)+iff(close>=Ref(close,18),1,-1)+iff(close>=Ref(close,19),1,-1)+iff(close>=Ref(close,20),1,-1);").GetVectorDouble("a");


Thanks!



QuantShare
2010-07-20 05:14:38

  1

Best Answer
Hi Stefan,

To get the close price of another symbol you can use the GetSeries function.
GetSeries("symbol", close)

To optimize the above formula, do not replace "close" by the getseries function.
Add a new variable "b" for example and replace "close" by "b".

result = cFunctions.CompileFormula("b=GetSeries('" + symbol_parameter + "', close); a = iff(b>=Ref(b,11),1,-1)+iff(b>=Ref(b,12),1,-1)+iff(b>=Ref(b,13),1,-1)+iff(b>=Ref(b,14),1,-1)+iff(b>=Ref(b,15),1,-1)+iff(b>=Ref(b,16),1,-1)+iff(b>=Ref(b,17),1,-1)+iff(b>=Ref(b,18),1,-1)+iff(b>=Ref(b,19),1,-1)+iff(b>=Ref(b,20),1,-1);").GetVectorDouble("a");



Stefan Kroscen
2010-07-20 15:34:47

  0

Thanks for your prompt response!


Stefan Kroscen
2010-07-20 18:41:56

  0

Actually, I shouldn't have closed this issue so quickly...

There is still a problem... when you pass symbol_parameter this way and compile the function, it compiles ok but does not work as expected. The value passed at runtime is not seen when the function runs. Is that because it is being concatenated into the string instead of passed as a parameter? Should QSFormula.SetParameter be overloaded to accept VectorS? It currently only accepts VectorD so I can't test to see if that would fix the problem.



QuantShare
2010-07-21 03:35:12

  1

Did you get the first or any value of the symbol parameter?
The parameter that is passed is a String Vector.
Also do not forget the single quote before and after the double quotes.

-> "b = GetSeries(' " + symbol[0] + " ', close);"

Let me know if this fixed your problem




Stefan Kroscen
2010-07-21 09:00:12

  0

That was the problem, thanks again!


No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
High to low stock pattern for the close price
How far are the close prices from the support line
Market Rule based on the Crossover Between Stock Close prices and...
Close Price Above Cursor
% bars in last N trading days where stock close price increased

How-to Lessons
How to change volume bar colors when the price closes down
How to copy the data/settings of an account to another account
How to perform a basic quantitative analysis using the S&P 500
How to plot the ratio of two stocks
How to detect whether price movements are predictable or not

Related Forum Threads
How do I find the close price for an entry matching a custom DB
how do you check if the price data is up to date?
How do you retrieve the entry and exit price for a position?
How to trade one symbol based on indicators of another?
handle stock split during simulation if close price as filter

Blog Posts
How to create market indicators using the composite function - Pa...
How to use the new Market Regimes Feature in QuantShare Trading S...
How to measure market strength with the composite tool
How to predict and trade the stock market using pivot points
Buy the best/top rated stocks or how to create powerful rank base...









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.