Need help with built-in indicator of Correlation RS - TradeStation | futures io social day trading
futures io futures trading


Need help with built-in indicator of Correlation RS
Updated: Views / Replies:616 / 3
Created: by tony1124 Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Need help with built-in indicator of Correlation RS

  #1 (permalink)
Trading Apprentice
new york
 
Futures Experience: Beginner
Platform: TradeStation
Favorite Futures: emini
 
Posts: 2 since Dec 2015
Thanks: 0 given, 0 received

Need help with built-in indicator of Correlation RS

Here is the original code for Correlation RS. My question is below

{ Search Tag: WA-Correlation RS }
{
This indicator plots the correlation of the symbol to which the indicator is applied
and a user-specified second symbol. The correlation is calculated over a user-
specified number of bars.

This study can be used only with daily, weekly, or monthly bars.
}

using elsystem ;
using tsdata.common ;
using tsdata.marketdata ;

inputs:
string SecondSymbol( "SPY" ), { the correlation between this symbol and the
symbol to which the indicator is applied will be calculated }
int CorrelLength( 14 ), { number of bars over which to calculate the
correlation }
double PosCorrAlert( 0.7 ), { correlation values equal to or above this value
will trigger an alert, if alerts are enabled }
double NegCorrAlert( -0.7 ), { correlation values equal to or below this value
will trigger an alert, if alerts are enabled }
int LoadedStateColor( DarkGreen ), { color to use in grid applications for
plotting of the State of the PriceSeriesProvider when the State is "loaded" }
int NotLoadedStateColor( DarkRed ) ; { color to use in grid applications for
plotting of the State of the PriceSeriesProvider when the State is something
other than "loaded" }

variables:
intrabarpersist int PSPNeededCount( 0 ),
intrabarpersist double CorrelValue( 0 ) ;

// event handler for indicator's Initialized event
method void Initialize( Object InitSender, InitializedEventArgs InitArgs )
begin

if Bartype < 2 or BarType > 4 then
throw Exception.Create( "Relative Strength can be used only with daily, " +
"weekly, or monthly bars." ) ;

// set-up the "aligned" PriceSeriesProvider
SecondSymPrices.Interval = DataInterval.FromCurrentSymbolData( BarType,
BarInterval ) ;
SecondSymPrices.Range.FirstDate =
DateTime.FromELDateAndTime( Date[CorrelLength], Time[CorrelLength] ) ;
SecondSymPrices.Load = true ;

{ calculate the value of the Count property of the PSP that will be required
for the correlation calculation; this value will be used when the correlation
is calculated, below, to ensure that the PSP contains enough data to perform the
correlation calculation }
PSPNeededCount = CorrelLength + 1 ;

end ;

// event handler for update event of the PriceSeriesProvider SecondSymPrices
method void SecondSymPriceUpdate( Object SecondSymPriceSender,
PriceSeriesUpdatedEventArgs SecondSymPriceUpdateArgs )
begin
UpdateCorrelCalc() ;
end ;

// calculate correlation
method void UpdateCorrelCalc()
begin

if SecondSymPrices.Close.Count >= PSPNeededCount then
CorrelValue = Correlation( Close, SecondSymPrices.Close, CorrelLength )
else
throw Exception.Create( "Insufficient data available to calculate" +
" correlation. Required bars = " + NumToStr( PSPNeededCount, 0 ) +
". Available bars = " + SecondSymPrices.Close.Count.ToString() + "." ) ;

PlotOutputs() ;

end ;

method void PlotOutputs()
begin

Plot1( UpperStr( SecondSymbol ), "2ndSym" ) ;
Plot2( SecondSymPrices.State.ToString(), "DataState",
iff( SecondSymPrices.State = DataState.Loaded, LoadedStateColor,
NotLoadedStateColor ) ) ;
Plot3( CorrelValue, "Correlation" ) ;

if CorrelValue >= PosCorrAlert then
Alert( Symbol + ": Positive correlation alert!" )
else if CorrelValue <= NegCorrAlert then
Alert( Symbol + ": Negative correlation alert!" ) ;

end ;

UpdateCorrelCalc() ;


{ ** Copyright © TradeStation Technologies, Inc. All Rights Reserved **
** TradeStation reserves the right to modify or overwrite this analysis technique
with each release. ** }

Question

I am new to use PriceSeriesProvider. I am trying to see the correlation between the rate of change of two stocks. So, I try to change the calculation
CorrelValue = Correlation( rateofchange(Close, 1), rateofchange(SecondSymPrices.Close, 1), CorrelLength )
But RadarScreen shows an error of "invalid index used to access element of a collection"
I tried to search something related to PriceSeriesProvider. SecondSymPrices.Close[0] is the closing price of current bar and SecondSymPrices.Close[1] is the closing price of 1 bar before. Then, I try
CorrelValue = Correlation( Close / close[1] - 1, SecondSymPrices.Close / SecondSymPrices.Close[1] - 1, CorrelLength )
Unfortunately, the number I get is wrong. Then, I try to print(SecondSymPrices.Close).
An error of "attempting to print an object reference. please use the '.' operator and select the object member you wish to use(ex. object.doublevalue, object.tostring(), etc"
I have no idea about that.
So, I try
CorrelValue = Correlation( Close / open - 1, SecondSymPrices.Close /SecondSymPrices.open - 1 , CorrelLength )
It shows the error of "operation not supported for these data types" and highlighted "1".
Then, I change it to
CorrelValue = Correlation( Close / open, SecondSymPrices.Close /SecondSymPrices.open , CorrelLength )
Error again and force me to close my EL. It seems due to infinite loop. I am not sure why.


