![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Nov 2006
Location: , ,
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
|
Hi. I cannot figure out how to make an int type variable take the value of an integer which is held in a double type variable.
Here is some sample code: #region Variables private double tickAltPeriodPro = 0.20;#endregion protected override void Initialize() { tickAltPeriod = Math.Floor(Bars.Period.Value * tickAltPeriodPro);} For example, let's say the variable tickAltPeriodPro takes a value of 0.20. Using a tick chart with a period of 266, I would like tickAltPeriod to be equal to 53 (Floor function return value of the expression [266 * 0.20]). If I make tickAltPeriod an int variable then I get an error when the Floor function returns a double. If I make tickAltPeriod a double then the Add function returns an error (it's expecting a int input). Hopefully there's a simple workaround that I'm overlooking. Thank you. Regards, |
|
|
|
|
|
#2 |
|
Member
Join Date: Nov 2006
Location: , ,
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
|
After poking around on the MSDN site I think I just answered my question:
tickAltPeriod = System.Convert.ToInt32(Math.Floor(Bars.Period.Valu e * tickAltPeriodPro));Thanks again. Regards, |
|
|
|
|
|
#3 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
This shoud also work:
tickAltPeriod = (int) Math.Floor(Bars.Period.Valu e * tickAltPeriodPro);
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Member
Join Date: Nov 2006
Location: , ,
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks for the prompt reply, Ray. After solving my first problem, I encountered a second one. I received the following error message in my log window:
Strategy Failed to call method 'Initialize' for strategy 'ATRTrade_v8': 'Bars' property can not be accessed from within 'Initialize' method Is there any way to access the period value in the Initialize block? Regards, |
|
|
|
|
|
#5 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Try "BarsPeriod"
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Member
Join Date: Nov 2006
Location: , ,
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
|
|
|
|
|
|
|
#7 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Try BarsPeriod.Value. Just use the intellisense and you'll see.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#8 | |
|
Member
Join Date: Nov 2006
Location: , ,
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
I get an error when I choose to run a backtest. I can ignore past the dialogue to run a backtest, but the period comes through as 0. |
|
|
|
|
|
|
#9 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
As the error you got suggests the value can not be 0.
You need to check that tickAltPeriod does not become 0.
Dierk
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Double EMA | NinjaTrader_Ray | NinjaScript File Sharing Discussion | 0 | 07-31-2007 10:20 AM |
| double to int ? | zoltran | Indicator Development | 3 | 03-14-2007 01:51 AM |
| Double moving average ,double time frame | Mauro60 | Indicator Development | 3 | 01-23-2007 02:11 AM |
| converting eSignal (javascript) to NinjaScript | ATI user | General Programming | 2 | 10-24-2006 03:06 AM |
| Converting TS strategy signals to NT | Elfsareus | Automated Trading | 7 | 02-15-2006 02:32 PM |