• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

if (GetCurrentBidVolume()< .50 *GetCurrentAskVolume())

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

    if (GetCurrentBidVolume()< .50 *GetCurrentAskVolume())

    trying create the following:

    if current bid volume is less than current ask volume (divided by 2)

    example:

    bid vol: 49
    ask vol: 100

    so, 49 is less than 100/2 or 50

    not sure if the code below is correct

    Code:
    if	(GetCurrentBidVolume()< .50 *GetCurrentAskVolume())

    #2
    Hello duck_CA,

    Thanks for your post.

    Your code would work but keep in mind that during historical data loading both the bid and ask volume will be the bar volume so your statement will only be effective during live data. Additionally I suspect you will want to run with CalculateOnBarClose = false so you can get the most current information.

    When something is not working you can add a print statement to assist in debugging. Here is an example:

    Code:
    Print ("Bv: "+GetCurrentBidVolume()+"  Av: "+GetCurrentAskVolume()+"  Bv<Av*.5"+(GetCurrentBidVolume() < GetCurrentAskVolume() ? true:false));
    The print code will show the bid volume, the ask volume and then test if the bid < ask * .5 and provide a true or false.

    If you do not want to see the historical loading you can add this statement:

    if (Historical) return;

    References:
    http://ninjatrader.com/support/helpG...taskvolume.htm
    http://ninjatrader.com/support/helpG...tbidvolume.htm
    http://ninjatrader.com/support/helpG...historical.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      not sure if the code is actually realizing the percentage adjustment the way I was anticipating.

      example:
      if ( GetCurrentAskVolume()*3.80 < GetCurrentBidVolume())

      Current Ask: 100
      Current Bid: 400

      Current Ask 100 x 3.8 = 380 or TRUE


      seems like i'm currently getting true statements based on the actual bid and ask prices and not the *3.80 factor.




      Code:
      //if	(Value[0] == GetCurrentAsk() || GetCurrentAskVolume()< GetCurrentBidVolume())
      			if ( GetCurrentAskVolume()*3.80 < GetCurrentBidVolume())
      			{
      			if(bidAsk)
      			PlotColors[0][0] = askColor;//green
      			}
      			//if	(Value[0] == GetCurrentBid() || GetCurrentBidVolume()< GetCurrentAskVolume())
      			//if	(GetCurrentBidVolume()< .20 *GetCurrentAskVolume())
      			//if	(GetCurrentBidVolume()*3.80< GetCurrentAskVolume())
      			if	(GetCurrentBidVolume()< .50 *GetCurrentAskVolume())
      			{
      			if(bidAsk)
      			PlotColors[0][0] = bidColor;//red
      			}
      			Print ("Bv: "+GetCurrentBidVolume()+"  Av: "+GetCurrentAskVolume()+"  Bv<Av*.5"+(GetCurrentBidVolume() < GetCurrentAskVolume() ? true:false));
      			//Print ("Av: "+GetCurrentAskVolume()+"  Bv: "+GetCurrentBidVolume()+"  Av<Bv*.5"+(GetCurrentAskVolume() < GetCurrentBidVolume() ? true:false));
      
      			Print ("Bid "+GetCurrentBidVolume()+"  Ask "+GetCurrentAskVolume()+"  80%"+(GetCurrentBidVolume() < GetCurrentAskVolume() ? true:false));
      			Print ("Ask "+GetCurrentAskVolume()+"  Bid "+GetCurrentBidVolume()+"  80%"+(GetCurrentAskVolume() < GetCurrentBidVolume() ? true:false));

      Comment


        #4
        Hello duck_CA,

        Thanks for your post.

        Your example is illustrating a correct answer.

        if the CurrentAskVolume = 100 and the CurrentBidVolume = 400 then it follows that 100 * 3.8 is less than 400 and thus the conditional statement if ( GetCurrentAskVolume()*3.80 < GetCurrentBidVolume()) would be true.

        To clear any confusion you would want to print out all elements of the conditions being evaluated, in your code segment I see Value[0], GetCurrentAsk(), GetCurrentAskVolume(), GetCurrentBidVolume(), bidAsk.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          please see video for questions on current indicator behavior

          http://screencast.com/t/tiTXVsTJ

          Comment


            #6
            Hello duck_CA,

            Thank-you for taking the time to do a video and walk through your questions.

            To be able to answer your questions it would be helpful if I could review your entire code. Please post the cs file. If you would rather not post it, please feel free to send into PlatformSupport[at]NinjaTrader[dot]Com with a subject line of Atten:Paul and a link to this thread.

            Yes, the Print statement will print values and calculation results.

            I suspect the issue is in the logic conditions but it would be easier to solve with all of the information.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              attached code for your review

              thank you so much for taking a moment to review attached indicator. it sounds like you have an understanding of what i'm trying to achieve.
              Attached Files

              Comment


                #8
                Hello duck_CA,

                Thanks for your post & code.

                One issue is using the GetCurrentAsk() & GetCurrentBid() and GetCurrentBidVolume() and GetCurrentAskVolume() at multiple times/locations in the code could yield different results as each time the same method would be called it is grabbing a snapshot of constantly changing conditions which make evaluation in OnbarUpdate() difficult. So to fix this would be to call each method once and save the result into a double variable to then be used throughout the remainder of OnBarUpdate()

                For the evaluation you had an "if" condition with an "or" condition and if either was true then the action/print statement was happening which was likely causing some of the prints when the volume values were not correct. I reworked the print statements to accurately show when each condition is true separately.

                Tied in with this the use of PlotColors to change the line color was based again on the condition being true. To answer a video question once PlotColor[0][0] is set, the line will continue plotting in that color until you change it. So what you need to get the three colors is:
                if - color1
                else if - color 2
                else - color 3

                Please review and test:

                Code:
                Value.Set(Close[0]);
                double GA = GetCurrentAsk();
                double GB = GetCurrentBid();
                double GAV = GetCurrentAskVolume();
                double GBV = GetCurrentBidVolume();
                
                
                if ( Value[0] == GA || GAV*3.80 < GBV)
                {
                	if (Value[0] == GA) 
                		Print ("Ask = Close, line = Green"); 
                				
                	if (GAV * 3.8 < GBV) 
                		Print ("GAV*3.8 < GBV: "+" GAV*3.8="+(GAV*3.8)+" < "+GBV+"  Line = green");
                				
                	if(bidAsk)
                		PlotColors[0][0] = askColor;//green
                }
                else if (Value[0] == GB|| GBV*3.80 < GAV)
                {
                	if (Value[0] == GB) 
                		Print ("Bid = Close, line = Red");
                				
                	if (GBV * 3.8 < GAV) 
                		Print ("GBV*3.8 < GAV: "+" GBV*3.8="+(GBV*3.8)+" < "+GAV+"  Line = Red");
                				
                	if(bidAsk)
                		PlotColors[0][0] = bidColor;//red
                }
                else
                {
                       PlotColors[0][0] = Color.Gold;
                	Print ("Neutral");
                }
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  thank you!

                  Paul, you went above and beyond. i really appreciate it buddy!

                  jason

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by StefanJ, Today, 04:11 AM
                  2 responses
                  7 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by fxSol, 03-17-2019, 04:17 AM
                  3 responses
                  22 views
                  0 likes
                  Last Post NinjaTrader_ChristopherD  
                  Started by MarthaClines, Yesterday, 08:06 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Started by Trader_Kim, Yesterday, 03:41 PM
                  1 response
                  11 views
                  0 likes
                  Last Post NinjaTrader_ChristopherD  
                  Started by MarthaClines, Yesterday, 06:23 PM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_PaulH  
                  Working...
                  X