Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Updated May 15, 2015
Top Posters
looks_one
gregid
with 13 posts (28 thanks)
looks_two
bltdavid
with 12 posts (17 thanks)
looks_3
Fat Tails
with 3 posts (8 thanks)
looks_4
timefreedom
with 2 posts (4 thanks)
Best Posters
looks_one
Fat Tails
with 2.7 thanks per post
looks_two
gregid
with 2.2 thanks per post
looks_3
timefreedom
with 2 thanks per post
looks_4
bltdavid
with 1.4 thanks per post
trending_up
11,555 views
thumb_up
61 thanks given
group
11 followers
forum
34 posts
attach_file
3 attachments
March 31st, 2015, 11:51 AM
Berlin, Europe
Legendary Market Wizard
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,104
timefreedom
Here is the code from @
Fat Tails that displays treasury formats. Insert #region Miscellaneous after #region Properties.
This was indeed the original code that I had published. It had a little bug. Sometimes it would display 32'' instead of 31'' or 0''. Please use the modified code as per below:
Code
public override string FormatPriceMarker(double price)
{
double trunc = Math.Truncate(price);
int fraction = 0;
string priceMarker = "";
if (TickSize == 0.03125)
{
fraction = Convert.ToInt32(32 * Math.Abs(price - trunc));
if (fraction < 10)
priceMarker = trunc.ToString() + "'0" + fraction.ToString();
else if(fraction == 32)
{
trunc = trunc + 1;
fraction = 0;
priceMarker = trunc.ToString() + "'0" + fraction.ToString();
}
else
priceMarker = trunc.ToString() + "'" + fraction.ToString();
}
else if (TickSize == 0.015625)
{
fraction = 5 * Convert.ToInt32(64 * Math.Abs(price - trunc));
if (fraction < 10)
priceMarker = trunc.ToString() + "'00" + fraction.ToString();
else if (fraction < 100)
priceMarker = trunc.ToString() + "'0" + fraction.ToString();
else if(fraction == 320)
{
trunc = trunc + 1;
fraction = 0;
priceMarker = trunc.ToString() + "'00" + fraction.ToString();
}
else
priceMarker = trunc.ToString() + "'" + fraction.ToString();
}
else if (TickSize == 0.0078125)
{
fraction = Convert.ToInt32(Math.Truncate(2.5 * Convert.ToInt32(128 * Math.Abs(price - trunc))));
if (fraction < 10)
priceMarker = trunc.ToString() + "'00" + fraction.ToString();
else if (fraction < 100)
priceMarker = trunc.ToString() + "'0" + fraction.ToString();
else if(fraction == 320)
{
trunc = trunc + 1;
fraction = 0;
priceMarker = trunc.ToString() + "'00" + fraction.ToString();
}
else
priceMarker = trunc.ToString() + "'" + fraction.ToString();
}
else
priceMarker = price.ToString(Gui.Globals.GetTickFormatString(TickSize));
return priceMarker;
}
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
April 3rd, 2015, 09:39 PM
San Jose, CA, USA
Experience: Intermediate
Platform: NinjaTrader
Posts: 112 since Dec 2013
Thanks Given: 35
Thanks Received: 103
timefreedom
Here is the code from @
Fat Tails that displays treasury formats. Insert #region Miscellaneous after #region Properties.
Code
#region Miscellaneous
public override string FormatPriceMarker(double price)
{
double trunc = Math.Truncate(price);
int fraction = Convert.ToInt32(320 * Math.Abs(price - trunc) - 0.0001); // rounding down for ZF and ZT
string priceMarker = "";
if (TickSize == 0.03125)
{
fraction = fraction/10;
if (fraction < 10)
priceMarker = trunc.ToString() + "'0" + fraction.ToString();
else
priceMarker = trunc.ToString() + "'" + fraction.ToString();
}
else if (TickSize == 0.015625 || TickSize == 0.0078125)
{
if (fraction < 10)
priceMarker = trunc.ToString() + "'00" + fraction.ToString();
else if (fraction < 100)
priceMarker = trunc.ToString() + "'0" + fraction.ToString();
else
priceMarker = trunc.ToString() + "'" + fraction.ToString();
}
else
priceMarker = price.ToString(Gui.Globals.GetTickFormatString(TickSize));
return priceMarker;
}
#endregion
Is that any different than FormatPrice?
Code
public double Round2TickSize(double DoubleValue)
{
return Instrument.MasterInstrument.Round2TickSize(DoubleValue);
}
public string FormatPrice(double DoubleValue)
{
return Instrument.MasterInstrument.FormatPrice(Round2TickSize(DoubleValue));
}
April 3rd, 2015, 09:52 PM
San Jose, CA, USA
Experience: Intermediate
Platform: NinjaTrader
Posts: 112 since Dec 2013
Thanks Given: 35
Thanks Received: 103
I use my "FormatMoney" routine to print money values.
An empty cents ".00" suffix is generally useless; I usually prefer to see "$2400" vs "$2,400.00". But if the cents are there, I print them.
I've also made commas optional by providing an overloaded method.
Code
public string FormatMoney(double Money)
{
return FormatMoney(Money, false);
}
public string FormatMoney(double Money, bool WantCommas)
{
string retval = String.Format("{0:C2}", Money);
if (!WantCommas)
retval = retval.Replace(",", String.Empty);
return retval.Replace(".00", String.Empty);
}
April 3rd, 2015, 10:02 PM
San Jose, CA, USA
Experience: Intermediate
Platform: NinjaTrader
Posts: 112 since Dec 2013
Thanks Given: 35
Thanks Received: 103
For strategies that trade futures, I've standardized on accessing certain NinjaTrader values via these properties, which are descriptive and simply named.
Code
public string ContractBaseName {
get { return Instrument.MasterInstrument.Name; }
}
public string ContractFullName {
get { return Instrument.FullName; }
}
public DateTime ContractExpiration {
get { return Instrument.Expiry; }
}
I've also found these useful,
Code
public int BarInterval {
get { return BarsPeriod.Value; }
}
public string BarType {
get { return BarsPeriod.Id.ToString(); }
}
public string BarSeries {
get { return BarInterval.ToString() + "-" + BarType; }
}
April 3rd, 2015, 10:23 PM
San Jose, CA, USA
Experience: Intermediate
Platform: NinjaTrader
Posts: 112 since Dec 2013
Thanks Given: 35
Thanks Received: 103
I have about a dozen boolean variables and properties that all use the naming convention "IsStrategyXXX".
This family of variables and properties handles strategy wide conditions, and it all started with these three,
Code
public bool IsStrategyLong {
get { return Position.MarketPosition == MarketPosition.Long; }
}
public bool IsStrategyShort {
get { return Position.MarketPosition == MarketPosition.Short; }
}
public bool IsStrategyFlat {
get { return Position.MarketPosition == MarketPosition.Flat; }
}
Define others as you see the need.
I have these as global booleans,
IsStrategyHalted
IsStrategyInited
IsStrategyStarted
IsStrategyPaused
IsStrategyDisabled
IsStrategyExiting
IsStrategyReversing
IsStrategyRunning
IsStrategyManual
and these as boolean properties,
IsStrategyIdle
IsStrategyLive
IsStrategyPerforming
I use IsStrategyIdle to know when it's safe to reverse a position. It looks like this,
Code
public bool IsStrategyIdle {
get { return IsStrategyFlat && NoOrderPending; }
}
public bool NoOrderPending {
get { return CountEntryOrders == 0 && CountStopOrders == 0 && CountTargetOrders == 0; }
}
You'll have to hookup the order counters yourself.
April 4th, 2015, 02:35 AM
Monterrey, Mexico
Experience: Beginner
Platform: NinjaTrader
Trading: Treasuries
Posts: 22 since Nov 2012
Thanks Given: 5
Thanks Received: 69
Fat Tails
This was indeed the original code that I had published. It had a little bug. Sometimes it would display 32'' instead of 31'' or 0''. Please use the modified code as per below:
I'd change a few lines, but that's just me ...
Code
public override string FormatPriceMarker(double price)
{
double trunc = Math.Truncate(price);
int fraction = 0;
string priceMarker = string.Empty;
if (TickSize == 0.03125)
{
fraction = Convert.ToInt32(32 * Math.Abs(price - trunc));
if (fraction == 32)
{
trunc = trunc + 1;
fraction = 0;
}
priceMarker = string.Format("{0}'{1:00}", trunc, fraction);
}
else if (TickSize == 0.015625)
{
fraction = 5 * Convert.ToInt32(64 * Math.Abs(price - trunc));
if (fraction == 320)
{
trunc = trunc + 1;
fraction = 0;
}
priceMarker = string.Format("{0}'{1:000}", trunc, fraction);
}
else if (TickSize == 0.0078125)
{
fraction = Convert.ToInt32(Math.Truncate(2.5 * Convert.ToInt32(128 * Math.Abs(price - trunc))));
if (fraction == 320)
{
trunc = trunc + 1;
fraction = 0;
}
priceMarker = string.Format("{0}'{1:000}", trunc, fraction);
}
else
priceMarker = price.ToString(Gui.Globals.GetTickFormatString(TickSize));
return priceMarker;
}
April 4th, 2015, 07:13 AM
Berlin, Europe
Legendary Market Wizard
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,104
April 10th, 2015, 09:18 PM
San Jose, CA, USA
Experience: Intermediate
Platform: NinjaTrader
Posts: 112 since Dec 2013
Thanks Given: 35
Thanks Received: 103
Fat Tails
@
aquarius : This code does exactly the same thing, but the formatting of the strings is visibly more elegant.
Thank you for posting it.
I recommend it over the code that I have posted.
I submit there is something even better: just use the builtin FormatPrice() method.
See my post here:
NinjaTrader Support Forum - Price marker format for T-Notes Futures [AUTOLINK]Pivot[/AUTOLINK] Points
April 11th, 2015, 04:08 PM
Berlin, Europe
Legendary Market Wizard
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,104
bltdavid
@bltdavid : Good, this means that we can use inbuilt NinjaTrader methods that already exist to simplify the task.
My conclusion is that whenever you code an indicator in overlay mode - that is an indicator which is shown on the price panel - you should add the following lines of code:
Code
public override string FormatPriceMarker(double price)
{
return Instrument.MasterInstrument.FormatPrice(Instrument.MasterInstrument.Round2TickSize(price));
}
This would do the same as my more cumbersome suggestion or the improved version from #17, as the method is alreay built into NinjaTrader. A simple solution certainly beats the complex one!
April 20th, 2015, 11:04 AM
Wrocław, Poland
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 649 since Aug 2009
Thanks Given: 320
Thanks Received: 623
As I was writing g3ChartSpan indicator I needed a way of formatting the TimeSpan to optionally exclude some information if it == 0 and additionally give me some further info like years, months and weeks. I couldn't find anything generic that would satisfy my needs, so I ended up writing this simple method that gives me close enough approximation for the purpose of the indicator. So here is the code:
Code
public static string OptionalFormat(TimeSpan ts)
{
var totalDays = ts.TotalDays;
var years = (int)Math.Floor(totalDays / 365.25);
var months = (int)Math.Floor((totalDays % 365.25) / 30.5);
var weeks = (int)Math.Floor(((totalDays % 365.25) % 30.5 )/ 7);
var days = (int)Math.Floor((((totalDays % 365.25) % 30.5 )% 7));
return (years == 0 ? "" : years.ToString() + " Year" + (years == 1 ?", " :"s, "))
+ (months == 0 ? "" : months.ToString() + " Month" + (months == 1 ? ", " : "s, "))
+ (weeks == 0 ? "" : weeks.ToString() + " Week" + (weeks == 1 ? ", " : "s, "))
+ (days == 0 ? "" : days.ToString() + " Day" + (days == 1 ? ", " : "s, "))
+ (ts.Hours == 0 ? "" : ts.Hours.ToString("00") + "h")
+ (ts.Minutes == 0 ? "" : ts.Minutes.ToString("00") + "m")
+ (ts.Seconds == 0 ? "" : ts.Seconds.ToString("00") + "s");
}
Last Updated on May 15, 2015