Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Stop plotting before a bar with specific Index

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

    Stop plotting before a bar with specific Index

    Hi,

    My script plots line with every bar plotted on the chart, but I want to stop the plot prior to a specific bar with specific index. Can you please tell me the syntax or how that can be achieved in ninjascript?

    #2
    Hello asmmbillah,

    As an example of no longer plotting after a specific bar number I am choosing 50.

    if (CurrentBar < 50)
    {
    Value[0] = Close[0];
    }

    This would plot the close price until bar 50 and then would stop plotting.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply. I am using int firstBar a veritable to identify the index of firstBar drawn a static number of barsAgo. And drawing lines at low of each Bar. According to your note, if I use if (firstBar < number) Draw.Line(); will only draw line and other calculations only after firstBar, right?

      Comment


        #4
        Hello asmmbillah,

        Instead of stopping the plot prior to a specific bar with specific index, you are wanting to start the plot after a specific index?

        if (CurrentBar > firstBar)
        {
        Value[0] = Close[0];
        }

        You are wanting a plot a with AddPlot() and not a drawing object, is this correct?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks for your reply. I have taken a screenshot on the chart where you should see a white down arrow which has indicated the firstBar mentioned above and Aqua up arrow is indicating the last bar drawn on chart. I just want the Draw.Line() to always or any other calculations only limited to the firstBar and CurrentBar which now developing. Other condition I am using with that is to only Draw.Line() start from the Lowest Low within that bar index range and keep drawing within a static value interval upward to the highest High within tht bar index range, if that help you to understand. But when I am doing it, as you can see in the screenshot, it plotting Lines even before the firstBar. Any suggestion will be appreciated. thanks in advance.

          Comment


            #6
            Hello asmmbillah,

            To confirm, you are not wanting a plot but instead you are drawing a drawing object, is this correct?

            Draw.Line() objects will be drawn from the two points you supply, a start barsAgo value and price and an end barsAgo value and price.

            Draw.Line(NinjaScriptBase owner, string tag, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush)

            If you don't want the line drawn before a specific bar number, use a condition so the Draw method is only called after the bar number you would like.

            if (CurrentBar < myStartBar)
            {
            Draw.Line(this, "myLine", CurrentBar - myStartBar, High[CurrentBar - myStartBar], 0, High[0], Brushes.Blue);
            }

            Set the start barsAgo value to the bar where you want the drawn line to stop, set the end barsAgo value to the bar where you want the drawn line to stop.

            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks for your reply. I have made necessary changes and for debugging I am plotting a dot on a bar to get the close price instead of drawing line to simplify the process. I am using:
              double startPrice = 0;
              if (BarsInProgress == 0)
              {
              if (!Bars.IsFirstBarOfSession)
              {
              lBar = CurrentBar;
              }
              else
              {
              fBar = CurrentBar;
              }
              startPrice = Close[lBar - fBar - 1];
              Draw.Dot(this, "lastClose", true, lBar - fBar, High[lBar - fBar] + 200 * TickSize, Brushes.Red);
              }

              it is plotting the Dot, but insead of 1 bar before, it is plotting on the first bar and close price is keeps changing where startPrice ie, Close price should be static, right? Can you advice?

              Please note, I am using calcluation per tick.

              Comment


                #8
                Hello asmmbillah,

                When using Calculate .OnEachTick, the close price of the current bar is still building and is not static.

                A closed bar however would be static as the bar is fully closed.

                I'm not certain what bar you are getting the price from as the barsAgo index is being calculated.

                Try using a print. Print the barsAgo index, print the time of the current bar, print the time of the bar with that barsAgo index, print the value of the close.

                Below is a link to a forum post that demonstrates using prints to understand behavior.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks that was very helpful.
                  In the standard volume profile indicator, it is using 1 day for calculating data and plotting it. I have tried few options so that instead of 1, how I could calculate and plot any number of days data; unfortunately it does not work or plot. Can you please guide me where this calculation is taking place within the volume profile indicator script or any suggestion where to make the change? Thanks in advance.

                  Comment


                    #10
                    Can anyone help here? thanks

                    Comment


                      #11
                      Hello asmmbillah,

                      The @VolumeProfile.cs script gets the X by bar index on lines 248 and 249.

                      As a heads up our support is not able to assist with logic.
                      This thread will remain open for any community members that would like to assist with logic.

                      What specifically is not working?

                      Is the unmodified open source VolumeProfile included with NinjaTrader not rendering on a chart that has data?

                      With your custom script, are you printing values?
                      Last edited by NinjaTrader_ChelseaB; 06-14-2020, 08:06 PM.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi, thanks for your reply. Probably you didn’t understand my question in previous reply. VP is plotting just latest day on chart, I wanted to plot multiple days worth data using a variable for number of days . In the email notification I received, you suggested some, but you have edited that later. I would appreciate any suggestion.

                        Comment


                          #13
                          Hello asmmbillah,

                          On lines 118 to 126 the script resets on a new session by clearing the dictionaries of the saved prices. You can change this to the logic you would like to use instead if you are not wanting to reset on a new session.
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Brevo, Today, 01:45 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post Brevo
                          by Brevo
                           
                          Started by aussugardefender, Today, 01:07 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post aussugardefender  
                          Started by pvincent, 06-23-2022, 12:53 PM
                          14 responses
                          239 views
                          0 likes
                          Last Post Nyman
                          by Nyman
                           
                          Started by TraderG23, 12-08-2023, 07:56 AM
                          9 responses
                          384 views
                          1 like
                          Last Post Gavini
                          by Gavini
                           
                          Started by oviejo, Today, 12:28 AM
                          0 responses
                          6 views
                          0 likes
                          Last Post oviejo
                          by oviejo
                           
                          Working...
                          X