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);



    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:
    [FONT=Courier New]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));
        }
    }[/FONT]
    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,



        To convert this to NinjaTrader 8 we can add the line

        Code:
        [FONT=Courier New]bool Historical = State == State.Historical;[/FONT]
        Here is my earlier sample with this addition.

        Code:
        [FONT=Courier New]
        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));
            }
        }[/FONT]
        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:
                [FONT=Courier New]private double saved = 0.0;
                private bool processed = false;
                protected override void OnBarUpdate()
                {[/FONT]
                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.

                    Download NinjaTrader FREE at http://www.ninjatrader.comThis video is a recording of our live "Market Replay" webinar covering the topics:5:58 &#8211; Getting Start...
                    Jessica P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by TraderBCL, Today, 04:38 AM
                    1 response
                    4 views
                    0 likes
                    Last Post bltdavid  
                    Started by martin70, 03-24-2023, 04:58 AM
                    14 responses
                    105 views
                    0 likes
                    Last Post martin70  
                    Started by Radano, 06-10-2021, 01:40 AM
                    19 responses
                    606 views
                    0 likes
                    Last Post Radano
                    by Radano
                     
                    Started by KenneGaray, Today, 03:48 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post KenneGaray  
                    Started by thanajo, 05-04-2021, 02:11 AM
                    4 responses
                    470 views
                    0 likes
                    Last Post tradingnasdaqprueba  
                    Working...
                    X