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

Volumetric data based on chart info

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

    Volumetric data based on chart info

    Hello,

    I have a script that adds bar delta on top and on the bottom of the current bar.
    However, everytime a different chart is open (30seconds, 5 min etc.) I have to manualy go to the script and change the bar period type.
    " AddVolumetric("",BarsPeriodType.Second, 30, VolumetricDeltaType.BidAsk, 1);"
    Is there a way to have the bar delta calculated based on the data series / chart that the indicator is loaded with (30 sec, 5 min, PNF etc.) ?

    On a differnet question: the current script runs OnBarClose basis. I'd like it to run it OnEachTick form. Problem is whenever it's active and a new negative to postive or positve to negative value is formed - the old value is still on the screen and is not erased. Ideally, I'd like to have the last known value dispalyed only. I have tried ForceRefresh() but it doesn't do it in the matter required.

    Thank you

    #2
    Hello nzag555,

    Thank you for your post.

    As stated in the help guide, "Arguments supplied to AddVolumetric() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner."

    This means that your current method of hard-coding the Volumetric bar period type is the supported way to use AddVolumetric(). Trying to base this on the data series or chart that the indicator is loaded on could result in errors and would be unsupported.

    For your second question, since you are not experiencing the desired behavior when your script is running OnEachTick, I would recommend using Print() statements to debug your script and check the calculations of the values displayed. Are you using a Draw method to display the deltas above and below the current bar? If so, what string is being used for the Draw method? You could Print the value before and after the draw method and check the outputs in the NinjaScript Output window to see if the value is being updated there, then this would help to better understand if there is a disconnect and where to fix that. Additionally, if you are using a Draw method (like Draw.Text) as long as you continue to use the same tag, then rather than a new drawing object being created the existing drawing object will be updated with the new values.

    We have a basic guide on using prints to debug your script here:


    I would not be able to debug your script for you, although if you show me the part of code you are using to display values on your chart I might be able to give a more specific example of a print you could use.

    Please let me know if I may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Thank you Emily for your response,

      For the first question: how is it possible to load the same script with an accurate delta on a PNF chart? The Base period type is lookiing for Tick/ Volume/ Second etc. NinjaTrader 8
      * If a cumulative delta indicator can generate this data accuraly- how can that info be put on the script?

      Here's the script for the displayed values:

      if(Close[0] < Open[0]){ //Red Bar

      if(barsType.Volumes[CurrentBar].BarDelta < 0){ //if delta is a negative value draw the number below the chart;
      Draw.Text(this, "Bdelta"+ CurrentBar, barsType.Volumes[CurrentBar].BarDelta.ToString(), 0, Low[0] - (0.35 * TickSize + 0.25), Brushes.Red);
      // Draw.Text(this, "Bdelta"+ CurrentBar, (barsType.Volumes[CurrentBar].BarDelta - barsType.Volumes[CurrentBar -1].BarDelta).ToString(), 0, Low[0] - (2.5 * TickSize + 0.25), Brushes.White);
      } else { //draw it above the chart
      Draw.Text(this, "Bdelta"+ CurrentBar, barsType.Volumes[CurrentBar].BarDelta.ToString(), 0, High[0] + (0.35 * TickSize + 0.25), Brushes.Red);
      //Draw.Text(this, "Bdelta"+ CurrentBar, (barsType.Volumes[CurrentBar].BarDelta - barsType.Volumes[CurrentBar -1].BarDelta).ToString(), 0, Low[0] - (2.5 * TickSize + 0.25), Brushes.White);
      }
      }
      if(Close[0] > Open[0]){ //Green Bar
      if(barsType.Volumes[CurrentBar].BarDelta < 0){
      Draw.Text(this, "Bdelta"+ CurrentBar, barsType.Volumes[CurrentBar].BarDelta.ToString(), 0, Low[0] - (0.35 * TickSize + 0.25), Brushes.Lime);
      // Draw.Text(this, "Bdelta"+ CurrentBar, (barsType.Volumes[CurrentBar].BarDelta - barsType.Volumes[CurrentBar -1].BarDelta).ToString(), 0, High[0] + (2.5 * TickSize + 0.25), Brushes.White);
      } else {
      Draw.Text(this, "Bdelta"+ CurrentBar, barsType.Volumes[CurrentBar].BarDelta.ToString(), 0, High[0] + (0.35 * TickSize + 0.25), Brushes.Lime);
      // Draw.Text(this, "Bdelta"+ CurrentBar, (barsType.Volumes[CurrentBar].BarDelta - barsType.Volumes[CurrentBar -1].BarDelta).ToString(), 0, High[0] + (2.5 * TickSize + 0.25), Brushes.White);
      }

      }
      if(Close[0] == Open[0]){ //Doji
      if(barsType.Volumes[CurrentBar].BarDelta < 0)
      Draw.Text(this, "Bdelta"+ CurrentBar, barsType.Volumes[CurrentBar].BarDelta.ToString(), 0, Low[0] - (0.35 * TickSize + 0.25), Brushes.White);
      //
      else
      Draw.Text(this, "Bdelta"+ CurrentBar, barsType.Volumes[CurrentBar].BarDelta.ToString(), 0, High[0] + (0.35 * TickSize + 0.25), Brushes.White);
      // Draw.Text(this, "Bdelta"+ CurrentBar, (barsType.Volumes[CurrentBar].BarDelta - barsType.Volumes[CurrentBar -1].BarDelta).ToString(), 0, High[0] + (2.5 * TickSize + 0.25), Brushes.White);Draw.Text(this, "Bardltchgb"+ CurrentBar, (barsType.Volumes[CurrentBar].BarDelta - barsType.Volumes[CurrentBar -1].BarDelta).ToString(), 0, High[0] + (2.5 * TickSize + 0.25), Brushes.White);
      }

      Do you think that changing the tag for each action (green bar / Red Bar ) would result in the new delta value overwriting the old one?

      Comment


        #4
        Hello nzag555,

        Thank you for your reply.

        Point and figure is not a supported base period type for Order Flow Volumetric Bars. Volumetric Bars do not support "exotic" base types, as the indicator analyzes a single tick data series to calculate its values. The possible base period types are listed on this page:



        Please reference the following documents to see if the Cumulative Delta indicator will meet your needs:




        I have created an example script that uses the Cumulative Delta data to draw the DeltaClose either below or above the bar in red depending on if it is negative or positive. This is similar to your logic used for if it is a red bar. This example could be expanded upon for your green and white colored text as needed. I used the same tag "delta" without the CurrentBar index, so there is only ever one text item on the chart at a time that overwrites itself as the value is updated.

        CumulativeDeltaExample_NT8.zip


        Please let me know if I may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Thank you Emily, this looks great! Only thing is I wanted it to be historical and live as well.

          Comment


            #6
            Hello nzag555,

            Thank you for your reply.

            If you would like the delta to show historically on all bars, you will need to change the tag for the Draw.Text methods so that each bar gets a unique tag. This could be achieved by adding CurrentBar like you did in your previous post. Here is an example:

            protected override void OnBarUpdate()
            {
            if (CurrentBar < 1)
            return;
            if (BarsInProgress == 0)
            {
            //if delta is a negative value draw the number below the bar
            if (cumulativeDelta.DeltaClose[0] < 0)
            Draw.Text(this, "delta" + CurrentBar, cumulativeDelta.DeltaClose[0].ToString(), 0, Low[0] - (1 * TickSize), Brushes.Red);
            else
            Draw.Text(this, "delta" + CurrentBar, cumulativeDelta.DeltaClose[0].ToString(), 0, High[0] + (1 * TickSize), Brushes.Red);
            }
            else if (BarsInProgress == 1)
            {
            // have to update the secondary series of the hosted indicator to make sure the values we get in BarsInProgress == 0 are in sync
            cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
            }
            }


            Thanks for your patience. Please let us know if you have any additional questions or concerns.
            Emily C.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by pibrew, Today, 06:37 AM
            0 responses
            4 views
            0 likes
            Last Post pibrew
            by pibrew
             
            Started by rbeckmann05, Yesterday, 06:48 PM
            1 response
            14 views
            0 likes
            Last Post bltdavid  
            Started by llanqui, Today, 03:53 AM
            0 responses
            6 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by burtoninlondon, Today, 12:38 AM
            0 responses
            11 views
            0 likes
            Last Post burtoninlondon  
            Started by AaronKoRn, Yesterday, 09:49 PM
            0 responses
            16 views
            0 likes
            Last Post AaronKoRn  
            Working...
            X