![]() |
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 |
|
Junior Member
Join Date: Apr 2012
Posts: 16
Thanks: 3
Thanked 3 times in 2 posts
|
I really needed to run the Optimizer and be able to test bools. In other words, optimize with the bool variable false and then try it with true. Currently, this is not supported in NT7.
Here's the simple method I worked out to make this easy: 1. Declare bools as normal in NinjaScript. Use them as normal. Too easy! private bool MyFavouritebool = false ; // Just a normal bool 2. In the Properties region, declare bools as follows: // Pseudo-bool -- 0 is false, 1 is true. public int _MyFavouritebool { get { return MyFavouritebool ? 1 : 0 ; } set { MyFavouritebool = value % 2 == 1 ? true : false ; } } 3. Set the parameter value to 0 for false and 1 for true. This makes optimization with bools simple. To leave the bool as false, use 0;0;1. To leave it as true, use 1;1;1. To optimize using the bool as false, then true, use 0;1;1. I hope you find this useful. Cheers. |
|
|
|
|
The following 2 users say thank you to jeronymite for this post: |
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,781
Thanks: 159
Thanked 565 times in 556 posts
|
jeronymite
Thank you for sharing your work in this area!
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Jul 2009
Posts: 60
Thanks: 18
Thanked 2 times in 2 posts
|
I'm trying to implement this code. Since adding it, I'm getting the following errors when I compile:
9/18/2012 10:06:06 PM Default Strategy 'NinjaTrader.Strategy.TrendlineBreakOutDT' could not be deserialized: There is an error in XML document (1, 6787). 9/18/2012 10:06:07 PM Strategy Error on getting/setting property 'MacdExit' for strategy 'TrendlineBreakOutDT/8bacaef5f437438d95661270b6885a6c': Object of type 'System.Boolean' cannot be converted to type 'System.Int32'. Any ideas? Despite these errors, the code does appear to work correctly, but it bothers me that it doesn't compile cleanly. Thanks! |
|
|
|
|
|
#4 |
|
Junior Member
Join Date: Apr 2012
Posts: 16
Thanks: 3
Thanked 3 times in 2 posts
|
Hi Style,
Glad you find the code useful. I too have experienced de-serialization issues, but they were not specifically caused by the pseudo-boolean construct. I found the issue when I tried to rename a strategy. In any case, the approach I took to overcome the issue was to create a completely new strategy using the Strategy Wizard that was empty of any content -- essentially a shell strategy. I then copied and pasted my source code into the new strategy and saved/recompiled. No more de-serialization errors since, and I use the pseudo-boolean construct all the time. Try this and see how you go. If you still see the errors, I would suggest it is not the pseudo-boolean construct and you may need to look elsewhere for the source of the issue. Perhaps the NT support folks may have some insights on this? Cheers. |
|
|
|
|
The following user says thank you to jeronymite for this post: |
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,781
Thanks: 159
Thanked 565 times in 556 posts
|
Style
Can you please post the exact region properties section of the code you are using?
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
#6 | ||
|
Member
Join Date: Jul 2009
Posts: 60
Thanks: 18
Thanked 2 times in 2 posts
|
Quote:
Quote:
[Description("")] [GridCategory("Parameters")] public int StartTime { get { return startTime; } set { startTime = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int EndTime { get { return endTime; } set { endTime = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int ThreeBarExit { get { return threeBarExit ? 1 : 0 ; } set { threeBarExit = value % 2 == 1 ? true : false ; } } [Description("")] [GridCategory("Parameters")] public int MacdExit { get { return macdExit ? 1 : 0 ; } set { macdExit = value % 2 == 1 ? true : false ; } } [Description("")] [GridCategory("Parameters")] public bool StaticStop { get { return staticStop; } set { staticStop = value; } } [Description("")] [GridCategory("Parameters")] public bool StaticTarget { get { return staticTarget; } set { staticTarget = value; } } [Description("")] [GridCategory("Parameters")] public bool StaticEntry { get { return staticEntry; } set { staticEntry = value; } } [Description("")] [GridCategory("Parameters")] public bool SineExit { get { return sineExit; } set { sineExit = value; } } [Description("")] [GridCategory("Parameters")] public int FasterTimeFrame { get { return fasterTimeFrame; } set { fasterTimeFrame = Math.Max(10, value); } } [Description("")] [GridCategory("Parameters")] public int MacdSineTimeFrame { get { return macdSineTimeFrame; } set { macdSineTimeFrame = Math.Max(10, value); } } [Description("")] [GridCategory("Parameters")] public int Strength { get { return strength; } set { strength = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public double Ratio { get { return ratio; } set { ratio = Math.Max(1, value); } } #endregion |
||
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,781
Thanks: 159
Thanked 565 times in 556 posts
|
The next time this occurs, rather than recreating the strategy, can you please try resetting the database to see if this resolve the issue? You can do this by going to Tools--> Options--> Data tab--> select "Reset DB".
Matthew
NinjaTrader Customer Service |
|
|
|
![]() |
| Tags |
| bools, optimizer, optimizer parameters |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Optimize indicator | rzeemeijer | Strategy Development | 2 | 10-27-2011 11:43 AM |
| Using Bars with Bools | CaptainAmericaXX | General Programming | 2 | 04-14-2011 11:29 AM |
| Bools and [] indexing | kenb2004 | Strategy Development | 5 | 02-28-2011 11:41 AM |
| ... no parameters to optimize | ThatManFromTexas | Strategy Analyzer | 10 | 02-28-2011 10:08 AM |
| ints and bools??? | John833 | Strategy Development | 2 | 12-08-2008 09:40 AM |