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

GetCurrentBid(); not working?

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

    GetCurrentBid(); not working?

    I've written an indicator to draw some lines based on the current price and I must be missing something obvious. Here's a code snippet:

    dCurrentPrice = GetCurrentBid();

    Print( dCurrentPrice );
    Print( GetCurrentAsk() );

    The output window shows :
    11826
    11826


    Every single time regardless of the price on my chart. For example, as I wruite the price is 12106 on YM. Also, only prints those two lines even tho I have CalcOnBarClose=false so it should be looping the pice as it changes, right? Any ideas?

    #2
    Hi TiggerTrader,

    Yes, if accessed in real time with CalculateOnBarClose = false then you'll receive updates with every incoming tick of data. These values are only designed to be used in real time, so when accessed historically it will use Close price instead.

    If you want, you can add a filter that only prints these values in real time. It may make the output window easier to follow.

    if (!Historical)
    {
    Print( dCurrentPrice );
    Print( GetCurrentAsk() );
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Interesting... this is now NOT printing my price at all. So why is this live indicator in a live chart show only Historical data?

      Why is the code NOT real time? Is there some global value I need to set to tell it to show real time?

      Comment


        #4
        What connection are you using for real time data? What is the instrument and interval you're viewing? Is there movement on the chart?

        Most June futures contracts recently stopped trading, so make sure you're not using those. If you want to verify real time functionality with your script, you can always use the simulated data feed.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          PFGBest. And the chart is an 89 tick YM 09-11 which is fluidly showing the price movement.

          Comment


            #6
            I'm not sure why it's not working for you. There's nothing additional to set. Make sure you've compiled all code changes by Right Clicking in editor > Compile. Make sure your script is running the latest version of these code changes by Right Clicking on Chart > Reload NinjaScript.

            If it's still not working the way you expect, can you post the complete script here and will take a look?
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              OK, here it is. The idea is to show where a sopt might be on the upside and downside as you watch the movement.
              Attached Files

              Comment


                #8
                Thanks for the script. This is the issue:

                dCurrentPrice = GetCurrentBid();
                dPrevPrice = GetCurrentBid();

                if( dCurrentPrice == dPrevPrice )
                return;


                You're setting two variables equal to the same value, and stopping code processing with return;
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  No, the prev gets set AFTER all the lines are drawn before exiting the routine. So when it runs, it prints the "Drawing Lines" once and only once. Which means the first time thru prevPrice = 0. Also, that doesn't explain why the Historical is kicking out the Print statements and why the
                  GetCurrentBid()
                  is producing 11826 all the time.

                  Comment


                    #10
                    The results you're getting seem expected to me. You're setting two variables equal to one another and returning out when they're equal. They're equal because you set them so, and return doesn't allow the whole block to be processed.

                    Keep in mind this is run against all historical bars so you may need to simplify and print all values, along with the corresponding bar index CurrentBar, to track what it's doing.

                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by TiggerTrader View Post
                      No, the prev gets set AFTER all the lines are drawn before exiting the routine. So when it runs, it prints the "Drawing Lines" once and only once. Which means the first time thru prevPrice = 0. Also, that doesn't explain why the Historical is kicking out the Print statements and why the
                      GetCurrentBid()
                      is producing 11826 all the time.
                      On Historical bars, that would make no difference, as the values can only be calculated on bar close anyway. (A Historical bar is one structure that has only one set of values for any bar. i.e., there is no intrabar granularity on Historical bars)

                      Comment


                        #12
                        OK, so I've tried to reduce my problem. Started a new indicator. Now I can't get DrawRay to work...grrrrr... This version does print the correct price, but no ray is drawn. Help file doesn't help me see why it's not working. Please see attached script. I'm sure it's some small detail I missed.
                        Attached Files

                        Comment


                          #13
                          Originally posted by TiggerTrader View Post
                          OK, so I've tried to reduce my problem. Started a new indicator. Now I can't get DrawRay to work...grrrrr... This version does print the correct price, but no ray is drawn. Help file doesn't help me see why it's not working. Please see attached script. I'm sure it's some small detail I missed.
                          The DrawRay() method that you are using requires the autoScale parameter.

                          Code:
                          DrawRay("UpTrendLine", [COLOR=Red][B]false,[/B][/COLOR] 20, GetCurrentAsk()+5, 5, GetCurrentAsk()+5, upTrendColor, DashStyle.Solid, 2);

                          Comment


                            #14
                            No effect. Also, doing just that 1 change BROKE GetCurrentBid. Now it prints 11877 once and only once. This is frustrating. All I want is to draw a line above and below the current price as it changes.

                            Comment


                              #15
                              Originally posted by TiggerTrader View Post
                              No effect. Also, doing just that 1 change BROKE GetCurrentBid. Now it prints 11877 once and only once. This is frustrating. All I want is to draw a line above and below the current price as it changes.
                              What is the error in your log?

                              StopTest.cs does not contain "GetCurrentBid()".
                              Last edited by koganam; 06-22-2011, 07:43 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ScottWalsh, Today, 06:52 PM
                              3 responses
                              18 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by trilliantrader, Today, 03:01 PM
                              2 responses
                              17 views
                              0 likes
                              Last Post helpwanted  
                              Started by cre8able, Today, 07:24 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post cre8able  
                              Started by Haiasi, Today, 06:53 PM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by ScottW, Today, 06:09 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X