NinjaScript Little Helpers Code Share - Snippets/UserDefinedMethods - NinjaTrader Programming | futures io social day trading
futures io futures trading


NinjaScript Little Helpers Code Share - Snippets/UserDefinedMethods
Updated: Views / Replies:3,677 / 34
Created: by gregid Attachments:3

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
 3  
 
Thread Tools Search this Thread
 

NinjaScript Little Helpers Code Share - Snippets/UserDefinedMethods

  #31 (permalink)
Elite Member
San Jose, CA, USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, RCG/Continuum
Favorite Futures: GC,CL
 
Posts: 89 since Dec 2013
Thanks: 14 given, 89 received


ratfink View Post
Couldn't disagree more.

With simple 'bool's it should just be:
 
Code
if (entryDetails)
{
    // draw
}
if (exitDetails)
{
    // draw
}
if (targetDetails)
{
    // draw
}
if (stopDetails)
{
    // draw
}

No worries, I love these back & forth ideas on code organization (aka "readability").

I have not done the extension for the enumeration type, but I really like that idea.

ratfink reminds me how I actually check my DebugFlags enumeration. I define a bool property for each
flag, using a related prefix.

In this case, I might do,
 
Code
private bool DrawingEntries { get { return drawDetails.Includes(DrawOrderDetails.Entries; } }
private bool DrawingExits { get { return drawDetails.Includes(DrawOrderDetails.Exits; } }
private bool DaawingTargets { get { return drawDetails.Includes(DrawOrderDetails.Targets; } }
private bool DrawingStops { get { return drawDetails.Includes(DrawOrderDetails.Stops; } }
private bool DrawingEntriesExits { get { return drawDetails.Includes(DrawOrderDetails.EntriesExits; } }
private bool DrawingEntriesExitsTargets { get { return drawDetails.Includes(DrawOrderDetails.EntriesExitsTargets; } }
private bool DrawingEntriesExitsStops { get { return drawDetails.Includes(DrawOrderDetails.EntriesExitsStops; } }
private bool DrawingEntriesExitsTargetsStops { get { return drawDetails.Includes(DrawOrderDetails.EntriesExitsTargetsStops } }
private bool DrawingEntriesTargets { get { return drawDetails.Includes(DrawOrderDetails.EntriesTargets; } }
private bool DrawingEntriesStops { get { return drawDetails.Includes(DrawOrderDetails.EntriesStops; } }
private bool DrawingExitsTargets { get { return drawDetails.Includes(DrawOrderDetails.ExitsTargets; } }
private bool DrawingExitsStops { get { return drawDetails.Includes(DrawOrderDetails.ExitsStops; } }
private bool DrawingTargetsStops { get { return drawDetails.Includes(DrawOrderDetails.TargetssStops; } }

which turns ratfink's code suggestion into this,
 
Code
if (DrawingEntries)
{
    // draw
}
if (DrawingExits)
{
    // draw
}
if (DrawingTargets)
{
    // draw
}
if (DrawingStops)
{
    // draw
}

but I'd probably not make every combination an enumeration in this kind of example. Obviously the
first 4 are the base members, so another idea is to define just the 4 base members inside the
enumeration, and then define 4 properties for those members. This gives combinations that are
spelled out in the code, at the point of use, and it's also pleasant to read, too.

For example,
 
Code
if (DrawingEntries || DrawingExits)
{
    // same as DrawingEntriesExits
}
if (DrawingExits || DrawingStops)
{
    // same as DrawingExitsStops
}
if (DrawingEntries || DrawingExits || DrawingTargets || DrawingStops)
{
    // same as DrawingEntriesExitsTargetsStops
}

Great ideas, all of these ... as always, naming consistency is key, regardless of methods/conventions chosen.

Reply With Quote
The following user says Thank You to bltdavid for this post:
 
  #32 (permalink)
Elite Member
Wrocław, Poland
 
Futures Experience: Intermediate
Platform: NinjaTrader, Racket
Favorite Futures: Ockham's razor
 
gregid's Avatar
 
Posts: 651 since Aug 2009
Thanks: 321 given, 605 received


ratfink View Post
Often in the desire to be with the OO street kids we miss the elephant in the room.

I think you missed this part:
"The example is quite naive and could be solved with 4 bools - this is just to show how it works so you can use it for more complex problems."

Reply With Quote
The following user says Thank You to gregid for this post:
 
  #33 (permalink)
Elite Member
San Jose, CA, USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, RCG/Continuum
Favorite Futures: GC,CL
 
Posts: 89 since Dec 2013
Thanks: 14 given, 89 received



gregid View Post
I think you missed this part:
"The example is quite naive and could be solved with 4 bools - this is just to show how it works so you can use it for more complex problems."

No, the example shows advanced ideas, using 4 bools is naive.

I think your example is very good because it shows how to solve limitations with NinjaTrader backtesting.

NinjaTrader cannot optimize bools in the Strategy Analyzer, and having 4 bool properties exposed in the property grid is a bit overkill.

The solution?

Expose a single int property which is the bit pattern for the [Flags] enumeration type.

The user would add bit values together to produce the "pattern" representing the desired combination.

And, since this is an int property, it's fully optimizable.

I've done that many times, see screenshot for how the user selects their desired TradeDays in my strategy property grid.

PS: I use multi-line descriptions for my property help, does everyone know how to do that?

Attached Thumbnails
NinjaScript Little Helpers Code Share - Snippets/UserDefinedMethods-2015-05-14_14-50-14.jpg  

Last edited by bltdavid; May 14th, 2015 at 07:19 PM.
Reply With Quote
 
  #34 (permalink)
Elite Member
San Jose, CA, USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, RCG/Continuum
Favorite Futures: GC,CL
 
Posts: 89 since Dec 2013
Thanks: 14 given, 89 received


bltdavid View Post
Expose a single int property which is the bit pattern for the [Flags] enumeration type.

The user would add bit values together to produce the "pattern" representing the desired combination.

And, since this is an int property, it's fully optimizable.

I think I first saw this technique in a Woodies demo strategy I downloaded a few years back.

Woodies stuff is built by MicroTrends using (I presume) their strategy framework product.

Anyways, when I saw it in the Woodies' property grid, I immediately knew what MicroTrends had done (and why) and set about to do the same thing for my strategies.

Reply With Quote
 
  #35 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,336 since Dec 2012
Thanks: 11,276 given, 7,090 received

I still like naive when it just means simple, we overcomplicate far more than necessary so many times. It is interesting to see sophisticated approaches to tackling complex problems, but at my age it has to be KISS.

Travel Well
Reply With Quote
The following user says Thank You to ratfink for this post:

Reply



futures io > > > > > NinjaScript Little Helpers Code Share - Snippets/UserDefinedMethods

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
vvhg's Little Helpers - Keeping Them In One Place vvhg The Elite Circle 32 January 7th, 2016 11:58 PM
Code TRX Channel for TOS (MT4 Code here) rommark ThinkOrSwim Programming 0 October 1st, 2014 04:55 PM
Code Snippets needed! zeller4 NinjaTrader Programming 11 June 20th, 2011 04:21 PM
code snippets Saroj Feedback and Announcements 1 September 11th, 2009 02:10 PM


All times are GMT -4. The time now is 10:31 PM.

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-10 in 0.09 seconds with 20 queries on phoenix via your IP 54.221.73.186