NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 07-29-2012, 05:30 AM   #1
ripwinkle
Junior Member
 
Join Date: Jul 2012
Posts: 6
Thanks: 3
Thanked 0 times in 0 posts
Default Multiple Timeframe issue

I am facing Multiple Timeframe issue.
The primary instrument is 5 min timeframe.
I have initialized the other timeframes as below in Initialize()

Add(PeriodType.Minute, 15);
Add(PeriodType.Minute,
60);


I have created a simple Spread function
public double Spread(IDataSeries data1, IDataSeries data2) {
return data1[0]-data2[0];
}


I create a strategy where I want to compute a variable x such that
x = Spread(15min-low, 60min-high)*100

Using
x = Spread(Lows[1][0],Highs[2][0]) *100

doesnot work correctly due to datatype error.


Please advise.
Last edited by ripwinkle; 07-29-2012 at 05:34 AM.
ripwinkle is offline  
Reply With Quote
Old 07-29-2012, 10:58 AM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

ripwinkle.

Could you show us the exact error here?
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-29-2012, 04:14 PM   #3
ripwinkle
Junior Member
 
Join Date: Jul 2012
Posts: 6
Thanks: 3
Thanked 0 times in 0 posts
Default

the errors are as below :-

ErrorThe best overloaded method match for 'NinjaTrader.Strategy.Strategy.Spread(NinjaTrader. Data.IDataSeries, NinjaTrader.Data.IDataSeries)' has some invalid argumentsArgument '1': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries'Argument '2': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries'

where method points to 'Spread'
argument 1 points to 'Lows'
argument 2 points to 'Highs'

Please advise.
ripwinkle is offline  
Reply With Quote
Old 07-29-2012, 04:22 PM   #4
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
Default

Quote:
Originally Posted by ripwinkle View Post
I am facing Multiple Timeframe issue.
The primary instrument is 5 min timeframe.
I have initialized the other timeframes as below in Initialize()

Add(PeriodType.Minute, 15);
Add(PeriodType.Minute,
60);


I have created a simple Spread function
public double Spread(IDataSeries data1, IDataSeries data2) {
return data1[0]-data2[0];
}


I create a strategy where I want to compute a variable x such that
x = Spread(15min-low, 60min-high)*100

Using
x = Spread(Lows[1][0],Highs[2][0]) *100

doesnot work correctly due to datatype error.


Please advise.
I haven't typed this up,

but does this work?

Code:
x = Spread(Lows[1],Highs[2]) *100;





sledge is offline  
Reply With Quote
The following user says thank you to sledge for this post:
Old 07-29-2012, 09:11 PM   #5
ripwinkle
Junior Member
 
Join Date: Jul 2012
Posts: 6
Thanks: 3
Thanked 0 times in 0 posts
Default

This does work Sledge and I have previously tried it also.

1. But I want to confirm if this is exactly going to provide the output that I originally intended ?
Is Lows[1] = Lows[1][0] ?

2. Also, if the computation was not on the current bar, and I intended to compute on one bar ago i.e.

x = Spread(Lows[1][1],Highs[2][1]) *100

then how can I achieve the same ?

Please assist.
ripwinkle is offline  
Reply With Quote
Old 07-30-2012, 08:53 AM   #6
Coder_Kenny
Junior Member
 
Join Date: Jul 2012
Location: Houston, TX
Posts: 17
Thanks: 1
Thanked 15 times in 9 posts
Default

ripwinkle,

Lows[1] refers to the dataseries of your 15 minute instrument. Lows[1][1] refers to the Low double value of [1] 15 minute candle ago. If you want to use the double values of a certain candle of your choice, instead of the current value, trying changing your function definition to take doubles as arguments instead of DataSeries':

Code:
public double Spread(double data1, double data2) {
    return data1-data2;
}
Now when you call the function you can use:

Code:
x = Spread(Lows[1][1],Highs[2][1]) *100
Hope that helps,

Kenny
Coder_Kenny is offline  
Reply With Quote
The following user says thank you to Coder_Kenny for this post:
Old 07-31-2012, 07:23 PM   #7
ripwinkle
Junior Member
 
Join Date: Jul 2012
Posts: 6
Thanks: 3
Thanked 0 times in 0 posts
Default

Thanks Kenny!
ripwinkle is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple timeframe indiwator always 0 altias Market Analyzer 3 04-12-2011 04:35 PM
Multiple Timeframe Question canuck Strategy Development 20 12-12-2010 12:04 PM
Multiple Timeframe problem in 7.0 paulca Strategy Development 1 11-12-2010 03:04 PM
Multiple Timeframe questions paulca Strategy Development 3 07-24-2010 12:55 PM
multiple timeframe in a chart stevebong Charting 1 02-20-2009 03:27 AM


All times are GMT -6. The time now is 08:14 PM.