Debugging a BarsType help - NinjaTrader Programming | futures io social day trading
futures io futures trading


Debugging a BarsType help
Updated: Views / Replies:3,352 / 13
Created: by zacharydw00 Attachments:2

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

Debugging a BarsType help

  #11 (permalink)
 Vendor: www.coroin.com 
Galveston ,TX
 
Futures Experience: Intermediate
Platform: NT7
Broker/Data: Zaner
Favorite Futures: Futures
 
Posts: 386 since Mar 2010
Thanks: 364 given, 433 received

tweaked your code ... here's what i came up with:

 
Code
        /// <summary>
        /// write debug to log file
        /// </summary>
        /// <param name="time"></param>
        /// <param name="bar"></param>
        /// <param name="msg"></param>
        void Debug(DateTime time, int bar, string msg)
        {
            // local variables
            string path = string.Concat(Cbi.Core.UserDataDir.ToString(), @"log\YourFileName.log");
            FileInfo file = new FileInfo(path);

            // ensure file exists
            if (!file.Exists)
            {
                using (StreamWriter sw = file.CreateText())
                {
                    try
                    {
                        sw.WriteLine(string.Concat("===== ", DateTime.Now.ToString(), " ====="));
                        sw.Flush();
                    }
                    catch (Exception ex) { }

                    sw.Close();
                }
            }

            // write debug entry
            using (StreamWriter sw = File.AppendText(path))
            {
                try
                {
                    sw.WriteLine("{0} : {1} \r\n{2}", time, bar, msg);
                    sw.Flush();
                }
                catch (Exception ex) { }

                sw.Close();
            }
        }
to invoke from a bar-type, do something like this:
 
Code
                    string msg = string.Concat("myValue1: ", myValue1.ToString(), "\r\nmyValue2: ", myValue2.ToString());
                    Debug(time, bars.Count, msg);
logs are posted in <my docs>\NinjaTrader7\log and look like this:

 
Code
2011-04-28 07:30:00 : 475 
myValue1: 8
myValue2:12616
2011-04-28 07:30:03 : 476 
myValue1: 8
myValue2:12624
2011-04-28 07:32:17 : 477 
myValue1: 8
myValue2:12616
2011-04-28 07:50:11 : 478 
myValue1: 8
myValue2:12624
note: i haven't tested this in ChartStyles or Indicators or Strategies. should work just fine, but my primary use (for now) is debugging a bar type, which is the point of this thread.

cheers,
-e

Reply With Quote
 
  #12 (permalink)
Elite Member
Idaho
 
Futures Experience: Intermediate
Platform: NinjaTrader,ToS
Broker/Data: Amp Futures, ToS
Favorite Futures: ES, E7, CL, GC
 
zacharydw00's Avatar
 
Posts: 139 since Aug 2009
Thanks: 81 given, 164 received

No wiki yet. I've been offline for a while. will post what i've been using so far. I did get the debugging output file to work. will post it here later today, for a quick post, then post wiki later. Thanks for the suggestion @eman.

Milk-a-What?
Reply With Quote
 
  #13 (permalink)
Elite Member
Idaho
 
Futures Experience: Intermediate
Platform: NinjaTrader,ToS
Broker/Data: Amp Futures, ToS
Favorite Futures: ES, E7, CL, GC
 
zacharydw00's Avatar
 
Posts: 139 since Aug 2009
Thanks: 81 given, 164 received


 
Code
using System.IO;
using System.Windows.Forms;

   
 public class LineBreakWickedTestBarsType : BarsType
    {
        private static bool        registered            = Register(new LineBreakWickedTestBarsType());
        private double            switchPrice            = double.MinValue;
        private double            anchorPrice            = double.MinValue;
        ....

        #region Debug StreamWriter
        private string                    path = Cbi.Core.UserDataDir+"LBWickedTest "+DateTime.Now.ToString("_yyyy.MM.dd")+".txt";  // CHANGE LB WICKEDTEST to the file name you want.
        private System.IO.StreamWriter    sw;
        public void Debug(DateTime time, String line)    // This will print the Time specified given
        {
            try        {    sw = new StreamWriter(path, true);    sw.AutoFlush = true;
                        sw.WriteLine(String.Format("{0} | {1}", time.ToString("HH:mm:ss:fff"), line));
                    }
            catch (NullReferenceException e) 
                    {    MessageBox.Show(e.ToString());        }
            finally    {    sw.Close();        }
        }
        public void Debug(String line)    // This will print the Time now
        {
            try        {    sw = new StreamWriter(path, true);    sw.AutoFlush = true;
                        sw.WriteLine(String.Format("{0} | {1}", DateTime.Now.ToString("HH:mm:ss:fff"), line));
                    }
            catch (NullReferenceException e) 
                    {    MessageBox.Show(e.ToString());        }
            finally    {    sw.Close();        }
        }
        #endregion

        public override void Add(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isRealtime)
        {
            int barcnt = bars.Count;
            bool endOfBar = true;

Debug("_");
Debug(String.Format("BarTime: {0:yyyy/MM/dd HH:mm:ss} :  Barcnt= {1:00}, O_{2:000.0}, H_{3:000.0}, L_{4:000.0}, C_{5:000.0}", time, barcnt, open, high, low, close));
           ...
        }
This will create a file in ...\My Documents\NinjaTrader 7\ directory.

Milk-a-What?

Last edited by zacharydw00; April 29th, 2011 at 05:48 PM.
Reply With Quote
 
  #14 (permalink)
Elite Member
Charlottetown, Prince Edward Island
 
Futures Experience: Advanced
Platform: Ninja
Broker/Data: Optimus - Rithmic
Favorite Futures: GC
 
WolfieWolf's Avatar
 
Posts: 232 since Jul 2010
Thanks: 100 given, 273 received

Solution

Hi Guys,

I know this is a really old thread but I came across it about eight months ago when I started developing a custom bars type. Just now, after messing with streamwriters all this time I figured it out. Hopefully this helps someone who's developing down in the guts of NinjaTrader where you're not supposed to be.

using NinjaTrader.code;

public void Print(string output)
{
OutputEventArgs.ProcessEventArgs(new OutputEventArgs(output + "\r\n"));
}

Then from anywhere in that namespace you can do the same thing you've always done in Indicators or Strategies.

Print ("This is my value: " + _myValue);

The Ninja Output window will now happily give you the output you want.

I hope that helps.

/W

Reply With Quote
The following 3 users say Thank You to WolfieWolf for this post:

Reply



futures io > > > > > Debugging a BarsType help

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
NinjaTrader 7 List of used BarsType base(PeriodType.?) zacharydw00 NinjaTrader Programming 13 December 16th, 2015 01:59 PM
Momentum BarsType (NT7) eman The Elite Circle 308 June 24th, 2014 12:52 PM
BarsType.Add method - how to always detect if (bars.Count == 0)? jdfagan NinjaTrader Programming 2 June 29th, 2010 06:33 PM
need some help with debugging. kaywai NinjaTrader Programming 1 January 18th, 2010 05:40 AM


All times are GMT -4. The time now is 10:47 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-16 in 0.07 seconds with 20 queries on phoenix via your IP 54.227.51.103