NexusFi: Find Your Edge


Home Menu

 





NinjaScript Little Helpers Code Share - Snippets/UserDefinedMethods


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one gregid with 13 posts (28 thanks)
    2. looks_two bltdavid with 12 posts (17 thanks)
    3. looks_3 Fat Tails with 3 posts (8 thanks)
    4. looks_4 ratfink with 2 posts (1 thanks)
      Best Posters
    1. looks_one Fat Tails with 2.7 thanks per post
    2. looks_two gregid with 2.2 thanks per post
    3. looks_3 timefreedom with 2 thanks per post
    4. looks_4 bltdavid with 1.4 thanks per post
    1. trending_up 10,701 views
    2. thumb_up 61 thanks given
    3. group 11 followers
    1. forum 34 posts
    2. attach_file 3 attachments




 
Search this Thread

NinjaScript Little Helpers Code Share - Snippets/UserDefinedMethods

  #31 (permalink)
 bltdavid 
San Jose, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Posts: 112 since Dec 2013
Thanks Given: 35
Thanks Received: 103


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
Thanked by:

Can you help answer these questions
from other members on NexusFi?
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
Increase in trading performance by 75%
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #32 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623


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."

Started this thread Reply With Quote
Thanked by:
  #33 (permalink)
 bltdavid 
San Jose, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Posts: 112 since Dec 2013
Thanks Given: 35
Thanks Received: 103



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
Click image for larger version

Name:	2015-05-14_14-50-14.jpg
Views:	169
Size:	26.5 KB
ID:	182677  
Reply With Quote
  #34 (permalink)
 bltdavid 
San Jose, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Posts: 112 since Dec 2013
Thanks Given: 35
Thanks Received: 103


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)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425

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
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on May 15, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts