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

Condition met for consecutive volumetric bars

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

    Condition met for consecutive volumetric bars

    Hello,
    I'm stuck on the logic of this simple strategy (which is related to conditions to satisfy for consecutive bars). I would like to measure the volume (I'm using Volumetric bars) of the last 2 bars just completed (not the bar that has yet to finish). If both bars meet the conditions then it should print a dot. While I have absolutely no problems with the single bar strategy, I can't get the 2 bar logic to work. Can you help me please?

    This is the simple code for 1 bar strat (for long candles):



    if (barsType.Volumes[CurrentBar].TotalVolume > volumeThreshold && Close[0] > Open[0]

    {
    Draw.Dot(this, "Bar"+CurrentBar, false, Time[0], Low[0]-TickSize*5, Brushes.Green);
    }

    This instead is the 2 consecutive bars logic that doesn't work:


    if (barsType.Volumes[CurrentBar].TotalVolume > volumeThreshold && Close[0] > Open[0]) && (barsType.Volumes[CurrentBar - 1].TotalVolume > volumeThreshold && Close[1] > Open[1])

    {
    Draw.Dot(this, "Bar"+CurrentBar, false, Time[0], Low[0]-TickSize*5, Brushes.Green);
    }​
    I've tried different combinations without success...any suggestion really welcome.

    #2
    Hello Alex Al23,

    Thank you for your inquiry.

    I have moved your post to a new thread, as the thread you replied to was only tangentially related and from over a year ago. You may still use the Volume or Volumes (multi-series script) series to get total volume information for a series, even if it uses volumetric bars, based on a barsAgo index:For example, you could test a script that uses the volumetric series as the primary series and include the following logic in OnBarUpdate():
    Code:
            protected override void OnBarUpdate()
            {
                if (Bars == null || CurrentBar < 1)
                    return;
    
                NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = Bars.BarsSeries.BarsType as    
                NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
    
                if (barsType == null)
                    return;
    
                try
                {
                    double price;
                    Print("=========================================================================");
                    Print("Bar: " + CurrentBar);
                    Print("Trades: " + barsType.Volumes[CurrentBar].Trades);
                    Print("Total Volume: " + barsType.Volumes[CurrentBar].TotalVolume);
                    Print("Total Buying Volume: " + barsType.Volumes[CurrentBar].TotalBuyingVolume);
                    Print("Total Selling Volume: " + barsType.Volumes[CurrentBar].TotalSellingVolume);
                }
                catch{}
    
                if (IsFirstTickOfBar)
                {
                    Print("*****NEW BAR*****");
                    Print("Volume[0]: " + Volume[0] + " Volume[1]: " + Volume[1]);
                }
            }​
    The prints when IsFirstTickOfBar is true will be output on bar close and you may compare them with the volume values shown from barsType.Volumes[CurrentBar].TotalVolume for each bar previously. If you want to check if the volume from one bar ago is greater than the threshold, instead of this:
    barsType.Volumes[CurrentBar - 1].TotalVolume > volumeThreshold

    You could use this:
    Volume[1] > volumeThreshold

    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hello Emily,
      thanks for the reply. I am working with volumetric bars and this is pretty confusing to me because I also use other parameters (like bid, ask). I'd like to maintain as similar as possible the original code. Is the code I provided wrong?

      if (barsType.Volumes[CurrentBar].TotalVolume > volumeThreshold && Close[0] > Open[0]) && (barsType.Volumes[CurrentBar - 1].TotalVolume > volumeThreshold && Close[1] > Open[1])
      From what I understand, the code you suggested works universally on volume but in this case I should work exclusively with volumetric bars and their parameters
      Last edited by Alex Al23; 09-21-2023, 10:56 AM.

      Comment


        #4
        Originally posted by Alex Al23 View Post
        Hello Emily,
        thanks for the reply. I am working with volumetric bars and this is pretty confusing to me because I also use other parameters (like bid, ask). I'd like to maintain as similar as possible the original code. Is the code I provided wrong?



        From what I understand, the code you suggested works universally on volume but in this case I should work exclusively with volumetric bars and their parameters
        No, the code you provided is not wrong. I was simply suggesting an alternative though I see what you are saying in the case that you would like to use other volumetric bars methods/properties. You could use CurrentBar -1 for the index as you have for barsType.Volumes[CurrentBar - 1].TotalVolume and this should work to get the TotalVolume for the previous bar. You mentioned this does not work; do you get any error messages on the screen or on the Log tab of the Control Center?

        I look forward to your reply.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Okok, no I don't get any error message on the Log and the print statement for debug doesn't show up (the conditions are not met). The strange thing is that on a single bar the conditions are met and the strategy works, so probably there's an error somewhere related to the bar enumeration.
          Last edited by Alex Al23; 09-21-2023, 01:17 PM.

          Comment


            #6
            Hello Alex Al23,

            Thank you for your reply.

            I suggest adding an additional print statement outside of the condition that outputs all of the values being compared in your condition to gain a deeper understanding of what values are used and why the condition is or is not being met. For more information on using prints to debug your scripts:


            Please let us know if we may be of further assistance.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Ok Emily, I'll try that. Thanks for the assistance.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by alexstox, 10-16-2018, 03:29 PM
              11 responses
              342 views
              0 likes
              Last Post aligator  
              Started by ageeholdings, 05-01-2024, 05:22 AM
              6 responses
              43 views
              0 likes
              Last Post ageeholdings  
              Started by tony_28217, Today, 07:04 PM
              0 responses
              11 views
              0 likes
              Last Post tony_28217  
              Started by flybuzz, Today, 10:33 AM
              1 response
              9 views
              0 likes
              Last Post flybuzz
              by flybuzz
               
              Started by spencerp92, 10-10-2023, 09:56 AM
              4 responses
              309 views
              0 likes
              Last Post flybuzz
              by flybuzz
               
              Working...
              X