• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Print Text at Lastbar in Chart

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Print Text at Lastbar in Chart

    hi, i want to do it..


    if I print using Bars.LastBarOfSession is not correct :


    if (CurrentBar==Bars.LastBarOfSession )
    {
    for (int i=0; i<Mt.Count; i++)
    Print("CurrentBar" + CurrentBar);

    https://gyazo.com/77508342d13fee64dc9970512bbb280c

    Is not correct...

    i Want To print all in the last bar in chart..not in all bar


    The graphic is composed in 2 parts:
    historic and real time..
    i want to plot in the last bar of historic chart
    Last edited by esignal; 08-03-2016, 02:19 AM.

    #2
    Hello esignal, and thank you for your question.

    If you want to take action on the last historical bar of the chart, you'll need to record what you need to work with every bar, and take action on the first live bar. That pattern could look like this

    Code:
    private double saved = 0.0;
    private bool processed = false;
    protected override void OnBarUpdate()
    {
        // updates every historical bar
        if (Historical)
        {
            saved = Close[0];
        }
    
        // run exactly once with information from the last historical bar
        else if (! processed)
        {
            processed = true;
            Print("CurrentBar" + (CurrentBar - 1));
        }
    }
    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      hi,
      i try it :
      protected override void OnBarUpdate()
      {
      if (Historical)
      {
      Print(CurrentBar);
      }


      }
      but i see nothing ..

      Is correct? ...The "Historical " where i find it in help guide?

      Comment


        #4
        My apologies, the example I gave you was for NinjaTrader 7. That documentation is here,

        http://ninjatrader.com/support/helpG...historical.htm

        To convert this to NinjaTrader 8 we can add the line

        Code:
        bool Historical = State == State.Historical;
        Here is my earlier sample with this addition.

        Code:
        
        private double saved = 0.0;
        private bool processed = false;
        protected override void OnBarUpdate()
        {
            bool Historical = State == State.Historical;
        
            // updates every historical bar
            if (Historical)
            {
                saved = Close[0];
            }
        
            // run exactly once with information from the last historical bar
            else if (! processed)
            {
                processed = true;
                Print("CurrentBar" + (CurrentBar - 1));
            }
        }
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          excuse me....i've still the problem
          I want to run my loop only one time (it finish historical feed and in that point i want to execute my loop..
          How i do can it?

          i try


          bool Historical = State == State.DataLoaded;
          if (Historical)
          {
          Print("ciao !"); //execute my loop
          }
          but i don't see it..

          Similar if i use State.Terminated or State.Transition or State.DataLoaded...

          Can you help me?

          Comment


            #6
            I am happy to help. In anticipation of your desire to only run this code exactly once, I included a boolean variable "processed" in my earlier code samples. If you include this in your strategy the way I have, all the code in the "if (! processed)" section will only be run exactly once.
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              bool Historical = State == State.Historical;
              bool processed = false;

              if (!Historical && !processed)
              {
              Print("ciaoff !");
              processed = true;
              }
              it print nothing...
              if i don't have connection internet it don't run Print
              Other suggestion?

              Comment


                #8
                Hello esignal,

                Your saved variables must be initialized outside of OnBarUpdate. See,

                Code:
                private double saved = 0.0;
                private bool processed = false;
                protected override void OnBarUpdate()
                {
                Jessica P.NinjaTrader Customer Service

                Comment


                  #9
                  i think the problem is that if i don't have connection
                  it see always Historical..and not real time

                  i try when i 've connection and it run Ok..
                  If i don't have it..don't run

                  Comment


                    #10
                    Hello esignal,

                    For situations such as this, where you would like to be in a live state but would also like to backtest a strategy, I highly recommend the playback connection. Here is an instructional video for NinjaTrader 7 on its Market Replay connection. Every concept regarding the NT7 Market Replay connection is valid with the NT8 Playback Connection.

                    https://www.youtube.com/watch?v=cgB1...56536A44DD7105
                    Jessica P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Tradarr, Today, 06:25 PM
                    2 responses
                    12 views
                    0 likes
                    Last Post Tradarr
                    by Tradarr
                     
                    Started by cocopod, Today, 04:47 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_JoshG  
                    Started by digibob, Today, 02:47 AM
                    2 responses
                    14 views
                    0 likes
                    Last Post NinjaTrader_Kate  
                    Started by mntemel, Today, 03:31 PM
                    4 responses
                    23 views
                    0 likes
                    Last Post mntemel
                    by mntemel
                     
                    Started by mrlucky1x, Today, 03:14 PM
                    2 responses
                    7 views
                    0 likes
                    Last Post mrlucky1x  
                    Working...
                    X