Thank you for your help

Reply With Quote
 
  #2 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,524 since Apr 2013
Thanks: 229 given, 852 received
Forum Reputation: Legendary

tony1124,

your best approach will likely be to print the different values, as this will help you to see what values the code uses. As you noticed you can't print objects directly, but each object provides the .ToString() method that you can use.

In your example instead of trying to print the object directly using print(SecondSymPrices.Close[0].ToString()) should give you the result you are looking for.

Regards,

ABCTG

Reply With Quote
 
  #3 (permalink)
Trading Apprentice
new york
 
Futures Experience: Beginner
Platform: TradeStation
Favorite Futures: emini
 
Posts: 2 since Dec 2015
Thanks: 0 given, 0 received



ABCTG View Post
tony1124,

your best approach will likely be to print the different values, as this will help you to see what values the code uses. As you noticed you can't print objects directly, but each object provides the .ToString() method that you can use.

In your example instead of trying to print the object directly using print(SecondSymPrices.Close[0].ToString()) should give you the result you are looking for.

Regards,

ABCTG

Hi ABCTG,

Thanks for helping me. I am trying to follow your way of thinking. I guess the print should be from ELsystem.object.tostring.

I try to print this
print("SecondSymbol: ", SecondSymbol, ", Date: ", date, ", SecondSymPrices.[0]: ", SecondSymPrices.Close[0].tostring(), ", SecondSymPrices.[1]: ", SecondSymPrices.Close[1].tostring(), ", SecondSymPrices.open[0]: ", SecondSymPrices.open[0].tostring(), ", SecondSymPrices.open[1]: ", SecondSymPrices.open[1].tostring() );

It works and shows that in the print lot.
SecondSymbol: SPY, Date: 1151211.00, SecondSymPrices.[0]: 201.88, SecondSymPrices.[1]: 205.87, SecondSymPrices.open[0]: 203.34999999999999, SecondSymPrices.open[1]: 205.42000000000002

At this point, I guess something is wrong in the number of open because it should not be that long. But, I think it is still OK.

Then, I try to print this.
print(SecondSymPrices.Close);
An error occurs and says "attempting to print an object reference. Please use the '.' operator and select the object member you wish to use (ex.object.doublevalue, object.tostring(), etc.)

I guess it is because SecondSymPrices.Close returns different close prices in different time, so it cannot be printed. This makes sense to me. For now, I can understand the difference between SecondSymPrices.Close and SecondSymPrices.Close[0], SecondSymPrices.Close[1]......

Then, I turn to see the correlation of rate of change between symbol1 and symbol2.
I change the original function to this
CorrelValue = Correlation( Close / open - 1, SecondSymPrices.Close / SecondSymPrices.open - 1, CorrelLength );

An error of "operation not supported for these data types" and highlighted 1.
My mind goes blank. Is it because SecondSymPrices.Close and SecondSymPrices.Open are an array. So, I should try something like this
for value1 = 0 to SecondSymPrices.Count - 1 begin
ChangeOnEachBar = SecondSymPrices.close[value1] / SecondSymPrices.open[value1] - 1;
end;

Thanks.


Last edited by tony1124; December 11th, 2015 at 11:10 PM.
Reply With Quote
 
  #4 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,524 since Apr 2013
Thanks: 229 given, 852 received
Forum Reputation: Legendary

tony1124;

the error message you are receiving points towards your study trying to access the PSP values before it's fully populated. Updating the method that computes the correlation to something like the below should do it.

 
Code
// calculate correlation
method void UpdateCorrelCalc()
begin

if SecondSymPrices.Close.Count >= PSPNeededCount and PSPNeededCount  > 0 then
begin 
CorrelValue = Correlation( Close, SecondSymPrices.Close, CorrelLength ) ;
PlotOutputs() ;
end ;
end ;
Regards,

ABCTG

Reply With Quote

Reply



futures io > > > > Need help with built-in indicator of Correlation RS

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Correlation indicator alert Giulianzo MetaQuotes MetaTrader MQL Programming 1 April 5th, 2015 04:38 PM
Correlation indicator chadschneid NinjaTrader 0 August 15th, 2014 11:25 AM
Open a new chart from RS brakkar TradeStation 1 March 19th, 2014 09:47 AM
Correlation indicator (NT7) gregid NinjaTrader 4 February 25th, 2013 06:14 PM
RS of Houston (www.rsofhouston.com) nqcruiser Trading Reviews and Vendors 4 October 2nd, 2010 04:46 PM


All times are GMT -4. The time now is 02:12 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-11 in 0.12 seconds with 19 queries on phoenix via your IP 54.226.34.209