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

Swing Volume Compared!

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

    Swing Volume Compared!

    Hello all, I have this small indicator that shows The Volume of each Swing Up or down. Attached below. I'd like to know how can I save the Volume of let's say, every 3 Up Swings, so that I can later use them for something. I tried doing this in a Plot[], but I couldn't get it to work right. Any suggestions would be appreciated, please and thank you!!


    Here's a pic of what I'd like https://www.screencast.com/t/0N20XtxOTZR
    Attached Files

    #2
    Hello ginx10k,

    Thanks for the post.

    I'd like to know how can I save the Volume of let's say, every 3 Up Swings
    To do something every X you would need to count to do that. An int variable would likely be easiest, count using the int by adding 1 to it each time a swing happens. On the third reset the variable and plot the result.

    I tried doing this in a Plot[], but I couldn't get it to work right
    Can you detail what part that is in the script so I can follow along better?

    A plot would be correct for storing data, it really depends on what you mean by it didn't work right. If you are doing something every X and not every bar that would make an inconsistent plot, depending on the use of that plot you may need to replot data to fill in gaps or use IsValidPlot:


    Another item here based on the comment in your image would be if you wanted to compare previous instances from X in time. To do that you would very likely need to use a loop and IsValidPlot+ a plot. The ZigZag indicator does this and could be used as a reference on this type of logic, it has a LowBar method that shows using Update() and also looping/IsValidPlot. Because the last swings point in time is not known you would have to find it by going back through the plot data. You would mainly need to see the loop in the zig zag, the Update is used if this would be an exposed method for example if a strategy were to access the data, that's otherwise not needed.

    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 01-20-2021, 10:47 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse, thanks for response. I've uploaded a different version of the indicator. I must of deleted the Plot that I attempted before. This was my most recent attempt at making it work. THis picture shows the area of the code where I want this to happen. https://www.screencast.com/t/azBkbqPn4

      I'm not too sure what you meant about doing something every X. Perhaps you can give an example or a little snippet of code to help guide me. This is for NT7 btw, since I haven't moved to NT8 yet.

      So, as you can see, I want to gather the Value after a Swing Closes and store it for later access. This way, every 3 Swings, indicator can do a
      Code:
      if(swingOneVol > swingTwoVol && swingTwoVol > swingThreeVol).
      This is basically what I'm trying to do.
      Attached Files

      Comment


        #4
        Hello ginx10k,

        I updated the last post to contain nt7 links.

        I'm not too sure what you meant about doing something every X.
        What I had suggested would be to use an int variable and count 1, 2, 3.

        So, as you can see, I want to gather the Value after a Swing Closes and store it for later access. This way, every 3 Swings, indicator can do a
        This description seems to conflict with what you described earlier. Are you trying to add to the plot once every 3 swings or store each swing and then access the last 3?

        I'd like to know how can I save the Volume of let's say, every 3 Up Swings,
        Every 3 to me would be do something once after 3 swings then wait to do that again for 3 more swings. Is that what you meant?


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          This description seems to conflict with what you described earlier. Are you trying to add to the plot once every 3 swings or store each swing and then access the last 3?
          I'm trying to store the value after each Swing, and then access it later. So Swing1 Closes, the Vol1 = swing1Vol, etc. that way, after 3 swings, it'll do the
          Code:
          if(swingOneVol > swingTwoVol && swingTwoVol > swingThreeVol).
          . But remember I always want to look at '3 UpSwingsAgo' and '2 UpSwingsAgo', the way that a Plot would look at 3 barsAgo by using Plot[2] > Plot[1] etc..

          So can you see what I'm trying to do now? is there a example that you can write to show me how to do it?

          Comment


            #6
            Hello ginx10k,

            Thanks for confirming.

            If you are trying to store each swing and then access the last 3 you will need a method like shown in the ZigZag indicator to access that data. When you set the plot at the time of the swing that's only 1 point. The space in between points would be invalid points which can then be used logically to find instances.

            . But remember I always want to look at '3 UpSwingsAgo' and '2 UpSwingsAgo', the way that a Plot would look at 3 barsAgo by using Plot[2] > Plot[1] etc..
            You won't be able to do that with the plot because the span between the places where the plot is set would be considered invalid, you would have to use logic to check for that. A loop could be used and rather than accessing the plot directly with BarsAgo.

            Looping backwards from the CurrentBar like shown in the zig zag method would be one way to do that to find instances. That method returns a BarsAgo so you would know where the data is within the plot to avoid the invalid points. Using the BarsAgo it returns you could then access the plot and supply that BarsAgo to get the data for X instance.



            One other note from the script you provided, your plots point to the same underlying Values index:

            Code:
            public DataSeries SwingUpVol
            {
            get { return [B]Values[0]; [/B]}
            }
            
            public DataSeries SwingDownVol
            {
            get { return [B]Values[0];[/B] }
            }
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks Jesse. I'll look into this stuff.

              Comment


                #8
                Hi there, I still can't get it to work. This time, I've tried a Counter and using a Plot. This is all I get https://www.screencast.com/t/8rRcUBMa8cf9

                This is the line of the code that does all the work
                Code:
                 //NEXT Store the PREVIOUS 3 Up Swing's Volume into Variable for Later use
                
                //4. Store the Up Swing's Delta Volume into Variables for Later use
                if(upSwingCounter == 0 ) //Initilalize
                {
                upSwingBar1 = CurrentBar - lasthibar; //Start counting bars at most recent Swing High
                upSwingOne = SwingUpVol[CurrentBar - lasthibar];
                
                DrawText("test1"+CurrentBar,false,"S.One= "+upSwingOne.ToString(), CurrentBar-lasthibar, lasthi + (20* TickSize),0, Color.Yellow, new Font("Courier", 11, FontStyle.Bold), StringAlignment.Center, Color.Black, Color.Black, 0);
                
                
                upSwingCounter++;
                }
                if(upSwingCounter == 1 && CurrentBar > upSwingBar1) //
                {
                upSwingBar2 = CurrentBar - lasthibar; //Start counting bars at most recent Swing High
                upSwingTwo = SwingUpVol[CurrentBar - lasthibar];
                
                DrawText("test2"+CurrentBar,false,"S.Two= "+upSwingTwo.ToString(), CurrentBar-lasthibar, lasthi + (18* TickSize),0, Color.Yellow, new Font("Courier", 11, FontStyle.Bold), StringAlignment.Center, Color.Black, Color.Black, 0);
                
                
                upSwingCounter++;
                }
                if(upSwingCounter == 2 && CurrentBar > upSwingBar2) //
                {
                upSwingBar3 = CurrentBar - lasthibar; //Start counting bars at most recent Swing High
                upSwingThree = SwingUpVol[CurrentBar - lasthibar];
                
                DrawText("test3"+CurrentBar,false,"S.Three= "+upSwingThree.ToString(), CurrentBar-lasthibar, lasthi + (16* TickSize),0, Color.Yellow, new Font("Courier", 11, FontStyle.Bold), StringAlignment.Center, Color.Black, Color.Black, 0);
                
                
                upSwingCounter++;
                }
                //RESET Counter
                if(upSwingCounter == 3 )
                {
                upSwingCounter = 0;
                }
                
                //////////END OF PREVIOUS UP SWING DATA/////////
                Please help, I just don't get why I can't access the Plot using SwingUpVol[CurrentBar - upSwingBar1];

                Attached Files

                Comment


                  #9
                  Hello ginx10k,

                  I believe this would be easiest if you look at the plots you created on the chart and first verify that is doing what you need it to. Is the SwingUpVol correct on the chart if you look at just that plot and not your drawings of it?

                  If the plot is correct then the data is inconsistent so If you want to access the plots using a BarsAgo you will need to calculate the correct BarsAgo for each instance of the plot. To do that you would use a loop like the ZigZag indicator, looping backwards to find valid data points in the plot. The Bars where you see N/A is an invalid data point and is how the loop works in the zig zag. You would need to also do that if you want to access the plotted data in some way by using a BarsAgo, that loop finds the BarsAgo needed.

                  The BarsAgo you are using is the CurrentBar - a variable, depending on if that equates to the last instance or not would determine what you are drawing in the text. You could try to debug the code further if you wanted to know specifically why you are getting the result you pictured.

                  To do what you are asking it would likely be best to have your calculation logic separate from the drawing logic just like how the zig zag works. It calculates its data and plots it from OnBarUpdate then later utilizes the loops and the plots to draw the data. Because you are using a plot which has inconsistent data being set that would be a good use case to follow this approach. You could still use OnBarUpdate for drawing but rather than trying to put in objects throughout your calculation logic you could make a single loop like the zig zag has to draw everything at once at the appropriate plot instances using the loop to find the BarsAgo needed.

                  Please let me know if I may be of further assistance.

                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by PaulMohn, Today, 12:36 PM
                  2 responses
                  16 views
                  0 likes
                  Last Post PaulMohn  
                  Started by Conceptzx, 10-11-2022, 06:38 AM
                  2 responses
                  53 views
                  0 likes
                  Last Post PhillT
                  by PhillT
                   
                  Started by Kaledus, Today, 01:29 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post Kaledus
                  by Kaledus
                   
                  Started by yertle, Yesterday, 08:38 AM
                  8 responses
                  37 views
                  0 likes
                  Last Post ryjoga
                  by ryjoga
                   
                  Started by rdtdale, Today, 01:02 PM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Working...
                  X