NexusFi: Find Your Edge


Home Menu

 





Serialising thread/code samples from NT forum


Discussion in NinjaTrader

Updated
    1. trending_up 5,267 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

Serialising thread/code samples from NT forum

  #1 (permalink)
 
cclsys's Avatar
 cclsys 
Sydney, NS
 
Experience: Intermediate
Platform: Ninja
Broker: Zen-Fire
Trading: TF,S,GC
Posts: 605 since Nov 2009
Thanks Given: 248
Thanks Received: 393

If anyone runs into serializing issues, this thread has some good info with clear coding examples.

NinjaTrader Support Forum - View Single Post - Complete list of [AUTOLINK]NinjaTrader[/AUTOLINK].Gui.Design.Serializable options?

I paste it in here too (the main contribution):

Warning: I've been asked to remind all that "Unsupported" means this may break in a future release. Or might not work with other aspects of the program eg Analyzer etc. Use this insight with caution, it is not documented.


Thanks everyone.
I used .NET reflection to rip out all the Methods, Properties etc.
I can state with confidence that there are only 3 extra serialisation methods provided by Ninja above that which comes standard with .NET.
They are :-
  • NinjaTrader.Gui.Design.SerializableColor
  • NinjaTrader.Gui.Design.SerializableFont
  • NinjaTrader.Gui.Design.SerializablePen
Pen seems to work differently so get confident with the others first.

On Serialising the File Object.
Clearly not difficult to parse the properties into a Parameter & use XMLSerialise & StreamWriter to create my own serialization class. But unlike the Color & Font it doesn't appear that the Ninja properties dialog is designed to handle the File Objects properties. So hooking it up the FileOpen dialog looked like it would make the indicator too hard to install on other peoples machines. As getting an "easy to change property value" experience wa what I was going for. Its back to the drawing board.

I hope you find the code below useful.

Partial code walking you thru the step to use build-in Ninja Serialization.
Step 1 - Declare local Variables

#region Variables
// Wizard generated variables
private float yOffset = 15; // Gap up from the bottom of the Panel
private Color textColor = Color.Black;

// User defined variables (add any user defined variables below)
//----------< Text for Y Axis Labels >--------------------
StringFormat stringFormat = new StringFormat();
private SolidBrush textBrush = new SolidBrush(Color.Black);
private Font textFont = new Font("Arial", 8);
#endregion

Step 2 - Set Brush color to property

protected override void Initialize()
{
textBrush.Color = textColor;

Step 3 - Set Properties & Serialise Correctly


[Description("Y Offset of text from Bottom of Panel")]
[Category("Parameters - Font")]
[Gui.Design.DisplayName("Text Position")]
public float YOffset
{
get { return yOffset; }
set { yOffset = Math.Min(Math.Max(0,value),1000); }
}

[Browsable(false)]
public string MyFontSerialize
{
get { return NinjaTrader.Gui.Design.SerializableFont.ToString(textFont); }
set { textFont = NinjaTrader.Gui.Design.SerializableFont.FromString (value); }
}

[XmlIgnore()]
[Description("Font of Bar Numbers")]
[Gui.Design.DisplayName("Text Font")]
[Category("Parameters - Font")]
public System.Drawing.Font TextFont
{
get { return textFont; }
set { textFont = value; }
}

[Browsable(false)]
public string TextColorSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString(textColor); }
set { textColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
}

[XmlIgnore()]
[Description("Color of Bar Numbers")]
[Category("Parameters - Font")]
[Gui.Design.DisplayName("Text Color")]
public Color TextColor
{
get { return textColor; }
set { textColor = value; }
}
#endregion

Step 4 - Use it Somewhere

public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
// ---< ensure you call the base Plot Method prior to exiting this method >---
base.Plot(graphics, bounds, min, max);

if (Bars == null || /*Plots.Count < 2 ||*/ ChartControl == null)
return;

// if (CurrentBar <= 1)
// return;

// ------------< Initialise Offsets & Graphic environment >---------------------
int barWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartCont rol.BarWidth);
int barSpace = ChartControl.BarSpace;

SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
graphics.SmoothingMode = SmoothingMode.AntiAlias;

// ===< Determine where Text will be displayed.Bottom of the Price Chart >===
float y = bounds.Top + bounds.Height - yOffset - textFont.Height;
graphics.DrawString( "CB-cntBar", textFont, textBrush, bounds.Left, y, stringFormat);

float y2 = y - 15;
graphics.DrawString( "cntBar", textFont, textBrush, bounds.Left, y2, stringFormat);

// ---< For each bar that is displayed on the screen >---
for(int cntBar = ChartControl.FirstBarPainted; cntBar <= ChartControl.LastBarPainted; cntBar++)
{
// if (!ChartControl.ShowBarsRequired && cntBar < BarsRequired)
// continue;

float x = ChartControl.GetXByBarIdx(cntBar);
graphics.DrawString( (CurrentBar - cntBar).ToString(), textFont, textBrush, x, y, stringFormat);
graphics.DrawString( cntBar.ToString(), textFont, textBrush, x, y2, stringFormat);
}

//=====< Return SmoothingMode to its original value >========
graphics.SmoothingMode = oldSmoothingMode;
}

Visit my NexusFi Trade Journal Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Exit Strategy
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #2 (permalink)
 
makusan's Avatar
 makusan 
Long Beach, CA
 
Experience: Advanced
Platform: Sierra Chart
Trading: Futures
Posts: 43 since Jun 2010
Thanks Given: 10
Thanks Received: 37

From time to time I'm getting unable to save due to indicator is not "serialized", in NT7. This happens with GOMI indicators. Most recently it is the GomRecorderIndicator. Works just fine. I have it set up as instructed, then, out of the blue, at end of day when I go to save all workspaces I get serialized error message. What do I need to do to correct this error. NT tech instructs to delete .xml file?

Respectfully,
Makusan

Reply With Quote
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,399 since Jun 2009
Thanks Given: 33,175
Thanks Received: 101,539



makusan View Post
From time to time I'm getting unable to save due to indicator is not "serialized", in NT7. This happens with GOMI indicators. Most recently it is the GomRecorderIndicator. Works just fine. I have it set up as instructed, then, out of the blue, at end of day when I go to save all workspaces I get serialized error message. What do I need to do to correct this error. NT tech instructs to delete .xml file?

Respectfully,
Makusan

Use the GomRecorder thread:



Post your question there, along with exact error messages from the log output, and exact version of GomRecorder and any other Gom* indicators you are using.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on October 22, 2013


© 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